- SD card write performance
- Copyright Notice.
- Top Posts
- Recent Comments
- Archives
- Chris Collins
- Coder – Maker – Educator – Leader
- Testing SD Cards with Linux
- Before we start…
- Testing Access Speed
- Testing Drive Size
- Testing Data Durability
- Caveat Emptor (Buyer Beware)
- How to run benchmark tests on SD memory cards in elementary OS
- STEP 1: INSTALL GNOME DISKS UTILITY
- STEP 2: BENCH MARK SD CARD PERFORMANCE
- Is there an SD Card diagnostic utility?
- 4 Answers 4
- For Ubuntu 13.04 and later.
- From the dash
SD card write performance
I am writing a little application, which is writing jpeg images at a constant rate on a SD card. I choose an EXT3 filesystem, but the same behaviour was observed with an EXT2 filesystem. My writing loop looks like this :
get_image() fopen() fwrite() fsync() fclose()
I also display some timing statistics, and I can see my program is sometime blocked for several seconds. The average rate is still good, because if I keep the incoming images into a fifo, then I will write many image in a short period of time after such a stall. Do you know if it is a problem with the OS or if it is related to the SD card itself ? How could I move closer to realtime ? I don’t need strong realtime, but being stalled for several seconds is not acceptable. Some precision : Yes it is necessary to fsync after every file, because I want the image to be on disk, not in some user or kernel buffer. Without fsyncing, I have much better throughoutput, but still unacceptable stall. I don’t think it is a buffer problem, since the first stall happens after 50 Mbytes have been written. And according to the man page, fsync is here precisely to ensure there is no data buffered. Precision regarding the average write rate : I am writing at a rate that is sustainable by the card I am using. If I pile incoming image while waiting for an fsync to complete, then after this stall the write transfer rate will increase and I will quickly go back to the average rate. The average transfer rate is around 1.4 MBytes /s. The systeme is a modern laptop running ubuntu 8.04 with stock kee (2.6.24.19)
Copyright Notice.
Blog entries are licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Blog comments are copyright to their respective authors.
Top Posts
Recent Comments
Archives
Chris Collins
Coder – Maker – Educator – Leader
Testing SD Cards with Linux
While on holiday recently, my wife bought a 32GB micro-SD card, which she intended to use in her tablet. Since then, it has been giving various errors, so I thought I should take it and verify its quality.
In order to test the card, we’re going to run three tests:
- Access Speed, to assess the card Speed Class.
- Drive Size, to assess if the reported size matches the actual size.
- Data durability. to assess that data written can be read back reliably.
Before we start…
The tools and techniques we’re going to use will be destructive to any data that is on the SD card. If this is important to you, make a backup of your data to a safe location before starting.
Testing Access Speed
A relatively quick assessment of speed can be made using the ‘gnome-disks’ tool. This sometimes appears as ‘Disks’ under the start menu on most modern Linux distributions. Opening this, you can find the SD card in the drive list, and use the tools to run a benchmark test. We’re interested in the write speed, so ensure you select to do a write test. Once complete, the benchmark tool will show a graph of results similar to the following figure.
SD Card Benchmark Results
We can see that the write speed is averaging 5.8 MB/s. Comparing this to the SD Association Speed Class data, we can conclude that this is only sufficient to claim Speed Class 4. This is quite disappointing for a card that was sold as a Class 10 High Speed card.
We’re going to have to mark this test as a fail.
Testing Drive Size
Again, the gnome-disks tool shows the reported size of the SD card as 34 GB (33,554,432,000 bytes). There is some ambiguity in terms of how disk sizes are reported, given that there are two definitions of what a Gigabyte is. Some consider it as 10 9 bytes (a decimal gigabyte), while some consider it as 2 30 bytes (a binary gigabyte). That said, the card was sold as a 32GB card, so if it holds that much (or more), we’re happy.
To test the drive size we’re going to create a 32GB file containing random data. Assuming you have a hard-disk location suitable for a file of this size, one can be created using the command:
dd if=/dev/urandom of=rnd_data bs=1024 count=32768000
‘dd‘ is the disk-duplicator, we’re using it to read from the input file (if) /dev/urandom. This is a pseudo-file to the kernel random number generator, and will return a random string of ones and zeros. We’re going to write this data to the output file (of) called rnd_data. We’re reading block size chunks (bs) of 1024 bytes (1 kilobyte). We’re also going to read ‘count’ blocks. Count was derived by dividing the reported disk size by the block size. As this is a large amount of random data to produce, it took several hours to produce this file, so be patient.
Once this file is created, we can copy it to the SD card to see if it fits. Again we can use the dd command for this, but this time we’ll need administrator rights.
sudo dd if=rnd_data of=/dev/sdc bs=1024 count=32768000
In my case the drive was listed as /dev/sdc, though this might differ in your case. Again the gnome-disks utility can help show where your device is listed. This command will overwrite the disk contents with the random data we previously produced. Back up any data on the card before running this command. Depending on the write speed of your card, this can also take several hours to complete.
In the end the results were a pass. All 32768000 blocks were written, so we can say the card had sufficient capacity to pass this test. Had the card been of a lower capacity, dd will show how many blocks were written. This will give an estimate of actual drive size in kilobytes. Dd also shows the average write speed as 3.8 MB/s, which is not enough to claim Class 4. Again, further proof that this is a mislabelled speed class.
Testing Data Durability
To ensure that the data we wrote can be correctly read back we can copy the SD card contents back to another file. Again we’ll use dd…
sudo dd if=/dev/sdc of=rnd_read bs=1024 count=32768000
Reading is typically quicker than writing, but as we’re moving a large data size it can also take some time to complete. Once the data has been read back, we can compare the data that was written (rnd_data), with the data that was read back (rnd_read) using a hashing algorithm:
md5sum rnd* 729d62450dbf55d0676ddff494a7597d rnd_data c628379249c448eba5502acb9de9d477 rnd_read
The test is a failure as the checksums don’t match. It’s clear that the data read back doesn’t match the data written. If data durability can’t be assured, the card is useless. It’s little wonder the tablet constantly complained that the card didn’t have a file system.
Caveat Emptor (Buyer Beware)
To finish you can delete the rnd files and recover their disk space. Two of our three tests failed, so we can say that we bought a dud SD card.
So if I have any final advice it would be when buying SD Cards, or indeed any other electronics, is to buy reputable brands from reputable dealers. Alas, as we made the purchase abroad, a refund is not likely. Hopefully these instructions can help you avoid the duds, and get a refund if possible.
How to run benchmark tests on SD memory cards in elementary OS
There are several ways to check the SD memory cards read and write speeds. The best method I prefer is to use gnome disk utility which gives is completely GUI based and presents the results in the form of graph and average read and write speeds.
STEP 1: INSTALL GNOME DISKS UTILITY
Go to ‘Applications’ and launch ‘Terminal’.
sudo apt-get install gnome-disk-utility
You will have to enter root password to complete the installation.
STEP 2: BENCH MARK SD CARD PERFORMANCE
It’s time now to insert the SD card on which you want to run the benchmark tests. Go to ‘Applications’ and enter ‘Disks’ in the search box. Launch ‘Disks’ application. Alternately, you can launch gnome utility from Terminal using the command the following command line.
In the left pane of the Disks, select the SD card. Then click on a gear icon in the right pane. Select ‘Benchmark…’.
You will have to enter root password to begin the tests. The utility will confirm the sample size, number of samples, and access time. It’s OK to stay with the default values.
The utility will give readings and graph on the fly including Read/Write rate and access time.
SD Card Benchmark Results
Is there an SD Card diagnostic utility?
Are there any SD Card diagnostic utility programs out there for Ubuntu? I would like to run tests on my SD card to check capacity, write speed etc. I have one for windows but I am looking for a Linux flavor and hope to find some source code.
4 Answers 4
Look for Disk Utility on you dash (as an option press Alt+F2 and type palimpsest )
Click on the disk you want information from, to test it click on Benchmark
To start benchmark, select Read only or Read/Write benchmark
On 13.04 (raring) palimpsest was replaced with gnome-disks («Disks» when you access it from the menu). The instructions are the same as posted by Bruno Pereira.
For Ubuntu 13.04 and later.
From the dash
A window will appear. Click Start Benchmark. to see:
I left the defaults and clicked Start Benchmarking. . It will run for a while, building the chart over time. You can see that my new SD card’s read rate is around 7 MB/s, while the write rate is only slightly over 2 MB/s.
The model shown here is a SanDisk Ultra SDXC with an advertised speed of up to 30 MB/s. As you can see, the transfer rate is not as advertised.