Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 16: Page and Buffer Cache


How do address spaces fit into the structures of the page cache? They implement a translation mechanism
between two units:


  1. Pages in main memory are allocated to each address space. The contents of these pages can
    be manipulated by user processes or by the kernel itself using a variety of methods.
    These data represent the contents of the cache.

  2. Thebacking storespecifies the sources from which the address space pages are filled. Address
    spaces relate to the virtual address space of the processor and are a mapping of the segment
    managed by the processor in virtual memory and the corresponding positions on a source
    device (using a block device).
    If a position in virtual memory that is not associated with a physical page in memory is
    accessed, the kernel can refer to the address space structure to discover from where the data
    must be read.


To support data transfer, each address space providesa set of operations (in the form of function pointers)
to permit interaction between the two sides of address space — for instance, to read a page from a block
device or filesystem, or to write back a modified page. The following section takes a close look at the data
structures used before examining the implementation of address space operations.

Address spaces are one of the most crucial data structures in the kernel. Their management has evolved
to one of the central issues faced by the kernel. Numerous subsystems (filesystems, swapping, synchro-
nization, caching) are centered around the concept of an address space. They can therefore be regarded
as one of the fundamental abstraction mechanisms of the kernel, and range in importance among the
traditional abstractions like processes and files.

16.3.1 Data Structures


The basis of an address space is theaddress_spacestructure, which is in slightly simplified form defined
as follows:


struct address_space {
struct inode *host; /* owner: inode, block_device */
struct radix_tree_root page_tree; /* radix tree of all pages */
unsigned int i_mmap_writable;/* count VM_SHARED mappings */
struct prio_tree_root i_mmap; /* tree of private and shared mappings */
struct list_head i_mmap_nonlinear;/*list VM_NONLINEAR mappings */
unsigned long nrpages; /* number of total pages */
pgoff_t writeback_index;/* writeback starts here */
struct address_space_operations *a_ops; /* methods */
unsigned long flags; /* error bits/gfp mask */
struct backing_dev_info *backing_dev_info; /* device readahead, etc */
struct list_head private_list; /* ditto */
struct address_space *assoc_mapping; /* ditto */
} __attribute__((aligned(sizeof(long))));
❑ The link with the areas managed by an address space is established by means of a pointer to
an inode instance (of typestruct inode) to specify the backing store and a root radix tree
(page_tree) with a list of all physical memory pages in the address space.
Free download pdf