Skip to content
About
Main content

Spill is algorithm substitution

Why is spilling a change of algorithm rather than overflow, and what two problems does it buy?

Everything so far was about fitting. This article is about the moment the grant runs out. First, fix the mental model:

The difference is quantitative. Suppose you "paged out part of the hash table." You would then generate random reads at page against a structure designed for random access. That is precisely what swap does, and it is the worst access pattern the storage layer offers. Instead, a spilling operator abandons its algorithm and adopts a different one. The new algorithm's I/O is sequential by construction, because the operator partitions the data using a hash function it chose itself.

This is the theme of this mechanism for the fourth and last time, and its strongest quantitative case. The kernel cannot turn random access into sequential access, because it does not know the access pattern. The operator can, because it defined the pattern. The ratio between those two I/O patterns is about 20–50× on NVMe, and three orders of magnitude on the spinning disks this mechanism was designed for. That ratio is the entire reason database spill exists as something separate from operating-system paging.