Part 7 of 7 · 3 min read
Exercises
Easy
Easy 1: Blocks in a drive (20 minutes)
Pages are 4 KiB and a block has 64 pages. How many blocks make 1 GiB?
Done when: 4,096 blocks (1 GiB / 256 KiB).
Hint
a block is 64 x 4 KiB = 256 KiB. Divide 1 GiB by it.
Easy 2: Compute the amplification (20 minutes)
A host writes 10 GB and the drive programs 25 GB. Find the write amplification.
Done when: 2.5.
Hint
divide flash writes by host writes.
Easy 3: One victim block (20 minutes)
A victim block is 50% valid. What is the write amplification of collecting it?
Done when: 2, from 1 / (1 - 0.5).
Hint
use the formula with u = 0.5.
Medium
Medium 1: Cost of one collection (45 minutes)
A victim has 48 valid pages out of 64. Reading takes 50 microseconds, programming 500 microseconds, and erasing 3 ms. Find the time of one collection, and the number of host pages that it makes room for.
Done when: 29.4 ms (48 x 550 microseconds + 3 ms) and 16 pages, giving a write amplification of 4.
Hint
copying a page is one read and one program. Add the erase once.
Medium 2: Drive life (45 minutes)
A 512 GB drive has blocks that last 1,000 cycles. The write amplification is 3 and the host writes 200 GB per day. How long does it last?
Done when: 170.7 TB of host writes, 853 days and about 2.3 years.
Hint
total writable = capacity x cycles. Divide by write amplification, then by the daily writes.
Medium 3: Run the simulator (45 minutes)
Compile the program of section 3 and run it with spare values of 10, 20, 25, 40 and 50. Make a table.
Done when: five rows of write amplification that fall as spare space grows (6.62, 2.97, 2.36, 1.52 and 1.27 on glibc 2.39), and one sentence on why.
Hint
pass the spare value as the first argument on the command line.
Hard
Hard 1: Check the identity (90 minutes)
Change the simulator to count the valid pages that it copies in all collections. For three spare values, compute the average valid pages per victim and check that write amplification equals 64 / (64 - average).
Done when: a table of three rows in which both values agree to two decimals, for example 36.9 valid pages and 2.36 at 25% spare.
Hint
add a counter in collect that adds one for each valid page it copies. Divide by the erase count.
Hard 2: Measure the wear (90 minutes)
Add an erase counter for each block. Run 200,000 writes at 25% spare and report the minimum and the maximum count. Then add a rule: when a block has been erased 50 times more than the least-erased block, swap their roles by moving cold data. Report the new spread.
Done when: a first spread of about 0 to 122 erases and a second spread that is narrower, with the write amplification of both runs.
Hint
keep eb[NB] incremented where the block is erased. Print the minimum and maximum at the end.
Hard 3: Simulate TRIM (90 minutes)
Make the simulator use only 80% of its logical pages for writes, with the other 20% trimmed (never filled). Run it at 10% spare, and compare it with the plain run at 10% and at 28% spare.
Done when: a write amplification near 2.1 for the trimmed run, close to the 2.11 of the plain run at 28% spare, against 6.62 at 10%, with a sentence explaining why.
Hint
set nlog to 80% of its usual value in both the fill loop and the random write.