Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


assigns physical pages to hold mapping data in Section 4.10 notes that there is then a need for reverse
mapping.

4.8.1 Data Structures


The kernel uses lean data structures to minimize management overhead for reverse mappings. Thepage
structure (discussed in Section 3.2.2) contains a single element to implement reverse mapping.

mm.h
struct page {
....
atomic_t _mapcount; /* Count of ptes mapped in mms,
* to show when page is mapped
* & limit reverse map searches.
*/
...
};

_mapcountindicates at how many points the page is shared. The original value of the counter is− 1 .Itis
assigned the value 0 when the page is inserted in the reverse mapping data structures and is incremented
by 1 for each additional user. This enables the kernel to check quickly how many users are using the page
in addition to the owner.

Obviously, this isn’t much help because the purpose of reverse mapping is to find all points at which the
physical page is used by reference to a givenpageinstance. Consequently, two other data structures have
aroletoplay:


  1. The priority search tree in which each region belonging to a non-anonymous mapping is
    embedded

  2. The linked lists of anonymous areas that lead back to the same pages in memory


The elements needed to generate both data structures are integrated invm_area_struct— these are the
sharedunion as well asanon_vma_nodeandanon_vma. To refresh the reader’s memory, I reproduce the
corresponding section fromvm_area_structbelow.

mm.h
struct vm_area_struct {
...
/*
* For areas with an address space and backing store,
* linkage into the address_space->i_mmap prio tree, or
* linkage to the list of like vmas hanging off its node, or
* linkage of vma in the address_space->i_mmap_nonlinear list.
*/
union {
struct {
struct list_head list;
void *parent; /* aligns with prio_tree_node parent */
struct vm_area_struct *head;
} vm_set;

struct raw_prio_tree_node prio_tree_node;
Free download pdf