The simple version
Sending a letter goes through layers: you hand it to the front desk, the mailroom sorts it, a truck carries it, and a postman delivers it. Sometimes the front desk already has a copy of the letter you want and hands it straight back: that's the page cache.
That shortcut is wonderful for speed and terrible for honest benchmarks.
The layers
Buffered reads and writes
Reads: on a cache hit, data comes straight from RAM and the disk is never touched. On a miss, the kernel reads from the device, often with read-ahead, and keeps a copy.
Writes: buffered writes land in the page cache as dirty pages and return immediately. Background writeback flushes them later, controlled by vm.dirty_background_ratio and vm.dirty_ratio. Data isn't durable until it's flushed: that is what fsync() is for.
$ grep -E '^(Cached|Dirty|Writeback):' /proc/meminfo
$ sysctl vm.dirty_ratio vm.dirty_background_ratioDirect I/O
Opening a file with O_DIRECT (fio: --direct=1) bypasses the page cache. Buffers and offsets must be aligned to the logical block size. Databases and many storage benchmarks use it so they measure the device, not RAM.
--direct=1, use a file much larger than RAM, or drop caches between runs: sync; echo 3 | sudo tee /proc/sys/vm/drop_caches (test machines only).Watching the block layer
$ sudo blktrace -d /dev/nvme0n1 -o - | blkparse -i -
blktrace shows every request as it is queued (Q), dispatched to the driver (D) and completed (C). The time from D to C is device time; from Q to D is time spent waiting in the block layer.
Tools
/proc/meminfoCached, Dirty and Writeback show page-cache state.
blktrace + blkparsePer-request trace of the block layer.
iostat -xDevice-level view: compare it with what the app thinks it's getting.
vmtouch / fincoreShow how much of a file is in the page cache (fincore ships with util-linux).
Quiz
Lab
Lab 1.2 · The impossibly fast benchmark
A report claims a single local NVMe drive read /scratch/bench.bin (8 GiB) at 18 GB/s. The drive is a PCIe Gen4 x4 class device (about 7 GB/s at most).
Try it now in the simulator (opens with the command ready; press Enter):
$ fio --name=buf --filename=/scratch/test.bin --size=4G --rw=read --bs=1M --ioengine=libaio --iodepth=8$ fio --name=buf --filename=/scratch/test.bin --size=4G --rw=read --bs=1M --ioengine=libaio --iodepth=8$ cat /proc/meminfo | grep -E 'Cached|Dirty'$ sync; echo 3 > /proc/sys/vm/drop_caches