DRIVERBLOCK LAYERFILE SYSTEMPAGE CACHESSDBLOCKADDRCMD1fd = open("a.txt", O_RDONLY);2n = read(fd, buf, 4096);bufCPU3?82004 KiB4096
Back: the kernel's I/O stack (file system, block layer, driver), the page cache, the SSDFront: your program and buf, the CPU and the interrupt line, another programTokens: a request going down, data copied by DMA, an interrupt coming backBack left: the kernel's I/O stack, the file system on the block layer on the driver, with the page cache beside it. Back right: the SSD and its registers. Front: the program, its buf, the CPU with the SSD's interrupt line, and another program. read() goes down the stack floor by floor; the driver writes the registers; the program sleeps while the other one runs; the SSD copies the block into the page cache by DMA and interrupts; the bytes are copied into buf and read returns 4096. The SSD here has three simple registers, like the canonical device in OSTEP. A real NVMe SSD takes its commands from queues the driver builds in RAM, and one register write tells it new commands are waiting, but the idea is the same: the driver prepares the work, one write starts it, the device copies by DMA and interrupts when done.

The stack

  1. A program never talks to a disk. Its read() goes down a stack of kernel layers: the file system, the block layer, then the device driver. Each layer talks only to the one below it, and only the driver touches the device.

Going down

The device

Coming back

What happens

;; step 1/12 · stack
user      your program        read(fd, buf, 4096)
--------- system call -----------------------------
kernel    file system (VFS)   files and offsets
          block layer         block requests, queues
          device driver       this device's registers
--------- hardware --------------------------------
device    SSD controller      does the work, then interrupts

The SSD here has three simple registers, like the canonical device in OSTEP. A real NVMe SSD takes its commands from queues the driver builds in RAM, and one register write tells it new commands are waiting, but the idea is the same: the driver prepares the work, one write starts it, the device copies by DMA and interrupts when done. Block 8200 is an example: where a file's bytes live depends on the file system and the disk. 4096 bytes is one 4 KiB block and one memory page, 8 sectors of 512 bytes.