Chapter 4: Virtual Process Memory
The individual elements have the following meanings:
❑ vm_mmis a back-pointer to themm_structinstance to which the region belongs.
❑ vm_startandvm_endspecify the virtual start and end addresses of the region in userspace.
❑ The linear linking of allvm_area_structinstances of a process is achieved usingvm_next,
whereas incorporation in the red-black tree is the responsibility ofvm_rb.
❑ vm_page_protstores the access permissions for the region in the constants discussed in
Section 3.3.1, which are also used for pages in memory.
❑ vm_flagsis a set of flags describing the region. I discuss the flags that can be set below.
❑ A mapping of a file into the virtual address space of a process is uniquely determined by the
interval in the file and the corresponding interval in memory. To keep track of all intervals asso-
ciated with a process, the kernel uses a linked list and a red-black tree as described above.
However, it is also necessary to go the other way round: Given an interval in a file, the kernel
sometimes needs to know all processes into which the interval is mapped. Such mappings are
calledshared mappings, and the C standard library, which is used by nearly every process in the
system, is a prime example of why such mappings are necessary.
To provide the required information, allvm_area_structinstances are additionally managed
in aprioritytree, and the elements required for this are contained inshared. As you can easily
imagine from the rather complicated definition of this structure member, this is a tricky business,
which is discussed in detail in Section 4.4.3 below.
❑ anon_vma_nodeandanon_vmaare used to manage shared pages originating from anonymous
mappings. Mappings that point to the same pages are held on a doubly linked list, where
anon_vma_nodeacts as the list element.
There are several of these lists, depending onhow many sets of mappings there are that share
different physical pages. Theanon_vmaelement serves as a pointer to the management structure
that is associated with each list and comprises a list head and an associated lock.
❑ vm_opsis a pointer to a collection of methods used to perform various standard operations on
the region.
<mm.h>
struct vm_operations_struct {
void (*open)(struct vm_area_struct * area);
void (*close)(struct vm_area_struct * area);
int (*fault)(struct vm_area_struct *vma, struct vm_fault *vmf);
struct page * (*nopage)(struct vm_area_struct * area, unsigned long
address, int *type);
...
};
❑ openandcloseare invoked when a region is created and deleted, respectively. They are
not normally used and have null pointers.
❑ However,faultis very important. If a virtual page is not present in an address space, the
automatically triggered page fault handler invokes this function to read the corresponding
data into a physical page that is mapped into the user address space.
❑ nopageis the kernel’s old method to respond to page faults that is less flexible thanfault.
The element is still provided for compatibility reasons, but should not be used in new code.