Chapter 16: Page and Buffer Cache
window. Mathematically speaking, the maximal readahead size is a fixed point of both functions. In
practical terms, this means that the readahead window can never grow beyond the maximally allowed
value, in this case, 32 pages.
5
10
15
20
25
30
5 10 15 20 25 30
Window size
Request size and last read readahead window, respectively
Initial window size
Next window size
Figure 16-6: How the kernel determines the readahead window depending on the
request size.
Let’s go back toondemand_readahead, which has to set the readahead window with the help of these
auxiliary functions. Three cases are most essential:
- The current offset is either at the end of the previous readahead window or at the end of the
interval that was synchronously read in. In both cases, the kernel assumes sequential read
access, and usesget_next_ra_sizeto compute the new window size as discussed. - If the readahead marker was hit, but the previous readahead state does not predict this, then
most likely two or more concurrent streams perform interleaved reads on the file — and
invalidate each other’s readahead state in the process. The kernel constructs a new reada-
head window that suits all readers. - If (among others) first read access on a file is performed or a cache miss has happened, a new
readahead window is set up withget_init_ra_size.
16.5 Implementation of the Buffer Cache
The buffer cache is used not only as an add-on to the page cache but also as an independent cache for
objects that are not handled in pages but in blocks.