COMP 3150Operating Systems

01 Introduction

Lesson 11.1 presented the hard disk's geometry — the platters, the heads, the tracks, and the cylinders — and showed that a read's cost is dominated by the seek and the rotational delay. Lesson 11.5 presented the disk scheduling algorithms that minimize the head's movement, and Lesson 11.6 presented the RAID arrays that combine several disks for the performance and the reliability. This lesson presents the solid-state drive: the device that has no heads to seek and no platters to rotate, and whose characteristics have reshaped the storage stack's design.

An SSD stores data in flash memory, a kind of non-volatile semiconductor memory. The flash's physics differ from the magnetic disks' in ways that matter to the entire stack:

  • No mechanical delay. An SSD has no moving parts, so its access time is dominated by the flash memory's read latency (tens of microseconds) and the controller's overhead, and the difference between the sequential and the random access is far smaller than a hard disk's. The observation is the reason the disk scheduling algorithms' seek-reduction (Lesson 11.5) is less important on an SSD.
  • Erase-before-write. Flash memory cannot be overwritten in place: a block must be erased before it can be written, and the erase operation works on a much larger unit (the erase block, typically 256 KB to several MB) than the read/write unit (the page, typically 4 KB to 16 KB). The asymmetry is the source of the flash translation layer (FTL), the garbage collection, and the write amplification that shape the SSD's behaviour.
  • Limited write endurance. Each flash cell can be erased and rewritten only a limited number of times (typically a few thousand cycles for the consumer drives, more for the enterprise drives). The limit is the source of the wear leveling, the technique that spreads the writes across the cells so that the drive's lifetime is determined by the total number of writes rather than by the hot spots' exhaustion.
  • Internal parallelism. An SSD contains many flash chips, and the controller can access several of them in parallel. The parallelism is the source of the SSD's high throughput, and it is the reason the drive can satisfy many concurrent requests without degrading. The NVMe protocol's queue-based interface (Lesson 11.4) is designed to exploit the parallelism.

The four characteristics explain the modern storage stack's design. The flash-specific file systems (Lesson 10.7's F2FS) are designed around the erase-before-write constraint and the internal parallelism. The disk schedulers' adaptation (Lesson 11.5's Kyber and the no-op scheduler) reflects the seek-reduction's reduced importance and the queue-depth's increased importance. The RAID's adaptation (Lesson 11.6's preference for the mirroring over the parity on the SSDs) reflects the write amplification's significance. And the modern file systems' and applications' I/O patterns (sequential writes, aligned writes, the TRIM command) are designed to cooperate with the FTL and the garbage collection rather than to fight them.

This lesson presents the SSD's architecture. It presents the flash memory's fundamentals — the floating-gate cell, the NAND and the NOR technologies, and the SLC, MLC, TLC, and QLC variants. It presents the memory's organization — the cells, the pages, the erase blocks, the planes, the dies, and the channels — and the read, write, and erase operations' asymmetries. It presents the flash translation layer and its address mapping (the page-level, the block-level, and the hybrid), the garbage collection, the write amplification, and the wear leveling. It presents the TRIM command and the drive's internal parallelism. It presents the host interface (the SATA/AHCI and the NVMe), the SSD's performance characteristics (the IOPS, the throughput, the latency, and the tail latency), its reliability (the endurance, the wear-out, and the SMART attributes), and the modern developments (the open-channel SSDs, the ZNS, and the host-managed flash). It closes with the SSD's design trade-offs and the storage stack's future.

Prerequisites

This lesson builds on Lessons 11.1 through 11.6. The I/O subsystem's layers, the interrupt and the DMA mechanisms, the device driver and the block layer's request queue, the disk scheduling algorithms, and the RAID levels are all assumed. The file systems' allocation and journaling (Lessons 10.5 and 10.6) and the flash-specific file systems (Lesson 10.7's F2FS) are the context for the discussion of the SSD's interaction with the file system. No new operating-system concepts are introduced; the lesson is about the SSD's internal architecture and its effect on the storage stack. Familiarity with the Linux command line from Lesson 2.2 is helpful, since the interactive activity uses fio, smartctl, and blkdiscard.

02 Learning objectives

By the end of this lesson you will be able to

  • Describe the flash memory's fundamentals: the floating-gate cell, the NAND and the NOR technologies, and the SLC, MLC, TLC, and QLC variants.
  • Describe the flash memory's organization (the cells, the pages, the erase blocks, the planes, the dies, and the channels) and explain the read, write, and erase operations' asymmetries.
  • Describe the flash translation layer and its address mapping (the page-level, the block-level, and the hybrid), and explain the garbage collection and the write amplification.
  • Explain the wear leveling (the dynamic and the static), the TRIM command, and the drive's internal parallelism.
  • Describe the host interfaces (the SATA/AHCI and the NVMe) and the SSD's performance characteristics (the IOPS, the throughput, the latency, and the tail latency).
  • Describe the SSD's reliability characteristics (the endurance, the wear-out, the failure modes, and the SMART attributes) and the modern developments (the open-channel SSDs, the ZNS, and the host-managed flash).

This lesson contributes to U11.7 and the unit's synthesis, and to course learning outcomes CLO1, CLO5, CLO6, and CLO7.

