The cost of a read is the number of trips
A read costs what its trips cost: the number of separate places a read visits, not the bytes it moves.
A computer reads whole blocks of 4 KB or 8 KB, so a read's cost depends on how many separate blocks it visits, not how many bytes it moves. On a spinning disk, each new place means a seek of milliseconds, while bytes under the head come nearly free. Indexes, B-trees, write-ahead logs, and columnar storage work by cutting the number of trips or making them sequential.
A spinning disk fetches a row in two steps. The read head moves to the track that holds it, which is a seek and takes milliseconds. Then the platter rotates until the right sector passes underneath. Once the head is in place the bytes are nearly free, and the disk hands back a whole block whether you wanted one byte or all of it. Reading a 1 MB file costs one seek and a stream of bytes. Reading 1000 scattered one-byte values costs 1000 seeks: the same kilobyte, thousands of times slower. Every storage structure attacks that count. An index turns a full scan into a handful of page visits. A B-tree makes it one page per level, with large nodes so the tree stays shallow.
The abstraction hides both multiplicity and layers. Latencies stack: RAM takes around 100 nanoseconds, NVMe flash around 100 microseconds, a datacenter network round trip around 500 microseconds, and a spinning-disk seek around 5 milliseconds. RAM and NVMe are about a thousand times apart, and a seek is roughly fifty times slower than an NVMe read. Adding an index can make p99 latency worse. Every insert must touch an extra page, often at a random location, and those index pages can evict data pages from the cache that reads depend on. The cost did not vanish. It moved from the read path to the write path and into the cache.
Before tuning, count the distinct places the operation touches, both before and after the change, and ignore the byte total. Treat each block as one trip, so a scattered set of reads is many trips. Keep reads large and sequential where you can, because object stores and spinning disks reward streams. On NVMe, random reads cost less, but still count them, since you still fetch whole blocks. Choose by write pattern. Use a B-tree when lookups dominate and you can accept scattered updates. Use an LSM tree when writes dominate and you can accept reads that may check several files, plus background compaction that periodically rewrites the data.
- L1 cache
- ~1 ns
- RAM
- ~100 ns
- NVMe random read
- ~100 µs
- same-datacenter round trip
- ~500 µs
- spinning-disk seek
- ~5 ms
One CPU cycle is a third of a nanosecond, so a cache hit is a handful of them. Grace Hopper handed out 11.8-inch pieces of wire as "nanoseconds" (the distance light travels in that time) so officers could feel the limit physics sets.
A main-memory load, roughly 200 to 400 cycles. Wulf and McKee named the widening gap between CPU and memory the "memory wall" in 1995, and that gap is why caches and locality dominate performance work.
A random 4 KB read from a modern SSD. Jeff Dean's 2009 "latency numbers every programmer should know" listed a disk seek at 10 ms; SSDs moved that number three orders of magnitude, which is why random reads stopped being fatal and stopped being free.
One network hop inside a datacenter, including switch queues. It sits between an SSD read and an old disk seek, which is why a cache in another rack is not a cache, it is a remote call.
Head movement plus rotational delay. At 7200 rpm the platter makes one turn every 8.3 ms, so a miss costs multiple milliseconds before any data moves.
The obvious way to read a file is to map it into memory and let the operating system page in what you touch. That is what several databases did, and it looks like it deletes the whole problem: no buffer pool to write, no readahead to tune, the CPU just dereferences.
The wall is that a page fault is an I/O request you did not schedule. The kernel decides when to fetch, when to evict, and how much to prefetch, and it does that for every process on the machine, not just yours. Under memory pressure the database's hot pages leave the cache and the next access pays a full trip with fault overhead on top. Latency stops being predictable, and a query plan that was fine in a benchmark stalls in production.
Teams tried the surface fixes: madvise hints, transparent huge pages, explicit prefetch calls. Each helped a little and none restored control. Crotty, Leis and Pavlo catalogued the result in a 2022 paper and answered their own title with "probably not", for databases that need to bound tail latency.
The non-obvious lesson is that the cost model only works if you own the trips. Once the OS schedules your I/O, you can no longer say how many blocks a query touches, so you cannot say why p99 moved. Owning the buffer pool is not bureaucracy. It is the mechanism that makes the count in the equation observable.