Raspberry Pi SD Card Speed Test

Since we first launched Raspberry Pi, an SD card (or microSD card) has always been a vital component. Without an SD card to store the operating system, Raspberry Pi is pretty useless*! Over the ensuing eight years, SD cards have become the default removable storage technology, used in cameras, smartphones, games consoles and all sorts of other devices. Prices have plummeted to the point where smaller size cards are practically given away for free, and at the same time storage capacity has increased to the point where you can store a terabyte on your thumbnail.

SD card speed ratings, and why they matter

However, the fact that SD cards are now so commonplace sometimes conceals the fact that not all SD cards are created equal. SD cards have a speed rating – how fast you can read or write data to the card – and as card sizes have increased, so have speed ratings. If you want to store 4K video from your digital camera, it is important not just that the card is big enough to hold it, but also that you can write it to the card fast enough to keep up with the huge amount of data coming out of the camera.

The speed of an SD card will also directly affect how fast your Raspberry Pi runs, in just the same way as the speed of a hard drive affects how fast a conventional desktop computer runs. The faster you can read data from the card, the faster your Raspberry Pi will boot, and the faster programs will load. Equally, write speed will also affect how well any programs which save large quantities of data run – so it’s important to use a good-quality card.

What speed can I expect from my SD card?

The speed rating of an SD card should be printed either on the card itself or on the packaging.

The 32GB card shown below is Class 4, denoted by the 4 inside the letter C – this indicates that it can write at 4MB/s.

The 64GB card shown below is Class 10, and so can write at 10MB/s. It also shows the logo of UHS (“ultra high speed”) Class 1, the 1 inside the letter U, which corresponds to the same speed.

More recently, speeds have started to be quoted in terms of the intended use of the card, with Class V10 denoting a card intended for video at 10MB/s, for example. But the most recent speed categorisation – and the one most relevant to use in a Raspberry Pi – is the new A (for “application”) speed class. We recommend the use of Class A1 cards (as the one above – see the A1 logo to the right of the Class 10 symbol) in Raspberry Pi – in addition to a write speed of 10MB/s, these support at least 1500 read operations and 500 write operations per second. All the official Raspberry Pi microSD cards we sell meet this specification.

A new tool for testing your SD card speed

We’ve all heard the stories of people who have bought a large capacity SD card at a too-good-to-be-true price from a dodgy eBay seller, and found that their card labelled as 64GB can only actually hold 2GB of data. But that is at least fairly easy to spot – it’s much harder to work out whether your supposedly fast SD card is actually meeting its specified speed, and unscrupulous manufacturers and sellers often mislabel low quality cards as having unachievable speeds.

Today, as the first part of a new suite of tests which will enable you to perform various diagnostics on your Raspberry Pi hardware, we are releasing a tool which allows you to test your SD card to check that it performs as it should.

To install the new tool, from a terminal do

sudo apt update
sudo apt install agnostics

(“agnostics”? In this case it’s nothing to do with religion! I’ll leave you to work out the pun…)

Once installed, you will find the new application “Raspberry Pi Diagnostics” in the main menu under “Accessories”, and if you launch it, you’ll see a screen like this:

In future, this screen will show a list of the diagnostic tests, and you will be able to select which you want to run using the checkboxes in the right-hand column. But for now, the only test available is SD Card Speed Test; just press “Run Tests” to start it.

Understanding your speed test results

One thing to note is that the write performance of SD cards declines over time. A new card is blank and data can be written to what is effectively “empty” memory, which is fast; but as a card fills up, memory needs to be erased before it can be overwritten, and so writes will become slower the more a card is used. The pass / fail criteria in this test assume a new (or at least freshly formatted) card; don’t be alarmed if the write speed test fails when run on the SD card you’ve been using for six months! If you do notice your Raspberry Pi slowing down over time, it may be worth backing up your SD card using the SD Card Copier tool and reformatting it.

The test takes a minute or so to run on a Raspberry Pi 4 (it’ll take longer on older models), and at the end you’ll see a results screen with either (hopefully) PASS or (if you are less fortunate) FAIL. To see the detailed results of the speed test, press “Show Log”, which will open the test log file in a text editor. (The log file is also written to your home directory as rpdiags.txt.)

