4
submitted 11 months ago by mikaey00@alien.top to c/homelab@selfhosted.forum

So I took it upon myself to answer the question of “what are the best and cheapest microSD cards out there?” This includes evaluating whether they’re fake flash, how well they perform, and how many read/write cycles they can endure before they start failing. So far I’ve tested four to the point of failure, I have 37 being tested right now, and I have 21 more waiting to be tested.

Sorry for the horrendous cable management — I have cable ties on order.

you are viewing a single comment's thread
view the rest of the comments
[-] Buttafuoco@alien.top 0 points 11 months ago

What are your methods for testing?

[-] mikaey00@alien.top 2 points 11 months ago

So I'm testing for three things:

  • Capacity
  • Performance
  • Endurance

Capacity

Divide the card up into eight equal segments. Within each segment (except for the first), choose a random starting location. Write 4MB of random data to the very beginning of the card, the very end of the card, and to each of the other 7 randomly selected locations. Then, read back each segment and compare the data read to what was written. If all 9 segments match, the card is considered "not fake flash". Otherwise, the space between the last "good" segment and the first "bad" segment is bisected until the point at which "bad" sectors begin to appear is determined. The device is considered to be "fake flash"; the capacity is declared to be the amount of space between the start of the device and the last "good" sector.

It's not a perfect strategy -- cause it doesn't account for wraparound flash or flash that is bad from the very beginning -- but it gets it right 98% of the time.

Performance

There's two components to this: a sequential read/write test and a random read/write test.

For the sequential read/write test: start from the very beginning of the device. For 30 seconds, read as much data as possible in a sequential fashion, recording the total number of bytes read. At the end of 30 seconds, take the total number of bytes read and divide by 30. The device's sequential read speed is considered to be this result (measured in bytes per second). For the sequential write test -- do the same thing, but generate random data and write it to the device.

For the random read/write test: Choose a random sector on the device. Read 4KB of data from the chosen sector. Repeat this process for 30 seconds, keeping count of the number of read operations completed. Take the final result and divide by 30. The device's random read speed is considered to be this result (measured in IOPs per second). For the random write test -- do the same thing, but generate random data and write it to the device.

Again, this isn't perfect. It's probably good enough for determining whether a device meets the requirements for Class2/Class4/Class6/Class10, but the video speed classes (V6/V10/V30/V60/V90) require some special commands to be issued to the card that just can't be issued via most USB card readers. Also, I didn't read the specific set of conditions for testing for the A1/A2 speed classes -- so my program can probably get you in the neighborhood of the right number, but won't be 100% accurate.

Endurance

Divide the card into 16 equal segments. Shuffle the segments into a random order. For each segment, write pseudorandom data to the entire segment.

Shuffle the segments into a random order again. For each segment, read back the data. Regenerate the pseudorandom data that was originally written to the segment and compare it to what was written. If there is a mismatch in any given sector, the sector is flagged as "bad".

(If an I/O error is encountered on any given sector, the operation is retried several times -- including resetting the device if necessary and/or waiting for the device to be reconnected. If all attempts fail, the sector is flagged as "bad".)

Keep a count of the number of complete read/write cycles that have been performed against the device.

Repeat until at least 50% of the sectors on the device have been flagged as "bad", or until an unrecoverable I/O error has occurred.

[-] Buttafuoco@alien.top 1 points 11 months ago

If the data being written is random how do you know what was written? Is it a known pattern? Something calculated given its address space?

For perf randread/write test, why was 4KB chosen?

For endurance do you have access to any hardware metrics to compare the running test? The drives should be self reporting endurance, each vendor may vary slightly in how they express it

[-] mikaey00@alien.top 1 points 11 months ago

If the data being written is random how do you know what was written? Is it a known pattern?

Essentially, yes. I use the random()/srandom() calls in the C library, which generates random numbers in a deterministic fashion using a given seed as the starting point. I generate unique seeds for each segment and each pass. When reading back a particular segment, I just set the seed back to the same value that I used when I originally wrote the data.

For perf randread/write test, why was 4KB chosen?

Because that's what's dictated by the SD card specification.

For endurance do you have access to any hardware metrics to compare the running test? The drives should be self reporting endurance, each vendor may vary slightly in how they express it

Nope. SD cards don't have SMART data like hard drives/SSDs do. I can't find anything in the SD spec that tells you how to figure out how long the card has been operating or how much data has been written to it.

[-] Buttafuoco@alien.top 1 points 11 months ago

Thanks for these thorough responses 😃.

load more comments (1 replies)
load more comments (1 replies)
this post was submitted on 21 Nov 2023
4 points (100.0% liked)

Homelab

371 readers
2 users here now

Rules

founded 1 year ago
MODERATORS