03 Required reading

  • Operating System Concepts — Chapter 11, Mass-Storage Structure, Section 11.1, Overview of Mass-Storage Structure (the discussion of the solid-state drives), and Section 11.2, Disk Scheduling (the discussion of the flash-based devices' scheduling).
  • OSTEP — Chapter 44, Flash-based SSDs. OSTEP's treatment of the flash memory's organization, the flash translation layer, the garbage collection, and the write amplification is the clearest available account, and it is the basis for the worked example in this lesson.
  • Tanenbaum & Bos — Modern Operating Systems, Chapter 5, Section 5.4.4, Solid-State Drives. A complementary treatment that develops the flash memory's characteristics from first principles.
  • Agrawal, N., Prabhakaran, V., Wobber, T., Davis, J. D., Manasse, M., & Panigrahy, R. — Design Tradeoffs for SSD Performance. USENIX Annual Technical Conference, 2008. The paper that systematically analyzed the SSD's performance characteristics and their trade-offs.
  • Gupta, A., Kim, Y., & Urgaonkar, B. — DFTL: A Flash Translation Layer Employing Demand-Based Selective Caching of Page-Level Address Mappings. EuroSys, 2009. The paper that introduced the demand-based FTL mapping.
  • Lee, C., Sim, D., Hwang, J., & Cho, S. — F2FS: A New File System for Flash Storage. USENIX FAST, 2015. The design of the flash-specific file system.
  • Bjørling, M., Gonzalez, J., & Bonnet, P. — LightNVM: The Linux Open-Channel SSD Subsystem. USENIX FAST, 2017. The design of the open-channel SSD and the host-managed flash.
  • Linux man pages: man 8 blkdiscard, man 8 fstrim, man 8 smartctl, man 8 nvme, man 1 fio, man 1 iostat, man 5 proc, man 4 sd, man 8 hdparm, man 1 lsblk, man 8 mkfs.f2fs.

Reading strategy

Read the OSTEP chapter first. It develops the SSD's architecture from the flash memory's characteristics — the erase-before-write, the page's and the block's organization, and the endurance's limit — and shows step by step why the flash translation layer, the garbage collection, and the wear leveling are necessary. The chapter's discussion of the write amplification and the FTL's mapping strategies is the basis for this lesson's core content, and its analysis of the SSD's performance is the basis for the worked example. Then read the Silberschatz section for the formal terminology and the survey of the storage devices, and the Tanenbaum section for the complementary view. The Agrawal et al. paper is the empirical study, and it is worth reading for the actual performance measurements and the trade-offs they reveal. The Gupta et al. and Bjørling et al. papers are the FTL's and the open-channel SSD's primary sources, and they are worth reading for the modern designs. Finally, the Linux man pages are the practical tools: blkdiscard and fstrim issue the TRIM command, smartctl reports the drive's health and its endurance, nvme manages the NVMe devices, and fio measures the drive's performance. Pay particular attention to the distinction between the drive's logical view (the block device that the host sees, with its numbered blocks) and its physical view (the flash chips, their pages and erase blocks, and the FTL's mapping between the two). The distinction is the key to understanding the SSD's behaviour: the drive's performance and its lifetime are determined by the physical operations, not the logical ones, and the modern stack's designs are shaped by the FTL's characteristics.

04 Core content

4.1 Flash memory fundamentals

Flash memory is a kind of non-volatile semiconductor memory: it retains its contents when the power is removed, and it can be read, written, and erased electrically. Its storage element is the floating-gate transistor (or, in the modern technologies, the charge-trap cell): a transistor with an additional gate — the floating gate — that is insulated from the rest of the transistor. The floating gate can hold a charge, and the charge's presence or absence determines the transistor's threshold voltage, which the controller's read operation interprets as the cell's value.

The write operation (the program operation) places the charge on the floating gate by applying a high voltage across the transistor's oxide layer; the electrons tunnel through the oxide and are trapped on the gate. The erase operation removes the charge by applying the reverse voltage; the electrons tunnel back through the oxide. The two operations stress the oxide layer, and the layer's degradation is the source of the cell's endurance limit: after a few thousand to a few hundred thousand the program/erase cycles, the oxide is damaged enough that the cell can no longer reliably hold its charge.

The flash memory has two main technologies:

NOR flash
A flash technology that provides the random access (any byte can be read individually), the fast reads, and the slow writes and erases. The NOR flash is used for the code storage (the firmware, the boot loaders, the embedded systems) because the code can be executed in place (the XIP, the execute-in-place). Its capacity is small (the megabytes), its cost per bit is high, and it is not used for the bulk storage.
NAND flash
A flash technology that provides the block access (the reads and the writes are performed on the pages, not the individual bytes), the high density, and the low cost per bit. The NAND flash is used for the bulk storage (the SSDs, the USB drives, the memory cards, the smartphones) because its density and its cost are the best of the flash technologies. Its disadvantages are the block access (the reads and the writes must be the page-aligned), the slow random access (the reads and the writes have a higher latency than the NOR flash's), and the write's and the erase's asymmetry (the write's granularity is the page, and the erase's granularity is the block). The NAND flash is the modern SSDs' technology, and the rest of this lesson refers to it.

4.2 The cell's variants: SLC, MLC, TLC, and QLC

A flash cell's value is determined by the amount of the charge on its floating gate, and the amount can be quantized into the different numbers of the levels. The number of the levels determines the number of the bits the cell stores, and the trade-offs between the density, the performance, and the endurance:

The flash cell's variants
Variant Bits per cell Levels Endurance (P/E cycles) Relative performance
SLC (Single-Level Cell) 1 2 ~100,000 Fastest
MLC (Multi-Level Cell) 2 4 ~3,000–10,000 Fast
TLC (Triple-Level Cell) 3 8 ~1,000–3,000 Moderate
QLC (Quad-Level Cell) 4 16 ~100–1,000 Slowest

The table's pattern shows the trade-offs. The SLC stores one bit per cell, and its two levels (the charged and the uncharged) are the easiest to distinguish, so the cell's endurance and its performance are the highest. The MLC, the TLC, and the QLC store more bits per cell (the four, the eight, and the sixteen levels), and the levels are the closer together, so the controller's read operation must distinguish them more precisely, and the cell's endurance and its performance are the lower. The higher densities' advantages are the capacity and the cost: a QLC cell stores four times the data of an SLC cell, so the drive's cost per bit is much lower. The consumer drives typically use the TLC and the QLC; the enterprise drives use the MLC and the TLC (and, for the write-intensive workloads, the SLC and the MLC).

The cell's variants' differences explain the modern drives' designs. A drive often uses a hybrid approach: a portion of the cells is configured as the SLC (the fast cache, the write buffer), and the rest as the TLC or the QLC (the bulk storage). The drive's controller writes the incoming data to the SLC cache first (the fast writes), and then migrates the data to the TLC or the QLC storage in the background (the slower writes). The design gives the drive the SLC's performance for the bursty writes and the TLC's or the QLC's capacity for the bulk storage, and it is the reason a modern TLC drive's write throughput can exceed the TLC's native rate for the short bursts.

4.3 The flash memory's organization

A flash chip's memory is organized as a hierarchy of the units:

Cell
The storage element: the floating-gate transistor that holds one or more bits. The cell is the smallest unit, and its state is determined by the charge on its floating gate.
Page
The read and the write unit: a group of the cells (typically 4 KB to 16 KB) that is read or written together. The page is the smallest unit that can be read or written, and its size determines the drive's minimum I/O's granularity.
Erase block
The erase unit: a group of the pages (typically 128 to 1,024 pages, or 256 KB to several MB) that is erased together. The erase block is the smallest unit that can be erased, and its size determines the garbage collection's granularity.
Plane
A group of the erase blocks (typically 1,024 to 4,096) that shares the chip's row and column decoders. A chip has two or four planes, and the planes can be accessed in parallel (the multi-plane operations), so the chip's throughput is multiplied by the planes' count.
Die
A single silicon chip. A package (the physical component) can contain several dies (the stacked dies), and each die has its own planes, its own erase blocks, and its own controller's interface.
Channel
The bus (the electrical connection) between the drive's controller and the dies. A drive has several channels (typically 4 to 16), and the dies on different channels can be accessed in parallel. The channels' count and the dies' count per channel determine the drive's internal parallelism, and the parallelism is the source of the drive's high throughput.

The hierarchy's units' sizes are the source of the flash memory's asymmetries. The read and the write's granularity is the page, and the erase's granularity is the erase block, which is 128 to 1,024 times larger. The observation is the source of the erase-before-write's problem: to update a single page, the drive must read the erase block's other pages, erase the block, and write the updated pages and the unchanged pages back. The read-modify-erase-write's cost is the garbage collection's work, and it is the reason the drive's controller maintains the flash translation layer.

The flash memory's organization and the flash translation layer The diagram has two parts. The top part shows the flash memory's hierarchy: a package contains several dies; each die contains several planes; each plane contains several erase blocks; each erase block contains several pages; each page contains many cells. The bottom part shows the flash translation layer: the host's logical page numbers are mapped through the FTL's translation table to the flash's physical page numbers; a write to a logical page allocates a new physical page and updates the mapping, and the old physical page is invalidated; the garbage collection reclaims the invalidated pages by copying the valid pages to a new erase block and erasing the old one. THE FLASH MEMORY'S ORGANIZATION Package (the physical component) Die 0 Plane 0 Erase block 0 Erase block 1 … Plane 1 Erase block 2 Erase block 3 … Die 1 Plane 0 Erase block 0 Erase block 1 … Plane 1 Erase block 2 Erase block 3 … Die 2 Plane 0 Erase block 0 Erase block 1 … Die 3 Plane 0 Erase block 0 Erase block 1 … An erase block's detail: pages within a block Erase block (the erase unit, 256 KB to several MB) Page 0 4–16 KB Page 1 4–16 KB Page 2 4–16 KB … Page 127 (or 255, …) 4–16 KB THE FLASH TRANSLATION LAYER Host (the block device) The file system issues the logical block addresses (LBAs). LBA 100, LBA 101, … Flash Translation Layer (FTL) The controller maps each LBA to the physical page (PPN), updating the mapping table on every write. Mapping: LBA 100 → PPN 4523 Flash (the physical pages) The physical page's location in the die, plane, block, and page. PPN 4523 = Die 1, Plane 0, Block 7, Page 42 A write updates the mapping When LBA 100 is overwritten, the FTL allocates a new physical page (PPN 6100) and updates the mapping to point to it. The old page (4523) is invalidated, but it is not erased until the GC runs. Garbage collection reclaims the invalid pages When a block's valid pages are few, the GC copies the valid pages to a new block, erases the old block, and updates the mapping. The copies add to the write amplification.
Figure 11.7 — The flash memory's organization and the flash translation layer. The top diagram shows the hierarchy: a package contains several dies; each die contains several planes; each plane contains many erase blocks; each erase block contains many pages; each page contains many cells. The erase block is the erase unit, and the page is the read/write unit. The bottom diagram shows the flash translation layer (FTL): the host's logical block addresses (LBAs) are mapped through the FTL's translation table to the flash's physical page numbers (PPNs). A write to an LBA allocates a new physical page and updates the mapping; the old physical page is invalidated but not erased until the garbage collection runs. The garbage collection reclaims the invalidated pages by copying the valid pages to a new erase block and erasing the old one; the copies are the source of the write amplification.

4.4 The read, write, and erase operations

The flash memory's three operations have different characteristics:

  • The read. The read operation senses the cell's threshold voltage and compares it with the reference levels, so it determines the cell's value. The read's granularity is the page, and its latency is tens of microseconds (the SLC's reads are the fastest, and the QLC's are the slowest). The read's endurance is effectively unlimited (the reads do not stress the oxide layer), though the read disturb effect (the reads' repeated voltage's application can shift the neighbouring cells' thresholds) requires the controller to refresh the data periodically.
  • The write (the program). The write operation places the charge on the cell's floating gate, so it sets the cell's value. The write's granularity is the page, and its latency is hundreds of microseconds (the SLC's writes are the fastest, and the QLC's are the slowest). The write's endurance is limited: each write stresses the oxide layer, and the layer's degradation is the source of the endurance limit. The write's constraint is the erase-before-write: the cell must be erased before it can be written, and the erase's granularity is the erase block.
  • The erase. The erase operation removes the charge from the cells, so it resets the erase block to its initial state. The erase's granularity is the erase block, and its latency is milliseconds (the slowest of the three operations). The erase's endurance is the lowest: each erase stresses the oxide layer, and the layer's degradation is the source of the endurance limit.

The three operations' asymmetries are the SSD's design's central constraints:

The flash operations' characteristics
Operation Granularity Latency Endurance
Read Page (4–16 KB) Tens of µs Unlimited (with the read disturb's refresh)
Write (program) Page (4–16 KB) Hundreds of µs Thousands of P/E cycles
Erase Erase block (256 KB–several MB) Milliseconds Thousands of P/E cycles

The table's pattern explains the SSD's design. The read's page granularity and its short latency are why the drive's reads are fast. The write's page granularity and its longer latency are why the drive's writes are slower than its reads. The erase's block granularity and its long latency are why the drive cannot update a page in place: the controller must write the new data to a fresh page and invalidate the old one, and the erase block's reclamation requires the garbage collection's read-modify-erase-write cycle.

4.5 The flash translation layer

The flash translation layer (FTL) is the drive's controller's firmware that hides the flash memory's constraints behind the block device's interface. Its principal function is the address translation: it maps the host's logical block addresses (LBAs) to the flash's physical page numbers (PPNs), and it updates the mapping on every write.

The FTL's translation is the source of the drive's out-of-place update behaviour: when the host overwrites a logical block, the FTL does not overwrite the corresponding physical page (the flash memory cannot); instead, it writes the new data to a fresh physical page, updates the mapping to point to the new page, and marks the old page as invalid. The old page's space is not reclaimed until the garbage collection (the GC) runs.

The FTL's mapping has three principal designs:

Page-level mapping
The FTL maintains a mapping entry for every logical page, so the translation is direct and the write's placement is unconstrained (any free page can be used). The page-level mapping's advantage is its flexibility; its disadvantage is the mapping table's size: for a 1 TB drive with 4 KB pages, the table has 256 million entries, and at 4 bytes per entry, the table is 1 GB — a significant fraction of the drive's RAM.
Block-level mapping
The FTL maps the logical blocks (not the pages) to the physical blocks, and the pages' offsets within the blocks are preserved. The mapping table is much smaller (one entry per block rather than per page), but the write's placement is constrained: the logical block's page must be written to the same offset in the physical block, so the FTL must read the old block's other pages, erase the block, and write the updated pages back — the read-modify-erase-write cycle on every small write. The block-level mapping's write amplification is high.
Hybrid mapping
The FTL combines the two: a small portion of the drive (the log blocks, or the cache) uses the page-level mapping, and the rest (the data blocks) uses the block-level mapping. The write's hot spots are served by the log blocks (the fast, flexible writes), and the cold data is stored in the data blocks (the compact mapping). The hybrid's advantage is the balance between the mapping table's size and the write amplification; its disadvantage is the complexity of the log blocks' management (the merge operations).

The modern drives use a variant of the page-level mapping with the demand-based caching: the full mapping table is stored in the flash (the drive's NAND), and only the working set (the recently accessed pages' mappings) is cached in the drive's RAM (the DRAM or the SRAM). The design (the DFTL, the demand-based FTL) reduces the RAM's requirement while keeping the page-level mapping's flexibility, and it is the modern consumer drives' standard.

4.6 Garbage collection and write amplification

The garbage collection (GC) is the FTL's process of reclaiming the invalid pages' space. The GC selects a victim erase block (typically the block with the fewest valid pages, to minimize the copies), reads the block's valid pages, writes them to a new block, erases the victim, and updates the mapping to point to the valid pages' new locations. The GC's work is the source of the SSD's write amplification:

The write amplification factor (WAF) is the ratio of the physical writes to the logical writes. A WAF of 1 means the drive writes exactly the data the host requested; a WAF of 3 means the drive writes three times the data (the host's writes plus the GC's copies plus the metadata's updates). The WAF is the SSD's central performance and lifetime metric: a higher WAF means a lower effective throughput (the drive's bandwidth is consumed by the GC's copies) and a shorter lifetime (the extra writes consume the cells' endurance).

The WAF depends on the workload's access pattern:

  • The sequential writes. A sequential write fills the erase blocks completely, so the GC's victim blocks have few valid pages (or none), and the GC's copies are minimal. The sequential writes' WAF is close to 1.
  • The random writes. A random write scatters the updates across the erase blocks, so the victim blocks have many valid pages, and the GC must copy them. The random writes' WAF is higher, and it grows with the drive's utilization (a fuller drive has fewer free blocks, so the GC runs more often and copies more data).
  • The over-provisioning. The drive's over-provisioning is the extra capacity (beyond the host's usable capacity) that the FTL uses for the GC's workspace. A larger over-provisioning reduces the WAF (the GC has more free blocks to work with), and it is the reason the enterprise drives (with the higher over-provisioning) have the lower WAFs and the longer lifetimes.
  • The TRIM command. The TRIM (section 4.8) informs the drive which logical blocks are free, so the FTL can invalidate the corresponding physical pages immediately (rather than waiting for the host to overwrite them). The TRIM reduces the WAF by reducing the GC's valid pages' count.

The WAF's typical values are 1.1 to 2 for the sequential workloads, 2 to 5 for the random workloads, and higher for the write-heavy, high-utilization workloads. The values' significance is the reason the modern file systems and the applications are designed to write sequentially and to issue the TRIM: the designs reduce the WAF, which improves the drive's performance and its lifetime.

4.7 Wear leveling

The wear leveling is the FTL's process of spreading the writes across the flash cells, so that no cell is worn out before the others. Without the wear leveling, a workload that repeatedly writes the same logical blocks would wear out the corresponding physical cells, and the drive would fail long before its total capacity's endurance was consumed. The wear leveling's goal is to make the drive's lifetime depend on the total number of writes rather than on the hot spots' concentration.

The wear leveling has two forms:

  • Dynamic wear leveling. The FTL chooses the free blocks for the new writes in a way that spreads the writes across the blocks' erase counts: it prefers the blocks with the lowest erase counts, and it avoids the blocks with the highest counts. The dynamic wear leveling is simple, and it handles the active data (the data that is written frequently), but it does not handle the cold data (the data that is written rarely and never moved): the cold data's blocks are never rewritten, so their erase counts stay low, and the active data's blocks wear out while the cold data's blocks are underused.
  • Static wear leveling. The FTL periodically moves the cold data to the blocks with the higher erase counts (or to the fresh blocks), so the cold data's blocks' erase counts increase and the drive's wear is spread more evenly. The static wear leveling's cost is the extra copies (the cold data's migration), and its benefit is the longer lifetime for the workloads with the mixed hot and cold data. The modern drives use the static wear leveling (or its variants), and the technique is the reason the drives' lifetimes are close to the cells' rated endurance.

The wear leveling's effectiveness is measured by the wear leveling factor: the ratio of the drive's maximum erase count to its average. A factor of 1 means the wear is perfectly even; a factor greater than 1 means some cells are worn more than others. The modern drives' factors are close to 1 (typically 1.1 to 1.3), and the SMART's attributes (the Wear_Leveling_Count and the Media_Wearout_Indicator) report the drive's wear's state.

4.8 The TRIM command

The TRIM (also called the discard) is the command by which the host informs the drive which logical blocks are no longer in use. The command's purpose is to reduce the write amplification: without it, the FTL cannot distinguish a logical block that holds the valid data from one that holds the stale data (the file system deleted the file, but the drive does not know), so the GC copies the stale pages as if they were valid. With the TRIM, the FTL can invalidate the corresponding physical pages immediately, so the GC's valid pages' count is smaller and the copies are fewer.

The TRIM's implementation has three forms:

  • The ATA TRIM command. The SATA drives' TRIM command (the DATA SET MANAGEMENT command), which the host issues for a range of logical blocks. The command's transport is the ATA protocol, and its granularity is the drive's logical block size.
  • The SCSI UNMAP command. The SAS drives' UNMAP command, which the host issues for a list of the logical block ranges. The command is the SCSI's equivalent of the ATA's TRIM.
  • The NVMe Dataset Management command. The NVMe drives' command, which the host issues for a list of the logical block ranges (the dataset management, the DSM). The command is the NVMe's equivalent of the ATA's TRIM, and it is more flexible (the host can specify the ranges' attributes, including the deallocate and the write-zeroes).

The Linux host's TRIM's mechanisms are:

  • The mount option. The discard mount option makes the file system issue the TRIM for the blocks that it frees, so the drive's FTL is informed immediately. The option's disadvantage is the TRIM's per-operation overhead (the command's issue for each free), which can reduce the performance on the workloads with the many small frees.
  • The periodic fstrim. The fstrim command (or the systemd's fstrim.timer) issues the TRIM for all the free blocks periodically (typically the weekly), so the drive's FTL is informed in the batches. The approach's advantage is the lower per-operation overhead; its disadvantage is the TRIM's delay (the blocks are not invalidated until the periodic run).
  • The blkdiscard command. The blkdiscard command issues the TRIM for a whole device or a range, so the drive's FTL invalidates the corresponding pages. The command is useful for the devices' preparation (the secure erase, the thin provisioning's reclamation) and for the testing.

The TRIM's importance is the reason the modern file systems and the storage stacks support it: without it, the drive's WAF is higher, its performance is lower, and its lifetime is shorter. The TRIM's propagation through the RAID and the LVM's layers (Lesson 11.6) is a design challenge, and the modern kernels support it (the mdadm's --discard option, the LVM's issue_discards option) for the devices that support it.

4.9 The SSD's internal parallelism

The internal parallelism is the source of the SSD's high throughput. A drive contains many flash chips (the dies), and the controller can access several of them in parallel:

  • The channel-level parallelism. The drive's controller has several channels (typically 4 to 16), and the dies on different channels can be accessed concurrently. The channels' count determines the drive's channel-level parallelism.
  • The die-level parallelism. The dies on the same channel can be interleaved (the controller issues the operations to the different dies' registers, and the operations execute concurrently), so the channel's throughput is multiplied by the dies' count.
  • The plane-level parallelism. The planes within a die can be accessed concurrently (the multi-plane operations), so the die's throughput is multiplied by the planes' count.
  • The cell-level parallelism. The drive's controller can access the different pages' offsets concurrently (the plane-level and the block-level interleaving), so the drive's throughput is multiplied by the interleaving's degree.

The parallelism's effect is the reason the drive's throughput depends on the queue depth: a single request can use only one channel (or one die, or one plane), so its throughput is limited; several concurrent requests can use the different channels, so the drive's aggregate throughput is the sum. The observation is the reason the NVMe protocol's queue-based interface (Lesson 11.4) is the modern drives' standard: the host can submit thousands of the requests concurrently, and the drive's controller can schedule them across its channels, so the drive's parallelism is fully exploited. The observation is also the reason the disk schedulers' role (Lesson 11.5) is reduced on the SSDs: the scheduler's job is to keep the queue's depth high, not to reorder the requests for the seek's reduction.

4.10 The host interfaces: SATA/AHCI and NVMe

The SSD's host interface determines the drive's performance ceiling and the host's ability to exploit the drive's parallelism:

SATA / AHCI
The SATA (Serial ATA) interface and its AHCI (Advanced Host Controller Interface) command protocol. The SATA's bandwidth is up to 6 Gb/s (about 600 MB/s after the encoding), and the AHCI's command queue has a single queue with 32 slots. The interface was designed for the hard disks (the AHCI's single queue reflects the hard disk's single actuator), and it is the bottleneck for the modern SSDs: the 600 MB/s bandwidth limits the drive's sequential throughput, and the single queue with the 32 slots limits the drive's parallelism's exploitation.
NVMe
The NVMe (Non-Volatile Memory Express) interface and its protocol. The NVMe runs over the PCIe (Lesson 11.1), so its bandwidth is the PCIe's (tens of gigabytes per second). Its command interface is the queue-based design: the drive has thousands of the command queues (the queue pairs), each with thousands of the command slots, and the host submits the commands by writing them to the queues in the memory (the DMA, Lesson 11.3). The queue-based interface is designed for the flash memory's parallelism: the host can submit the thousands of the requests concurrently, and the drive's controller can schedule them across the channels, so the parallelism is fully exploited. The NVMe is the modern high-performance SSDs' standard, and its interface is one of the reasons the NVMe SSDs achieve the millions of the IOPS with the low latency.

The interface's differences explain the modern drives' designs. A SATA SSD's performance is limited by the SATA's bandwidth and the AHCI's queue's depth, so its throughput is at most about 550 MB/s and its IOPS is limited by the queue's depth. An NVMe SSD's performance is limited only by the flash memory's characteristics, so its throughput can be several gigabytes per second and its IOPS can be millions. The observation is the reason the modern high-performance systems use the NVMe devices and the SATA devices are relegated to the legacy systems and the low-performance applications.

4.11 The SSD's performance characteristics

The SSD's performance is characterized by four metrics:

  • The sequential throughput. The drive's bandwidth for the large, sequential reads and writes. The SATA SSDs' sequential throughput is about 500–550 MB/s; the NVMe SSDs' is 2,000–7,000 MB/s (and the PCIe 5.0 devices' is higher). The sequential throughput is limited by the interface's bandwidth (the SATA) or the flash memory's bandwidth (the NVMe), and it is the metric that the large file transfers and the backups care about.
  • The random IOPS. The drive's operations per second for the small, random requests. The SATA SSDs' random IOPS is about 50,000–100,000 (limited by the AHCI's queue's depth); the NVMe SSDs' is 500,000–1,500,000 (the higher-end devices' is more). The random IOPS is limited by the flash memory's parallelism and the controller's scheduling, and it is the metric that the databases and the virtualization care about.
  • The latency. The time an individual request takes. The SSDs' average latency is tens of microseconds (the SATA's is slightly higher than the NVMe's), and the latency's distribution has the tail (the 99th and the 99.9th percentiles) that is much higher than the average. The tail latency is the source of the modern systems' quality-of- service (QoS) concerns: a system that must bound the worst-case latency must account for the SSD's tail.
  • The queue depth's scaling. The drive's throughput as a function of the number of the concurrent requests. The SSD's throughput increases with the queue's depth until it saturates at the drive's maximum (the parallelism's limit). The SATA's queue's depth is limited to 32, so its scaling saturates early; the NVMe's queue's depth is thousands, so its scaling continues further. The observation is the reason the modern systems' applications and the storage stacks are designed to submit the many concurrent requests (the asynchronous I/O, the deep queues), and it is the reason the NVMe's queue-based interface is the modern drives' standard.

The performance characteristics' analysis is the basis for the modern storage stack's design. The file systems' allocation policies (Lesson 10.5) write sequentially and align the writes to the flash memory's pages, so the WAF is reduced and the throughput is improved. The disk schedulers (Lesson 11.5) keep the queue's depth high, so the drive's parallelism is exploited. The applications use the asynchronous I/O (the io_uring, the libaio) and the deep queues, so the drive's parallelism is fully used. And the modern systems' monitoring (the iostat, the fio, the smartctl) tracks the performance's metrics and the drive's health, so the degradation is detected early.

4.12 The SSD's reliability

The SSD's reliability is characterized by the endurance, the failure modes, and the SMART attributes:

  • The endurance. The drive's total data that can be written before the cells wear out, expressed as the terabytes written (TBW) or the drive writes per day (DWPD) over the warranty's period. The endurance depends on the cells' variant (the SLC, the MLC, the TLC, the QLC), the drive's over-provisioning, and the workload's WAF. The consumer drives' endurance is typically 0.3 to 1 DWPD; the enterprise drives' is 1 to 10 DWPD. The endurance is the drive's lifetime's limit, and the workload's WAF determines how quickly the limit is reached.
  • The failure modes. The SSDs' failures differ from the hard disks': the SSDs tend to fail suddenly (the controller's failure, the firmware's bug, the flash's wear-out), rather than the gradual degradation that the hard disks exhibit. The sudden failures make the proactive maintenance less effective, and they are the reason the SSDs' redundancy (the RAID, the backups) is essential. The SSDs also have the read disturb (the reads' repeated voltage's application can shift the neighbouring cells' thresholds) and the retention (the charge can leak over the years, especially at the high temperatures) as their specific failure modes, and the modern controllers manage both (the periodic refresh, the retention's management).
  • The SMART attributes. The SSDs' SMART attributes report the drive's health and its wear:
    • Wear_Leveling_Count (the ID 177): the drive's average erase count (or the remaining life's percentage). The attribute decreases as the drive wears out.
    • Media_Wearout_Indicator (the ID 233): the drive's remaining life's percentage. A value of 100 means the drive is new; a value of 0 means the drive is at its rated endurance's limit.
    • Total_LBAs_Written (the ID 241): the total data that the drive has written, in the logical blocks. The attribute lets the administrator compute the drive's remaining endurance.
    • Reallocated_Sector_Ct (the ID 5): the number of the sectors that the drive has reallocated to the spare area. The attribute's growth is the drive's degradation's signal.
    • Program_Fail_Count and Erase_Fail_Count (the IDs 171 and 172): the number of the program and erase failures. The attributes' growth is the drive's wear-out's signal.

4.13 The modern developments: the open-channel SSDs, the ZNS, and the host-managed flash

The SSD's architecture is evolving, and the modern developments move the flash management from the drive's controller to the host:

Open-channel SSDs
The drives that expose the flash memory's physical interface to the host (the channels, the dies, the blocks, and the pages), rather than the block device's logical interface. The host's software (the host-managed FTL) performs the address translation, the garbage collection, and the wear leveling, so the host can optimize the flash's management for its workload. The open-channel SSDs' advantages are the host's control (the host can align its writes to the flash's pages and blocks, so the WAF is minimized) and the drive's simplicity (the controller's firmware is simpler, so the drive is cheaper and more reliable). The framework's disadvantages are the host's complexity (the host must manage the flash's details) and the ecosystem's immaturity (the host's software must be written for the drives). The Linux kernel's LightNVM subsystem is the open-channel SSDs' support, and the pblk is the kernel's host-managed FTL.
Zoned Namespaces (ZNS)
The NVMe's standard for the zoned storage: the drive's logical address space is divided into the zones, and each zone must be written sequentially (the writes within a zone must start at the zone's beginning and proceed in order). The ZNS's advantage is the alignment with the flash memory's characteristics: the sequential writes reduce the WAF, and the zones' management is simpler than the open-channel SSDs' (the drive still manages the FTL, but the host's writes' pattern is constrained). The ZNS is the modern standard's approach to the host-managed flash, and it is supported by the Linux kernel (the null_blk's ZNS mode, the zonefs file system, and the application's frameworks).
Computational storage
The drives that perform the computation within the storage device (the data's filtering, the compression, the encryption, the search), so the host's processor is offloaded and the data's movement is reduced. The computational storage is an emerging area, and its designs vary from the simple (the fixed-function offloads) to the programmable (the drives with the embedded processors and the software). The approach's promise is the performance (the data's processing at the storage's speed) and the efficiency (the reduced data's movement), and its challenges are the standardization and the software's ecosystem.

4.14 Common misconceptions

"An SSD is just a faster hard disk."

An SSD is a different kind of device. Its physics (the flash memory's cells and their endurance) and its organization (the FTL, the garbage collection, and the wear leveling) differ fundamentally from the hard disk's, and its performance and its failure modes are different. The modern stack's designs (the file systems, the schedulers, the RAID) are shaped by the SSD's characteristics, and they are not the same as the hard disk's.

"The SSD's writes are as fast as its reads."

The SSD's writes are slower than its reads: the write's latency is hundreds of microseconds (versus the read's tens of microseconds), and the write's throughput is reduced by the write amplification (the GC's copies). The asymmetry's source is the flash memory's physics (the program operation's longer latency) and the FTL's out-of-place updates (the GC's work). The modern drives' SLC caches mitigate the asymmetry for the short bursts, but the sustained writes are slower than the reads.

"The SSD's endurance is not a concern."

The SSD's endurance is a real concern: the cells' erase cycles are limited, and the drive's lifetime is determined by the total writes (scaled by the WAF). A consumer drive with a 0.3 DWPD rating can be worn out by a write-intensive workload (a database, a build farm) in a few years. The administrator should monitor the drive's SMART attributes (the wearout indicator, the total writes) and replace the drive before it wears out.

"The TRIM is optional."

The TRIM is important for the SSD's performance and its lifetime: without it, the FTL cannot distinguish the valid data from the stale data, so the GC copies the stale pages and the write amplification is higher. The modern file systems and the storage stacks support the TRIM, and the administrator should enable it (the discard mount option or the periodic fstrim). The RAID and the LVM's TRIM's propagation is a design challenge, and the modern kernels support it for the devices that support it.

"The SSD's performance is the same for all workloads."

The SSD's performance depends on the workload's access pattern. The sequential writes' WAF is close to 1, so their throughput is high; the random writes' WAF is higher, so their throughput is lower. The drive's performance also depends on its utilization: a full drive has fewer free blocks, so the GC runs more often and the WAF is higher. The observation is the reason the modern systems' designs (the file systems' sequential writes, the applications' aligned writes, the over-provisioning) are shaped by the SSD's workload's sensitivity.

"The SSD's tail latency is the same as its average."

The SSD's latency's distribution has a long tail: the average latency is tens of microseconds, but the 99th and the 99.9th percentiles can be hundreds of microseconds or more, because of the garbage collection, the write amplification, and the controller's internal scheduling. The tail latency is the source of the modern systems' QoS concerns, and the applications that must bound the worst-case latency (the databases, the real-time systems) must account for it.

"The SSD's controller does not matter."

The SSD's controller is the drive's most important component: it performs the FTL's translation, the GC, the wear leveling, and the internal scheduling, and its design determines the drive's performance, its endurance, and its reliability. The different drives' controllers (the different vendors' designs, the different firmware's versions) have the different characteristics, and the drive's selection should account for the controller's quality (the benchmarks' results, the reviews, the field's reports).

"The open-channel SSDs and the ZNS are the future."

The open-channel SSDs and the ZNS are emerging standards, and their adoption is growing, but they are not yet the mainstream: the traditional drives (the SATA SSDs and the NVMe SSDs with the host-transparent FTL) remain the most common, and their ecosystem (the operating systems, the file systems, the applications) is the most mature. The open-channel SSDs and the ZNS are the data centers' and the specialized systems' technologies, and their adoption will depend on the software's ecosystem's growth.

05 Worked example

The following example traces a write through the FTL, computes the write amplification for different workloads, estimates the drive's lifetime, and shows the parallelism's effect on the throughput.

Tracing a write through the FTL

Consider a 1 TB TLC SSD with 4 KB pages and 1 MB erase blocks (256 pages per block). The drive's over-provisioning is 7%, so its usable capacity is 1 TB and its raw capacity is about 1.07 TB. The drive's FTL uses the page-level mapping with the demand-based caching.

The host writes 4 KB to the logical block 100 (the LBA 100). The write passes through the following steps:

  1. The host issues the write. The host's file system issues a write of the 4 KB to the LBA 100. The write is submitted to the drive's queue (the NVMe's submission queue, the SATA's command slot).
  2. The drive's controller receives the write. The drive's controller (the SSD's internal processor) reads the command from the queue and identifies the target LBA.
  3. The FTL translates the LBA. The FTL looks up the LBA 100 in its mapping table. Suppose the LBA 100's current mapping is the physical page 4523 (the die 1, the plane 0, the block 7, the page 42).
  4. The FTL allocates a new physical page. The FTL selects a free physical page for the new data — suppose the page 6100 (the die 2, the plane 1, the block 9, the page 100). The selection accounts for the wear leveling (the block 9's erase count is low) and the channel's load (the die 2 is not busy).
  5. The FTL writes the data. The controller issues the program operation to the die 2's block 9's page 100. The operation's latency is hundreds of microseconds (the TLC's program's latency).
  6. The FTL updates the mapping. After the write completes, the FTL updates its mapping table: the LBA 100 now points to the page 6100. The old page 4523 is marked as invalid in the block's metadata (the block 7's page 42 is now the stale data).
  7. The write completes. The controller reports the write's completion to the host (the completion queue, the interrupt). The host's file system considers the write complete.

The write's logical size is 4 KB, but the drive's physical work is the 4 KB program operation plus the metadata's update (the mapping table's entry). The write's immediate amplification is about 1 (the data) plus the metadata's small overhead. The eventual amplification comes from the garbage collection: when the block 7's invalid pages accumulate, the GC will copy its valid pages (including the page 42's neighbours), so the total physical writes will exceed the logical writes.

Computing the write amplification

The write amplification's value depends on the workload and the drive's state. The following table shows the typical WAFs for the different workloads:

Workload Typical WAF Notes
Sequential write 1.0–1.1 The writes fill the blocks; the GC has few valid pages to copy
Large random write (≥ block size) 1.1–1.5 The writes span the whole blocks; the GC's copies are few
Small random write (4 KB) 2–4 The writes scatter the updates; the GC copies many valid pages
Small random write, high utilization (≥ 90%) 4–10 The free blocks are scarce; the GC runs often and copies a lot
Small random write, no TRIM 3–6 The stale pages are copied as if valid; the WAF is higher

The table's pattern shows the WAF's sensitivity to the workload. The sequential writes' WAF is close to 1, so the drive's effective throughput is close to its raw bandwidth. The small random writes' WAF is 2 to 4, so the drive's effective throughput is a quarter to a half of its raw bandwidth, and the drive's endurance is consumed two to four times faster than the logical writes would suggest.

The WAF's effect on the throughput is the reason the modern file systems write sequentially: a database's transaction log's sequential writes achieve the drive's full bandwidth, while the database's data pages' random writes achieve a fraction of it. The observation is the reason the databases' designs (the WAL, the log-structured merges) and the file systems' designs (the journaling, the copy-on-write) are shaped by the SSD's workload's sensitivity.

Estimating the drive's lifetime

Suppose the drive is a 1 TB TLC SSD with a 1,000 P/E cycle rating and a 7% over-provisioning. The drive's raw capacity is about 1.07 TB, and its cells can be written about 1,000 times, so the drive's total physical writes' capacity is:

Total physical writes = 1.07 TB × 1,000
                      ≈ 1,070 TB
                      ≈ 1.07 PB

The drive's endurance, expressed in the logical writes, depends on the WAF. With the WAF of 1.5 (a mixed workload), the drive's logical writes' capacity is:

Total logical writes = 1,070 TB ÷ 1.5
                     ≈ 713 TB

With the WAF of 4 (a small random write's workload), the drive's logical writes' capacity is:

Total logical writes = 1,070 TB ÷ 4
                     ≈ 268 TB

The difference is a factor of 2.7, and it is the reason the workload's access pattern matters for the drive's lifetime. The drive writes per day (DWPD) is the endurance's normalized measure: a drive with the 713 TB's endurance and the 5-year warranty has the DWPD of:

DWPD = 713 TB ÷ (1 TB × 365 days × 5 years)
     ≈ 0.39

The drive's DWPD of 0.39 means the warranty covers the writes of about 0.39 times the drive's capacity per day. A workload that writes more than that (a database, a build farm) would consume the drive's endurance before the warranty's end, and the administrator should either use the higher-endurance drives (the MLC or the SLC enterprise drives) or reduce the workload's WAF (the sequential writes, the TRIM, the over-provisioning).

The parallelism's effect on the throughput

Suppose the drive has 8 channels, 4 dies per channel (32 dies total), and 2 planes per die (64 planes total). Each plane can process one operation at a time, and the operation's latency is 100 µs (the read) or 500 µs (the write).

With a single request, the drive's throughput is limited by the one plane's operation's latency:

Single request (4 KB read):
  Throughput = 4 KB ÷ 100 µs = 40 MB/s

Single request (4 KB write):
  Throughput = 4 KB ÷ 500 µs = 8 MB/s

With many concurrent requests, the drive's throughput is limited by the planes' aggregate:

64 concurrent requests (4 KB reads):
  Throughput = 64 × 4 KB ÷ 100 µs = 2,560 MB/s

64 concurrent requests (4 KB writes):
  Throughput = 64 × 4 KB ÷ 500 µs = 512 MB/s

The parallelism's effect is dramatic: the drive's read throughput is 64 times the single request's, and its write throughput is 64 times the single request's. The observation is the reason the NVMe protocol's queue-based interface is the modern drives' standard: the host must submit the many concurrent requests to exploit the parallelism, and the interface's queue's depth determines the drive's throughput's ceiling.

The real drives' throughput is lower than the ideal calculation, because the controller's scheduling, the channels' contention, and the write amplification reduce the effective parallelism. But the pattern is what matters: the SSD's throughput is a function of the queue's depth, and the modern systems' designs (the asynchronous I/O, the deep queues, the multi-queue block layer) are shaped by it.

Observing the SSD on a live system

The Linux tools let an administrator inspect the SSD's characteristics, its health, and its performance.

# Identify the SSD and its interface
lsblk -d -o NAME,SIZE,ROTA,TRAN,MODEL
# ROTA=0 means non-rotational (an SSD).

# Show the drive's SMART health and its wear
sudo smartctl -a /dev/nvme0n1 2>/dev/null | head -60
sudo smartctl -a /dev/sda 2>/dev/null | grep -iE 'wear|erase|written|reallocat'

# The output's key attributes:
#   Wear_Leveling_Count — the drive's wear
#   Media_Wearout_Indicator — the remaining life's percentage
#   Total_LBAs_Written — the total logical writes
#   Reallocated_Sector_Ct — the reallocated sectors

# Show the drive's queue parameters
cat /sys/block/nvme0n1/queue/nr_requests
cat /sys/block/nvme0n1/queue/scheduler
cat /sys/block/nvme0n1/queue/rotational

# Issue a TRIM for the free blocks
sudo fstrim -v /
sudo fstrim -v /home

# The output shows the number of bytes that were trimmed.

# Measure the drive's performance with fio
sudo fio --name=seqread --filename=/tmp/fio-test.bin \
    --size=1G --rw=read --bs=1M --direct=1 --runtime=10 \
    2>/dev/null | grep -E 'bw|IOPS'

sudo fio --name=randread --filename=/tmp/fio-test.bin \
    --size=1G --rw=randread --bs=4k --iodepth=64 \
    --ioengine=libaio --direct=1 --runtime=10 \
    2>/dev/null | grep -E 'bw|IOPS'

The commands' outputs show the drive's characteristics, its health, and its performance. The lsblk's ROTA column shows whether the device is rotational (a hard disk) or non-rotational (an SSD). The smartctl's output shows the drive's SMART attributes, including the wear leveling's and the total writes' indicators. The fstrim's output shows the TRIM's effect. The fio's output shows the drive's sequential and random performance, and the comparison with the drive's specifications reveals whether the drive is performing as expected.

06 Interactive activity

Activity · explore SSD architecture on a live system

The goal of this activity is to use the Linux command line to inspect the system's SSDs, to measure their performance, to issue the TRIM, and to observe the workload's effect on the drive's health. Work through the steps in your course VM.

  1. Identify the SSDs and their interfaces. Use lsblk and lspci to list the storage devices and their interfaces.
    # List the block devices and their types
    lsblk -d -o NAME,SIZE,ROTA,TRAN,MODEL
    
    # The ROTA column: 1 = rotational (a hard disk),
    # 0 = non-rotational (an SSD). The TRAN column shows
    # the transport (sata, nvme, usb, etc.).
    
    # Show the storage controllers
    lspci | grep -iE 'sata|nvme|raid|scsi'
    
    # Show the NVMe devices
    sudo nvme list 2>/dev/null
    Which devices are SSDs, and which are hard disks? What interfaces do they use (SATA, NVMe)? What models are they? Write down what you find.
  2. Examine the drive's SMART health. Use smartctl to inspect the drive's health and its wear.
    # For an NVMe drive
    sudo smartctl -a /dev/nvme0n1 2>/dev/null | head -60
    
    # For a SATA drive
    sudo smartctl -a /dev/sda 2>/dev/null | grep -iE 'wear|erase|written|reallocat|program|health'
    
    # The key attributes:
    #   Media_Wearout_Indicator / Wear_Leveling_Count
    #   Total_LBAs_Written
    #   Reallocated_Sector_Ct
    #   Program_Fail_Count / Erase_Fail_Count
    What is the drive's wear's percentage? How much data has it written? Are there any reallocated sectors or program/erase failures? What does the SMART's overall health say? Write down what you find.
  3. Examine the drive's queue's parameters. Use the sysfs interfaces to inspect the drive's queue's configuration.
    # Show the drive's queue parameters
    for dev in nvme0n1 sda; do
        if [ -e /sys/block/$dev/queue/nr_requests ]; then
            echo "=== /dev/$dev ==="
            cat /sys/block/$dev/queue/nr_requests
            cat /sys/block/$dev/queue/scheduler
            cat /sys/block/$dev/queue/rotational
            cat /sys/block/$dev/queue/max_sectors_kb
            cat /sys/block/$dev/queue/nomerges
        fi
    done
    What is the queue's depth? What scheduler does the drive use? What is the maximum transfer size? How do the parameters differ between the NVMe and the SATA drives? Explain the difference in terms of the interfaces' designs.
  4. Measure the drive's performance. Use fio to measure the drive's sequential and random performance.
    # Check whether fio is available
    which fio
    
    # Create a test file
    dd if=/dev/zero of=/tmp/fio-test.bin bs=1M count=1000 2>/dev/null
    sync
    
    # Sequential read
    sudo fio --name=seqread --filename=/tmp/fio-test.bin \
        --size=1G --rw=read --bs=1M --direct=1 --runtime=10 \
        2>/dev/null | grep -E 'bw|IOPS'
    
    # Sequential write
    sudo fio --name=seqwrite --filename=/tmp/fio-test.bin \
        --size=1G --rw=write --bs=1M --direct=1 --runtime=10 \
        2>/dev/null | grep -E 'bw|IOPS'
    
    # Random read (with a deep queue)
    sudo fio --name=randread --filename=/tmp/fio-test.bin \
        --size=1G --rw=randread --bs=4k --iodepth=64 \
        --ioengine=libaio --direct=1 --runtime=10 \
        2>/dev/null | grep -E 'bw|IOPS'
    
    # Random write (with a deep queue)
    sudo fio --name=randwrite --filename=/tmp/fio-test.bin \
        --size=1G --rw=randwrite --bs=4k --iodepth=64 \
        --ioengine=libaio --direct=1 --runtime=10 \
        2>/dev/null | grep -E 'bw|IOPS'
    
    # Clean up
    rm /tmp/fio-test.bin
    What is the drive's sequential throughput? What is its random IOPS? How do the results compare to the drive's specifications? Are the reads faster than the writes? Explain the differences in terms of the flash memory's characteristics.
  5. Measure the queue depth's effect. Use fio to measure the drive's throughput at different queue depths.
    # Measure the random read's throughput at
    # different queue depths
    for qd in 1 2 4 8 16 32 64 128; do
        echo -n "qd=$qd: "
        sudo fio --name=randread --filename=/tmp/fio-qd.bin \
            --size=500M --rw=randread --bs=4k --iodepth=$qd \
            --ioengine=libaio --direct=1 --runtime=5 --time_based \
            2>/dev/null | grep -E 'IOPS' | head -1
    done
    
    # Clean up
    rm /tmp/fio-qd.bin 2>/dev/null
    How does the throughput change with the queue depth? At which depth does it saturate? What does the saturation point tell you about the drive's internal parallelism? How does the result compare to the lesson's analysis?
  6. Issue the TRIM and observe its effect. Use fstrim and blkdiscard to issue the TRIM, and observe the drive's behaviour.
    # Show the file system's discard support
    mount | grep discard
    cat /sys/block/nvme0n1/queue/discard_max_bytes
    cat /sys/block/nvme0n1/queue/discard_granularity
    
    # Issue a TRIM for the root file system's free blocks
    sudo fstrim -v /
    
    # The output shows the number of bytes that were trimmed.
    
    # Create a large file, delete it, and issue the TRIM again
    dd if=/dev/zero of=/tmp/trim-test.bin bs=1M count=500 2>/dev/null
    rm /tmp/trim-test.bin
    sync
    sudo fstrim -v /tmp
    
    # The output shows the TRIM's effect.
    
    # Use blkdiscard for a raw device (careful — this
    # destroys the data!)
    # sudo blkdiscard -n /dev/nvme0n1p3
    What is the drive's discard granularity? What does the fstrim's output show? What does the TRIM's effect tell you about the FTL's behaviour? What would happen if the TRIM were not issued?
  7. Compare the workloads' write amplification. Use the drive's SMART attributes to compare the write amplification of the sequential and the random workloads.
    # Record the Total_LBAs_Written before the workloads
    sudo smartctl -A /dev/nvme0n1 2>/dev/null | grep -iE 'written|wear'
    
    # Run a sequential write workload
    dd if=/dev/zero of=/tmp/seq-test.bin bs=1M count=2000 2>/dev/null
    sync
    
    # Record the Total_LBAs_Written after the workload
    sudo smartctl -A /dev/nvme0n1 2>/dev/null | grep -iE 'written|wear'
    
    # Compare the two outputs and compute the write
    # amplification (the physical writes divided by the
    # logical writes).
    
    # Repeat with a random write workload
    # (use fio with --rw=randwrite --bs=4k)
    What is the drive's write amplification for the sequential workload? For the random workload? Does the difference match the lesson's analysis? How does the write amplification affect the drive's endurance?
  8. Read the man pages. Read the man pages that document the SSD-related interfaces.
    man 8 smartctl
    man 8 nvme
    man 8 blkdiscard
    man 8 fstrim
    man 1 fio
    man 1 lsblk
    man 8 hdparm
    For each, write a sentence describing its main contribution to your understanding of the SSD. The man 8 smartctl page documents the SMART interface; the man 8 blkdiscard page documents the TRIM's raw interface; the man 1 fio page documents the I/O performance's benchmarking tool.

Reflect: the SSD is the storage stack's most consequential modern development, and its architecture is a study in the interplay between the physics, the controller, and the host. The flash memory's erase-before-write constraint created the FTL, the GC, and the write amplification; the cells' endurance created the wear leveling; the drive's internal parallelism created the need for the deep queues and the NVMe interface. The modern stack's designs (the file systems' sequential writes, the schedulers' queue-depth's management, the RAID's preference for the mirroring, the TRIM's propagation) are all responses to the SSD's characteristics. Which of the SSD's mechanisms matter most for the systems you use? What would you change about the SSD's architecture if you could? How would you explain the erase-before-write's constraint to someone who has never thought about it? What is the right balance between the drive's internal management and the host's control (the open-channel SSDs and the ZNS)?

07 Knowledge check

Check your understanding

Question 1

Describe the flash memory's fundamentals: the floating-gate cell, the NAND and the NOR technologies, and the SLC, MLC, TLC, and QLC variants. What are the trade-offs among the variants?

Show answer
Flash memory is a kind of non-volatile semiconductor memory. Its storage element is the floating-gate transistor: a transistor with an additional gate — the floating gate — that is insulated from the rest of the transistor. The floating gate can hold a charge, and the charge's presence or absence determines the transistor's threshold voltage, which the controller's read operation interprets as the cell's value. The write operation (the program) places the charge on the gate by applying a high voltage across the oxide layer; the erase removes the charge by applying the reverse voltage. The two operations stress the oxide, and the layer's degradation is the source of the cell's endurance limit. The flash memory has two main technologies. NOR flash provides the random access (any byte can be read individually), the fast reads, and the slow writes and erases; it is used for the code storage (the firmware, the boot loaders) because the code can be executed in place. Its capacity is small and its cost per bit is high. NAND flash provides the block access (the reads and writes are performed on the pages), the high density, and the low cost per bit; it is used for the bulk storage (the SSDs, the USB drives, the memory cards). Its disadvantages are the block access (the reads and writes must be page-aligned), the slower random access, and the write's and erase's asymmetry. The NAND flash is the modern SSDs' technology. The cell's variants determine the number of the bits per cell. The SLC (Single-Level Cell) stores one bit per cell (the two levels), and its endurance (~100,000 P/E cycles) and its performance are the highest. The MLC (Multi-Level Cell) stores two bits per cell (the four levels), with the endurance of ~3,000–10,000 cycles and the fast performance. The TLC (Triple-Level Cell) stores three bits per cell (the eight levels), with the endurance of ~1,000–3,000 cycles and the moderate performance. The QLC (Quad-Level Cell) stores four bits per cell (the sixteen levels), with the endurance of ~100–1,000 cycles and the slowest performance. The trade-off is between the density and the performance and the endurance: the higher densities store more data per cell (so the cost per bit is lower), but the levels are the closer together, so the controller's read must distinguish them more precisely and the cell's endurance and performance are the lower. The consumer drives use the TLC and the QLC; the enterprise drives use the MLC and the TLC (and the SLC and the MLC for the write-intensive workloads).

Question 2

Describe the flash memory's organization (the cells, the pages, the erase blocks, the planes, the dies, and the channels) and the read, write, and erase operations' asymmetries. Why do the asymmetries matter?

Show answer
The flash memory is organized as a hierarchy of the units. A cell is the storage element (the floating-gate transistor that holds one or more bits). A page is the read and write unit: a group of the cells (typically 4 KB to 16 KB) that is read or written together. An erase block is the erase unit: a group of the pages (typically 128 to 1,024 pages, or 256 KB to several MB) that is erased together. A plane is a group of the erase blocks (typically 1,024 to 4,096) that shares the chip's row and column decoders; a chip has two or four planes, and the planes can be accessed in parallel. A die is a single silicon chip; a package can contain several dies. A channel is the bus between the drive's controller and the dies; a drive has several channels, and the dies on different channels can be accessed in parallel. The three operations have different characteristics. The read operation's granularity is the page, and its latency is tens of microseconds; its endurance is effectively unlimited (though the read disturb requires the periodic refresh). The write (the program) operation's granularity is the page, and its latency is hundreds of microseconds; its endurance is limited (each write stresses the oxide). The erase operation's granularity is the erase block, and its latency is milliseconds; its endurance is the lowest. The asymmetries matter because they determine the SSD's behaviour. The read's page granularity and its short latency are why the drive's reads are fast. The write's page granularity and its longer latency are why the drive's writes are slower than its reads. The erase's block granularity and its long latency are why the drive cannot update a page in place: the controller must write the new data to a fresh page and invalidate the old one, and the erase block's reclamation requires the garbage collection's read-modify-erase-write cycle. The cycle is the source of the write amplification, and it is the reason the modern file systems and the applications write sequentially and issue the TRIM.

Question 3

Describe the flash translation layer and its address mapping (the page-level, the block-level, and the hybrid). What is the garbage collection, and what is the write amplification?

Show answer
The flash translation layer (FTL) is the drive's controller's firmware that hides the flash memory's constraints behind the block device's interface. Its principal function is the address translation: it maps the host's logical block addresses (LBAs) to the flash's physical page numbers (PPNs), and it updates the mapping on every write. The FTL's translation is the source of the drive's out-of-place update behaviour: when the host overwrites a logical block, the FTL writes the new data to a fresh physical page, updates the mapping to point to the new page, and marks the old page as invalid. The FTL's mapping has three principal designs. The page-level mapping maintains a mapping entry for every logical page, so the translation is direct and the write's placement is unconstrained; its disadvantage is the mapping table's size (the 1 GB for a 1 TB drive with 4 KB pages). The block-level mapping maps the logical blocks to the physical blocks, and the pages' offsets within the blocks are preserved; the mapping table is much smaller, but the write's placement is constrained (the read-modify-erase-write cycle on every small write), so the write amplification is high. The hybrid mapping combines the two: a small portion of the drive (the log blocks) uses the page-level mapping, and the rest (the data blocks) uses the block-level mapping; the write's hot spots are served by the log blocks, and the cold data is stored in the data blocks. The modern drives use a variant of the page-level mapping with the demand-based caching (the DFTL): the full mapping table is stored in the flash, and only the working set is cached in the drive's RAM. The garbage collection (GC) is the FTL's process of reclaiming the invalid pages' space. The GC selects a victim erase block (typically the block with the fewest valid pages), reads the block's valid pages, writes them to a new block, erases the victim, and updates the mapping to point to the valid pages' new locations. The GC's work is the source of the write amplification: the write amplification factor (WAF) is the ratio of the physical writes to the logical writes. The WAF depends on the workload's access pattern: the sequential writes' WAF is close to 1, and the small random writes' WAF is 2 to 4 (or higher for the high-utilization workloads). The WAF is the SSD's central performance and lifetime metric: a higher WAF means a lower effective throughput and a shorter lifetime.

Question 4

Describe the wear leveling (the dynamic and the static), the TRIM command, and the drive's internal parallelism. Why is each important?

Show answer
The wear leveling is the FTL's process of spreading the writes across the flash cells, so that no cell is worn out before the others. Without it, a workload that repeatedly writes the same logical blocks would wear out the corresponding physical cells, and the drive would fail long before its total capacity's endurance was consumed. The wear leveling has two forms. The dynamic wear leveling chooses the free blocks for the new writes in a way that spreads the writes across the blocks' erase counts (it prefers the blocks with the lowest counts), so the active data's wear is spread. But the dynamic wear leveling does not handle the cold data (the data that is written rarely and never moved): the cold data's blocks stay low, and the active data's blocks wear out while the cold data's blocks are underused. The static wear leveling periodically moves the cold data to the blocks with the higher erase counts, so the cold data's blocks' counts increase and the wear is spread more evenly; its cost is the extra copies, and its benefit is the longer lifetime for the workloads with the mixed hot and cold data. The TRIM (the discard) is the command by which the host informs the drive which logical blocks are no longer in use. The command's purpose is to reduce the write amplification: without it, the FTL cannot distinguish the valid data from the stale data (the file system deleted the file, but the drive does not know), so the GC copies the stale pages as if they were valid. With the TRIM, the FTL can invalidate the corresponding physical pages immediately, so the GC's valid pages' count is smaller and the copies are fewer. The TRIM is important because it reduces the WAF, which improves the drive's performance and its lifetime. The internal parallelism is the source of the SSD's high throughput. A drive contains many flash chips, and the controller can access several of them in parallel: the channel-level parallelism (the dies on different channels), the die-level parallelism (the dies on the same channel), the plane-level parallelism (the planes within a die), and the cell-level parallelism (the pages' offsets). The parallelism's effect is the reason the drive's throughput depends on the queue depth: a single request can use only one channel (or one die, or one plane), so its throughput is limited; several concurrent requests can use the different channels, so the drive's aggregate throughput is the sum. The parallelism is important because it explains the modern stack's design: the NVMe protocol's queue-based interface (the thousands of the queues) is designed to exploit the parallelism, and the modern applications use the asynchronous I/O and the deep queues to keep the drive's parallelism fully used.

Question 5

Describe the SSD's performance and reliability characteristics. What are the key metrics, and how do they differ from a hard disk's? What are the modern developments (the open-channel SSDs, the ZNS, and the host-managed flash)?

Show answer
The SSD's performance is characterized by four metrics. The sequential throughput is the drive's bandwidth for the large, sequential reads and writes: the SATA SSDs' is about 500–550 MB/s, and the NVMe SSDs' is 2,000–7,000 MB/s. The random IOPS is the drive's operations per second for the small, random requests: the SATA SSDs' is about 50,000–100,000, and the NVMe SSDs' is 500,000–1,500,000. The latency is the time an individual request takes: the SSDs' average is tens of microseconds, and the tail latency (the 99th and the 99.9th percentiles) is much higher. The queue depth's scaling is the drive's throughput as a function of the number of the concurrent requests: the throughput increases with the queue's depth until it saturates at the drive's maximum. The characteristics differ from a hard disk's in three ways. The SSD's access time is nearly uniform (the difference between the sequential and the random access is small), so the seek-reduction's scheduling is less important. The SSD's throughput depends on the queue's depth (the internal parallelism), so the modern interfaces (the NVMe's thousands of the queues) are designed for the deep queues. The SSD's latency is much lower than the hard disk's, but its tail latency is a concern (the GC's and the write amplification's effects). The SSD's reliability is characterized by the endurance (the drive's total data that can be written, expressed as the terabytes written or the drive writes per day), the failure modes (the SSDs tend to fail suddenly, and they have the specific failure modes of the read disturb and the retention), and the SMART attributes (the Wear_Leveling_Count, the Media_Wearout_Indicator, the Total_LBAs_Written, the Reallocated_Sector_Ct, and the Program_Fail_Count and the Erase_Fail_Count). The modern developments move the flash management from the drive's controller to the host. The open-channel SSDs expose the flash memory's physical interface to the host, so the host's software performs the address translation, the garbage collection, and the wear leveling; the host can optimize the flash's management for its workload, but the host's complexity is increased. The Zoned Namespaces (ZNS) is the NVMe's standard for the zoned storage: the drive's logical address space is divided into the zones, and each zone must be written sequentially; the ZNS's advantage is the alignment with the flash memory's characteristics (the sequential writes reduce the WAF), and the drive still manages the FTL. The computational storage performs the computation within the storage device (the filtering, the compression, the encryption, the search), so the host's processor is offloaded and the data's movement is reduced.

08 Unit discussion

Discussion prompt

The solid-state drive is the storage stack's most consequential modern development, and its history is a history of the storage stack's adaptation. The hard disk's characteristics — the rotating platters, the moving heads, the seek and the rotational delay — shaped the storage stack's design for decades. The file systems' allocation policies placed the data contiguously to minimize the head's movement; the disk schedulers reordered the requests to sort them by the block address; the RAID's parity's designs assumed that the writes were expensive and the capacity was precious. The SSD's characteristics are fundamentally different: the access time is nearly uniform, the write is expensive (the erase-before-write, the write amplification), and the endurance is limited. The storage stack's designs have changed accordingly: the file systems write sequentially to reduce the write amplification; the schedulers keep the queue's depth high to exploit the parallelism; the RAID's designs prefer the mirroring over the parity to reduce the write's cost; and the TRIM's propagation keeps the FTL informed.

The trend is toward the host-managed flash. The classical SSD hides the flash memory's details behind the block device's interface: the drive's controller performs the FTL's translation, the GC, the wear leveling, and the internal scheduling, and the host sees only the logical blocks. The host-managed flash (the open-channel SSDs, the ZNS, the host's software) moves the flash management to the host: the host sees the flash's physical units (the channels, the dies, the blocks, the pages) or the zones, and it performs the FTL's work (or the host and the drive share the work). The trend's rationale is the semantic gap between the host's knowledge and the drive's: the host knows which data is hot and which is cold, which blocks are free and which are in use, and which writes are sequential and which are random, while the drive's controller must infer the same information from the block-level requests. The host-managed flash lets the host use its knowledge to optimize the flash's management, so the write amplification is reduced, the drive's lifetime is extended, and the performance is improved.

The trend also raises a question about the abstraction's future. The block device's interface — the numbered blocks, the reads and the writes, the sector's abstraction — has been the storage stack's foundation for decades, and it has served the storage well: the file systems, the volume managers, the RAID, and the backup tools all assume the block device's abstraction, and the abstraction's simplicity is the reason the storage stack's layers are interchangeable. The host-managed flash's interfaces (the physical pages, the zones) break the abstraction, and the storage stack's layers must be rewritten to use them. The trade-off is between the abstraction's simplicity and the flash's efficiency: the abstraction hides the flash's details, but it also hides the information that the host could use to optimize the flash's management.

Where should the boundary between the host and the drive be? Should the drive's controller manage the flash transparently, or should the host's software manage it (the open-channel SSDs, the ZNS)? Should the block device's abstraction be preserved, or should the storage stack move to the flash-specific interfaces? What is the right balance between the abstraction's simplicity and the flash's efficiency? Post your response to the Unit 11 discussion forum and reply to at least two classmates. Supports CLO1, CLO5, CLO6, and CLO7.

09 Practice exercise

This ungraded exercise consolidates the lesson and completes Unit 11. Aim to spend 90–120 minutes on it.

  1. Trace a write through the FTL. A host writes 4 KB to the LBA 2000 on a TLC SSD with 4 KB pages and 1 MB erase blocks. The FTL's current mapping for the LBA 2000 is the physical page 8000 (the die 0, the plane 1, the block 5, the page 100). Trace the write's steps:
    • The command's reception.
    • The FTL's translation.
    • The new page's allocation (accounting for the wear leveling).
    • The program operation.
    • The mapping's update.
    • The completion's report.
    What is the write's immediate amplification? What is the eventual amplification (when the GC runs)? Explain the difference.
  2. Compute the write amplification and the lifetime. A 2 TB TLC SSD has a 1,500 P/E cycle rating and a 7% over-provisioning. Compute:
    • The raw capacity.
    • The total physical writes' capacity.
    • The total logical writes' capacity for the WAF of 1.2 (sequential), 2.5 (mixed), and 5 (random).
    • The DWPD for each WAF (assume a 5-year warranty).
    Which workload would exhaust the drive's endurance first? What could the administrator do to extend the drive's lifetime?
  3. Measure the SSD's performance. Use fio to measure the drive's sequential and random performance, and compare the results to the drive's specifications.
    # Sequential read
    sudo fio --name=seqread --filename=/tmp/fio.bin \
        --size=2G --rw=read --bs=1M --direct=1 --runtime=10 \
        2>/dev/null | grep -E 'bw|IOPS'
    
    # Sequential write
    sudo fio --name=seqwrite --filename=/tmp/fio.bin \
        --size=2G --rw=write --bs=1M --direct=1 --runtime=10 \
        2>/dev/null | grep -E 'bw|IOPS'
    
    # Random read (the queue depth = 64)
    sudo fio --name=randread --filename=/tmp/fio.bin \
        --size=2G --rw=randread --bs=4k --iodepth=64 \
        --ioengine=libaio --direct=1 --runtime=10 \
        2>/dev/null | grep -E 'bw|IOPS'
    
    # Random write (the queue depth = 64)
    sudo fio --name=randwrite --filename=/tmp/fio.bin \
        --size=2G --rw=randwrite --bs=4k --iodepth=64 \
        --ioengine=libaio --direct=1 --runtime=10 \
        2>/dev/null | grep -E 'bw|IOPS'
    
    # Clean up
    rm /tmp/fio.bin
    How do the results compare to the drive's specifications? Are the reads faster than the writes? Does the random read's throughput improve with the deeper queue? Explain the results in terms of the lesson's concepts.
  4. Measure the queue depth's effect. Use fio to measure the drive's random read's throughput at the different queue depths, and plot the results.
    # Measure at the increasing queue depths
    for qd in 1 2 4 8 16 32 64 128 256; do
        echo -n "qd=$qd: "
        sudo fio --name=randread --filename=/tmp/fio-qd.bin \
            --size=1G --rw=randread --bs=4k --iodepth=$qd \
            --ioengine=libaio --direct=1 --runtime=5 --time_based \
            2>/dev/null | grep -oE 'IOPS=[0-9.]+k?' | head -1
    done
    
    # Clean up
    rm /tmp/fio-qd.bin 2>/dev/null
    How does the throughput change with the queue's depth? At which depth does it saturate? What does the saturation point tell you about the drive's internal parallelism? How does the result compare to the lesson's analysis?
  5. Investigate the TRIM's effect. Use fstrim and the drive's SMART attributes to investigate the TRIM's effect on the write amplification.
    # Record the Total_LBAs_Written before the workload
    sudo smartctl -A /dev/nvme0n1 2>/dev/null | grep -i written
    
    # Write a large file
    dd if=/dev/zero of=/tmp/trim-test.bin bs=1M count=2000 2>/dev/null
    sync
    
    # Record the Total_LBAs_Written after the write
    sudo smartctl -A /dev/nvme0n1 2>/dev/null | grep -i written
    
    # Delete the file and issue the TRIM
    rm /tmp/trim-test.bin
    sync
    sudo fstrim -v /tmp
    
    # Record the Total_LBAs_Written after the TRIM
    sudo smartctl -A /dev/nvme0n1 2>/dev/null | grep -i written
    
    # Compute the write amplification (the physical writes
    # divided by the logical writes).
    What is the write's amplification? What is the TRIM's effect? Does the TRIM's issuance change the Total_LBAs_Written's reading? Explain the results in terms of the FTL's behaviour.
  6. Investigate the workload's effect on the write amplification. Compare the write amplification of a sequential workload and a random workload.
    # Record the Total_LBAs_Written before the workloads
    sudo smartctl -A /dev/nvme0n1 2>/dev/null | grep -i written
    
    # Sequential write
    sudo fio --name=seqwrite --filename=/tmp/seq.bin \
        --size=2G --rw=write --bs=1M --direct=1 --runtime=10 \
        2>/dev/null | grep -E 'bw'
    
    # Record the Total_LBAs_Written
    sudo smartctl -A /dev/nvme0n1 2>/dev/null | grep -i written
    
    # Random write
    sudo fio --name=randwrite --filename=/tmp/rand.bin \
        --size=2G --rw=randwrite --bs=4k --iodepth=64 \
        --ioengine=libaio --direct=1 --runtime=10 \
        2>/dev/null | grep -E 'bw'
    
    # Record the Total_LBAs_Written
    sudo smartctl -A /dev/nvme0n1 2>/dev/null | grep -i written
    
    # Clean up
    rm /tmp/seq.bin /tmp/rand.bin
    What is the sequential workload's write amplification? What is the random workload's? Does the difference match the lesson's analysis? Explain the difference in terms of the GC's behaviour.
  7. Design an SSD-based storage configuration. A company is building a database server for its transaction-processing workload. The database performs many small random reads (4 KB each) and many small writes (the transaction log's sequential writes and the data pages' random writes). The server must provide the low latency and the high throughput, and its storage must be reliable. The server has the budget for the enterprise NVMe SSDs (the 3 DWPD rating). Design the storage configuration. Consider:
    • How many SSDs would you use, and what capacity?
    • What RAID level would you use (the RAID 1, the RAID 10, the RAID 5, or the RAID 6), and why?
    • How would you configure the file system's and the database's I/O (the block size, the alignment, the TRIM, the sequential writes)?
    • How would you monitor the drives' health and their endurance?
    • How would you handle the drives' wear-out and their replacement?
    Justify your design.
  8. Reflect on Unit 11. In your own words, summarize the arc of Unit 11: how the I/O hardware, the interrupts, the DMA, the device drivers, the disk scheduling, the RAID, and the SSD architecture fit together, and how the SSD's characteristics have reshaped the storage stack. Then identify one concept from the unit that changed your understanding of the storage systems, and explain why. Finally, identify one question about the storage systems that the unit did not answer, and explain what you would need to learn to answer it.

10 Summary

  • Flash memory is a kind of non-volatile semiconductor memory. Its storage element is the floating-gate transistor, and its value is determined by the charge on the gate. The two main technologies are the NOR flash (the random access, the fast reads, the code storage) and the NAND flash (the block access, the high density, the bulk storage). The cell's variants — the SLC, the MLC, the TLC, and the QLC — store one, two, three, or four bits per cell, and the trade-offs among them are the density, the performance, and the endurance.
  • The flash memory is organized as a hierarchy: the cells, the pages (the read and write unit), the erase blocks (the erase unit), the planes, the dies, and the channels. The read's and the write's granularity is the page, and the erase's granularity is the erase block, which is 128 to 1,024 times larger. The asymmetry is the source of the erase-before-write's constraint and the flash translation layer.
  • The flash translation layer (FTL) maps the host's logical block addresses to the flash's physical page numbers, and it performs the out-of-place updates: a write allocates a new physical page and invalidates the old one. The FTL's mapping designs are the page-level (the flexible, the large table), the block-level (the compact, the high write amplification), and the hybrid (the balance). The modern drives use the page-level mapping with the demand-based caching.
  • The garbage collection (GC) reclaims the invalid pages' space by copying the victim block's valid pages to a new block, erasing the victim, and updating the mapping. The GC's work is the source of the write amplification (the ratio of the physical writes to the logical writes). The WAF is the SSD's central performance and lifetime metric, and it depends on the workload's access pattern (the sequential writes' WAF is close to 1; the small random writes' is 2 to 4 or higher).
  • The wear leveling spreads the writes across the cells. The dynamic wear leveling chooses the free blocks by their erase counts; the static wear leveling periodically moves the cold data to the blocks with the higher erase counts. The TRIM command informs the drive which logical blocks are free, so the FTL can invalidate the corresponding physical pages and the GC's copies are fewer. The internal parallelism (the channels, the dies, the planes) is the source of the SSD's high throughput, and it is the reason the drive's throughput depends on the queue's depth.
  • The SSD's host interfaces are the SATA/AHCI (the single queue with the 32 slots, the 600 MB/s bandwidth, the hard disk's legacy) and the NVMe (the thousands of the queue pairs, the PCIe's bandwidth, the flash's parallelism). The NVMe is the modern high-performance SSDs' standard, and it is the reason the NVMe SSDs achieve the millions of the IOPS with the low latency.
  • The SSD's performance is characterized by the sequential throughput, the random IOPS, the latency (the average and the tail), and the queue depth's scaling. The SSD's reliability is characterized by the endurance (the TBW and the DWPD), the failure modes (the sudden failures, the read disturb, the retention), and the SMART attributes (the Wear_Leveling_Count, the Media_Wearout_Indicator, the Total_LBAs_Written, the Reallocated_Sector_Ct, the Program_Fail_Count, and the Erase_Fail_Count).
  • The modern developments move the flash management from the drive's controller to the host: the open-channel SSDs (the host's software performs the FTL's work), the Zoned Namespaces (the zones with the sequential writes' requirement), and the computational storage (the drives that perform the computation). The developments are the recognition of the semantic gap between the host's knowledge and the drive's: the host knows the data's hotness and the free blocks' state, while the drive's controller must infer the same information from the block-level requests.
  • The SSD's characteristics have reshaped the storage stack's design: the file systems write sequentially (to reduce the WAF), the disk schedulers keep the queue's depth high (to exploit the parallelism), the RAID's designs prefer the mirroring over the parity (to reduce the write's cost), and the TRIM's propagation keeps the FTL informed. The storage stack's designs are the response to the SSD's characteristics, and they are the reason the modern systems' performance is so much higher than the hard-disk-based systems'.

Unit 11 complete — the storage stack's synthesis

This lesson completes Unit 11. The unit has presented the storage stack from the hardware up: the I/O subsystem's layers, the devices and the controllers, the interrupts and the DMA, the device drivers and the block layer, the disk scheduling algorithms, the RAID arrays, and the solid-state drive's architecture. The unit's arc is the storage stack's hierarchy: each layer builds on the one below it, and each layer hides the lower layer's details behind a simpler interface. The application issues the reads and the writes; the file system (Unit 10) turns them into the block requests; the block layer and the I/O scheduler (Lessons 11.4 and 11.5) order and merge them; the device driver (Lesson 11.4) translates them into the device's commands; the DMA (Lesson 11.3) moves the data; the device's controller executes the operations; and the interrupt (Lesson 11.2) reports the completions. The RAID (Lesson 11.6) combines several devices for the performance and the reliability, and the SSD (this lesson) determines the devices' behaviour. The unit's synthesis is the modern storage stack's design: a hierarchy of the abstractions, each shaped by the characteristics of the layer below it, and each hiding those characteristics behind a simpler interface. The next unit continues the story: it presents the distributed systems and the cloud storage, where the storage stack's abstractions are extended across the network and the data center.

11 References

  • Silberschatz, A., Galvin, P. B., & Gagne, G. Operating System Concepts, 10th ed., Chapter 11, Sections 11.1 and 11.2.
  • Arpaci-Dusseau, R. H., & Arpaci-Dusseau, A. C. Operating Systems: Three Easy Pieces, Chapter 44, Flash-based SSDs. Available online at ostep.org.
  • Tanenbaum, A. S., & Bos, H. Modern Operating Systems, 4th ed., Chapter 5, Section 5.4.4.
  • Agrawal, N., Prabhakaran, V., Wobber, T., Davis, J. D., Manasse, M., & Panigrahy, R. Design Tradeoffs for SSD Performance. USENIX Annual Technical Conference, 2008.
  • Gupta, A., Kim, Y., & Urgaonkar, B. DFTL: A Flash Translation Layer Employing Demand-Based Selective Caching of Page-Level Address Mappings. EuroSys, 2009.
  • Lee, C., Sim, D., Hwang, J., & Cho, S. F2FS: A New File System for Flash Storage. USENIX FAST, 2015.
  • Bjørling, M., Gonzalez, J., & Bonnet, P. LightNVM: The Linux Open-Channel SSD Subsystem. USENIX FAST, 2017.
  • Bjørling, M. Zone Append: A New Way of Writing to Zoned Storage. USENIX FAST, 2020.
  • Linux man-pages: man 8 blkdiscard, man 8 fstrim, man 8 smartctl, man 8 nvme, man 1 fio, man 1 iostat, man 5 proc, man 4 sd, man 8 hdparm, man 1 lsblk, man 8 mkfs.f2fs.
👤