We are testing against the A1 specification, which requires a sequential write speed of 10MB/s, 500 random write operations per second, and 1500 random read operations per second; we run the test up to three times. (Tests of this nature are liable to errors due to other background operations accessing the SD card while the test is running, which can affect the result – by running the test multiple times we try to reduce the likelihood of a single bad run resulting in a fail.)

If the test result was a pass, great! Your SD card is good enough to provide optimum performance in your Raspberry Pi. If it failed, have a look in the log file – you’ll see something like:

Raspberry Pi Diagnostics - version 0.1
Mon Feb 24 09:44:16 2020

Test : SD Card Speed Test
Run 1
prepare-file;0;0;12161;23
seq-write;0;0;4151;8
rand-4k-write;0;0;3046;761
rand-4k-read;9242;2310;0;0
Sequential write speed 4151 kb/s (target 10000) - FAIL
Note that sequential write speed declines over time as a card is used - your card may require reformatting
Random write speed 761 IOPS (target 500) - PASS
Random read speed 2310 IOPS (target 1500) - PASS
Run 2
prepare-file;0;0;8526;16
...

You can see just how your card compares to the stated targets; if it is pretty close to them, then your card is only just below specification and is probably fine to use. But if you are seeing significantly lower scores than the targets, you might want to consider getting another card.



[*] unless you’re using PXE network or USB mass storage boot modes of course.

66 comments
Jump to the comment form

Avatar

Hi,

is this Free Software? If yes, where can I find the code?

CU
Jens

Reply to Jens Kuehnel

Avatar

Just run the two lines of code given in the text “sudo apt update and sudo apt install agnostics” and it will load.

Reply to George Spak

Avatar

The term ‘Free Software’ means open source. It’s a Linux thing.

Reply to Dragon0307

Avatar

Free and Open Source are two different things.

Reply to Weldo

Avatar

Is there a source repo we can use if we want to contribute to it, or pull from if we want to build packages for other distributions?

Reply to Rick

Avatar

If you want the source, just get it from apt – “apt source agnostics”.

Reply to Simon Long

Avatar

apt info says the homepage of the package is at https://github.com/raspberrypi-ui/agnostics but this either doesn’t exist, or is private. Will it be making at appearance at some point? See my previous comments for a couple of ideas I had for minor improvements which I would like to contribute.

Avatar

We make some repos available in the raspberrypi-ui project of Github, but we do not guarantee that they will always be visible or accessible externally; it is sometimes necessary to keep work in progress confidential. The agnostics repo will probably be made accessible at some point, but it is possible that it is one of the repos which may need to be hidden from time to time, so people shouldn’t assume it will always be there.

apt should always be the primary means of access to our source code, not least because it reflects the software as actually released rather than including work-in-progress features.

Avatar

Thank you for the clarification. I’m always rather dubious about suggesting such minor changes without actually submitting a PR, as they seem a bit nit-picky, hence my query.

Avatar

good news

how about ssd direct boot on pi4

Reply to croft

Avatar

I agree it is well overdue.

Reply to Colin Tinker

Avatar

How about keeping to the topic in hand rather than bringing up the same topic time after time on unrelated threads. When its done it will be announced. It’s not been announced in this blog post, so that means its not ready to be announced. Which means it’s not finished yet. Keeping asking for it does not make the work proceed any faster, and in some cases, just annoys the engineers enough to slow them down.

Reply to James Hughes

Avatar

You can use and execute from USB by booting initially from the SD card. There is a Youtube video by Andreas Spiess called Boot a pi4 with an SSD.

Reply to Art

Avatar
Avatar

Coincidentally, Explaining Computers published this related video a few days ago :-)
https://www.youtube.com/watch?v=oLQ8A_vcBqU

Reply to AndrewS

Avatar

Wouldn’t bonnie work as well? At least on the console?

Reply to Jack Tramiel

Avatar

Piagnostics?

Reply to RichardH

Avatar

Is there a command line version?

Reply to andrum99

Avatar

Yes – all the tests in agnostics are shell scripts which are called from the GUI shell. Run /usr/share/agnostics/sdtest.sh from the command line.

Reply to Simon Long

Avatar

Incidentally that installed here with the wrong permissions – no X bit. There’s also a warning on line 34 “can only return from function or sourced script”

Reply to Chris

Avatar

