mikaey00

joined 1 year ago
[–] [email protected] 1 points 1 year ago (1 children)

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.

[–] [email protected] 2 points 1 year ago

I'm actually working on a script for a YouTube video right now. Might also make a blog post about it, I dunno.

[–] [email protected] 2 points 1 year ago (3 children)

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.

[–] [email protected] 1 points 1 year ago