Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 16: Page and Buffer Cache


If one of the buffers is modified, this has an immediate effect on the contents of the page (and
vice versa) so that there is no need for explicit synchronization of the two caches — after all,
both share identical data.

Page frame

buffer_head
b_this_page
b_data

Figure 16-2: Link between pages and buffers.

There are, of course, applications that access block devices using blocks rather than pages — reading
the superblock of a filesystem is one such example. A separate buffer cache is used to speed access of
this kind. The buffer cache operates independently of the page cache, not in addition to it. To this end,
buffer heads — the data structure is the same in buffer caches and page caches — are grouped together
in an array of constant size whose individual entries are managed on a least recently used basis. After
an entry has been used, it is placed at position 0 and the other entries are moved down accordingly;
this means that the entries most frequently used are located at the beginning of the array and those less
frequently used are pushed further back until they finally ‘‘drop‘‘off the array if they have not been used
for a lengthy period.

As the size of the array and therefore the number of entries in the LRU list are restricted to a fixed value
that does not change during kernel run time, the kernel need not execute separate threads to trim the
cache size to reasonable values. Instead, all it need do is remove the associated buffer from the cache
when an entry drops off the array in order to release memory for other purposes.

Section 16.5 discusses in detail the technical detailsof buffer implementation. Before this, it is necessary to
discuss the concept of address spaces because these are key to the implementation of cache functionality.

16.3 Address Spaces


Not only have caches progressed from a buffer orientation to a page orientation during the course of
Linux development, but also the way in which cached data are linked with their sources has been
replaced with a more general schema as compared to previous Linux versions. Whereas in the early
days of Linux and otherUnixderivatives, inodes were the only objects that acted as the starting point
for obtaining data from cache contents, the kernel now uses much more generaladdress spacesthat estab-
lish the link between cached data and the objects and devices required to obtain the data. Although file
contents still account for much of the data in caches, the interfaces are so generalized that the caches are
also able to hold data from other sources in order to speed access.
Free download pdf