That’s not actually wrong – the script is executed by the /usr/bin/agnostics binary by calling /bin/sh directly – it ignores the shebang line altogether. The shebang line in the script should probably point to /bin/sh as well, rather than /bin/bash though, or be removed altogether, since the agnostics binary ignores it. (/bin/sh on Raspbian Buster seems to be dash by default, rather than bash).

The warning is a bashism – dash doesn’t complain that the return value is ignored.

So if you want to run sdtest.sh on its own, invoke it like this:

sh sdtest.sh

Reply to andrum99

Avatar

Ah, OK, thanks!

Avatar
Avatar

Tried to run on Raspbian Buster Lite

It started but exited with error
fio: job startup hung? exiting.

Reply to Milliways

Avatar

How to run this outside of Raspberry Pi? So I can test a few sd cards before choosing one to flash the system.

Reply to Cyber Killer

Avatar

A well established, comprehensive and free disk test for the PC world is CrystalDiskMark
https://crystalmark.info/en/software/crystaldiskmark/
It can test removable memory (SD card, USB stick, Compact Flash, XQD…) and will also give you figures for hard disk drives and SSDs, whether they’re connected via USB, FireWire, SATA or pieces of damp string.
(Spoiler alert: damp string isn’t a generally recognised interface type).
I’m not associated with the software provider.

Reply to Giles

Avatar

This is a great addition..if it fails does reformatting bring it back to a usable state. At what point should the card be thrown away? Also how large of an SD card can the pi support?
Thanks again.

Reply to Don Isenstadt

Avatar

Reformatting should make a significant difference to write speed on an old card; if it doesn’t, your card has probably had it!

Reply to Simon Long

Avatar

I’m not sure that just reformatting will help, it will of course depend on how clever the FTL (flash translation layer) is. But I believe if you write zeros to the whole flash, it will then know that every sector is empty and therefore it’s use of free space will improve

Reply to Gordon Hollingworth

Avatar

I’ve long noticed that heavily used SD cards in Raspberry Pis degrade their speed over time, and can vouch for a full overwrite format usually restoring them.

Using HDTUNE Free version ( https://www.hdtune.com/ ) to plot a graph of transfer speed and access time across the whole card is interesting – a good new card should have a flat line, heavily used cards will show wild fluctuations.

I usually then use the SD Card association format tool ( https://www.sdcard.org/downloads/formatter/ ) with options set to Format Type : Full Overwrite and Format Size Adjustment to ON (removes partitions!)

This can take a while as it writes zeros to the entire card, but upon re-running HDTUNE and observing the graph, a noticable improvement can usually be seen.

These tools are Windows only (HDTUNE) and Windows/Mac (SDFormat) so I would be interested in Unix and especially Pi-specific tools or scripts that perform these tasks.

Thanks for this Speed Test Tool, it’s a handy little thing!

Reply to Ian Andrews

Avatar

A lot of mixing oranges with apples here. There are two layers involved: first, the card’s own wear leveling mechanism together with its flash cell hardware. Second, the file system you’ve formatted on top of it.

For (1), no formatting in the world will make your worn out flash cells return back to factory-new conditions. If it would, we wouldn’t need wear leveling.

This brings us to (2): the file system. Unless you use FAT and then mount a kernel-supported bootable file system on top, the existing file systems do not degrade to much over time. The lazarus-like speed improvements reported here can happen only on especially degraded FAT(xx) file systems, where a clean fs performs much better than a fragmented old one.

This matches from what my colleagues here see with sd cards degrading over time and no reformatting brings them back to initial performance.

But maybe you all here want to buy this incredible electromagnetic necklace which controls your mood by playing electromagnetic sound wave files and reformatting your brain’s neurons?

Reply to TheDiveO

Avatar

Reformatting the card may or may not bring it back to performance that meets the A1 specs. Some cards just don’t have the raw performance to begin with.

The official limit of the size of microSD cards supported by the Raspberry Pi is 32GB. The reason is that larger cards require SDXC support. Compliance with that spec requires support of the exFAT file system, which has to be licensed from Microsoft. Microsoft approved royalty-free inclusion of exFAT in the Linux kernel in 2019 and the code is now part of recent kernels, but the specifications of the Pi have not yet been updated to reflect that. (Also note that the inclusion in the kernel is not a license to use exFAT royalty-free in all cases; commercial sale of products in categories where royalties are required will still have to pay.)

Even before availability of exFAT code in Linux, the Raspberry Pi 3 and 4 already supported larger SD cards if they were formatted with other file systems such as ext4. I can personally verify that a 512GB microSD card will work in a Raspberry Pi 4, though I only tried it out to see if it would work; none of my normal uses for the Pi require that much space.

Reply to Shirley Dulcey

Avatar

Can you change the script to clarify the units slightly? Currently it says the sequential write is measured in kb/s, which is slightly ambiguous (could be bits or bytes). KB/sec would be a more standard way of writing that.

Reply to andrum99

Avatar

I watched the video Andrew mentioned ..excellent..I am looking forward to the next video, #4 in the series where he shows the performance on single board computers..

Reply to Don Isenstadt

Avatar

Could you explain the pun please?

Reply to bear

Avatar

On RPi3B with Stretch, “sudo apt update; sudo apt install agnostics” results in “E: Unable to locate package agnostics”.

Then “wget http://rpi.rutgers.edu/archive.raspberrypi.org/debian/pool/main/a/agnostics/
tar -xvf *.xz
cd agnostics
./autogen.sh
results in “./autogen.sh: 4: ./autogen.sh: autoreconf: not found”

Me thinks to stop here and let the masters cogitate.

Reply to Alan

Avatar

It’s not in the stretch repo; only in the buster repo. We’ve not tested it on stretch; it ought to work, but we don’t have the resource to test new programs against old versions of the OS.

Reply to Simon Long

Avatar

I also find f2fs speeds up read/write access on SD cards. Maybe with this tool I can finally quantify this!

Reply to Chris

Avatar

Sorry for the noob question, but does writing a new disk image to the MicroSD card with Etcher make it “freshly formatted” card? That is, does it clear out the previously written data and speed the card back up? Or do we need to do a full format first, then write the disk image? Thanks

Reply to Andy Spinks

Avatar

Great news indeed! I think the article lacks a clarification: should agnotic be used on the sdcard you just installed raspbian on, or on a different sdcard (e.g. plugged into the usb port using an adapter)?

Reply to odameron

Avatar

This doesn’t appear to be in the stretch repo’s yet? Is this accidental or is this program only intended for Buster?

Reply to Ralphius

Avatar

Since the launch of buster, we’ve only been adding new programs to the buster repos. It’s too time-consuming to test everything on old versions of the OS; we always recommend keeping your OS up to date, unless there’s a really compelling reason not to do so.

Reply to Simon Long

Avatar

Is there an equivalent of TRIM to tell an SD card that a block is unused? Or do you have to write all-zeros or all FFs to a block to do that?

Reply to Jonathan Pallant

Avatar

Yes, the blkdiscard tool can do this (it’s called erase for SD cards). It only works with non-USB card readers (PCIe or the Pi’s reader will work).

But be careful with this tool. You can destroy data on entire drives (like SSDs or SD cards) withing seconds with this!

Reply to pica200

Avatar

Yes, a lot of SD cards support TRIM or some equivalent. fstrim should work on your SD card.

Reply to Chris

Avatar

I would suggest that the trim function may work, but it is very much SD card specific (and since trim is an MMC command, most SD cards won’t support it).

Writing zeros to the card is the best way to ‘tell’ the card that a sector is unused

Reply to Gordon Hollingworth

Avatar

If I copy a Raspbian image to a fresh sd-card using dd, and then boot it which will then expand the root partition to fill the sd-card, would it then be sensible to do something like “dd if=/dev/zero of=/zero.bin; rm /zero.bin” to make sure all the free space is known to be free to the card?

And I suppose following on from that, would creating/deleting a “zero.bin” file be enough to freshen-up a card that’s in use?

Reply to Peter Ryan

Avatar

it is mention to use a new formated SD card.
is it only for performance reason or will the test “destroy” data on the SD card.

Reply to beta-tester

Avatar

will executing
sudo e4defrag /
help to increase performance on a long time used SD card or is it only relevant on mechanical HDD’s?

Reply to beta-tester

Avatar

Defragmentation isn’t as much of an issue with flash based devices because they have a ‘virtual addressing’ system anyway (the flash translation layer). But since the granularity of the virtual addressing (the equivalent of page size in virtual memory) is unlikely to be the same as the sector size on the filesystem then it is possible it may make a small difference.

But the biggest difference would be created by writing zeros to all unused sectors of the card…

Gordon

Reply to Gordon Hollingworth

Avatar

Is agnostic only testing the sdcard you installed raspbian on in the sd card slot, or can it be used on a different sdcard (e.g. plugged into the usb port using an adapter)? If so, how – there seems to be no choice of what sd card to choose (I had one plugged in with a usb card reader in addition to the operating system sd card). It simply tested the sd card with the operating system as far as I could tell (pass, btw).

Reply to Mark Rosenzweig

Avatar

It tests whatever device currently containst the directory /var/tmp. If you want to test another device, modify the relevant line in sd_bench.fio to select a directory on the device you want to test.

Reply to Simon Long

Avatar

sd_bench.fio can be found in the /usr/share/agnostics directory, along with the sdtest.sh script which executes it.

(sdtest.sh is in turn run by the /usr/bin/agnostics binary, which is the GUI app).

Reply to andrum99

Avatar

Is there a CLI option to run the tool? A lot of people, including me, never use the GUI much.

Reply to Protik

Avatar

It’s quite simple

apt-get install fio -y
mkdir /usr/share/agnostics/
curl https://raw.githubusercontent.com/raspberrypi-ui/agnostics/master/data/sd_bench.fio -o /usr/share/agnostics/sd_bench.fio
curl https://raw.githubusercontent.com/raspberrypi-ui/agnostics/master/data/sdtest.sh -o /usr/share/agnostics/sdtest.sh
chmod +x /usr/share/agnostics/sdtest.sh
/usr/share/agnostics/sdtest.sh

Reply to elmariofredo

Avatar

Well, running from SSD gave an easy PASS :)

Raspberry Pi Diagnostics – version (unknown)
Fri Mar 6 13:21:38 2020

Test : SD Card Speed Test
Run 1
prepare-file;0;0;313569;612
seq-write;0;0;313569;612
rand-4k-write;0;0;69057;17264
rand-4k-read;77557;19389;0;0
Sequential write speed 313569 kb/s (target 10000) – PASS
Random write speed 17264 IOPS (target 500) – PASS
Random read speed 19389 IOPS (target 1500) – PASS
Test PASS

… but I would like the option of testing the actual SD card (which is still there, because it’s a Pi4). Have you considered this? Thanks.

Reply to Ed

Avatar

You can read the info from Simon on the post below,
https://www.raspberrypi.org/blog/sd-card-speed-test/#comment-1523686

I have tested my usb stick by changing the parameter ‘Directory=’ in sd_bench.fio and it works.

Reply to Pearl.852

Avatar

My SD card SanDisk gives a result of 19349 kb/s in writing which makes about 20Mo/s, is it a good performance for a class 10 card ?

Thank you in advance

A great fan of Raspberry Pi.

Reply to PETITEAU

Avatar

* I have occasionally used a Pi zero as a micro-USB to pinheader power adapter which works best without a micro-SD-card.

Reply to Kiste

Avatar

what other diagnostic tests are in pipeline?

Reply to snowballearth

Avatar

Thanks for this!

It would be great if there were a “Details” button after the test, to reveal in the GUI, the measured IOPS, etc, should the user be the geekier type who wants to see more than just “Pass” or “Fail”.

Reply to Esbeeb

Avatar

Oops, I guess you do have the “Show Log” button. My bad.

Reply to Esbeeb

Avatar

Is this package only for Buster?
I tried this with Raspbian Stretch.
Result:
E: Unable to locate package agnostics

Reply to max11

Avatar

pushing this up …
Will it be available for Raspbian stretch?? (Raspi 3b+)

Reply to max11

Avatar

I took a brand new Samsung EVO Select 32GB card, loaded up Raspbian (FULL). Stuck it in an RPi4B (4GB) and booted it. after answering the start-up questions I installed agnostics and ran the test – PASSED, then I did an apt-get upgrade -y, & reran the test and it FAILED. Since these steps are normal to my install procedure, I question the value of the tests. I tried other cards (cheap ones always FAILED). Now I’m ordering several different models of cards (All SanDisk) and see if I can find any that pass this simple test. OBTW the upgrade only hit 4 packages, so there was little upgrading that was done. I imagine if I wait a month or so and rerun upgrade, the test will fail misserably. So I ask… Is this test even worth running?

Reply to jim brown

Leave a Comment