Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


4.5 Operations on Regions


The kernel provides various functions to manipulate the regions of a process. Creating and deleting
regions (and finding a suitable memory location for a new region) are standard operations needed when
setting up or removing a mapping. The kernel is also responsible for performing optimizations when
managing the data structures, as shown in Figure 4-10.

Existing region New region Region is being deleted

Figure 4-10: Operations on regions.

❑ When a new region is added immediately before orafter an existing region (and therefore also
between two existing regions), the kernel merges the data structures involved into a single
structure — but, of course,onlyif the access permissions for all the regions involved are identical
and contiguous data are mapped from the same backing store.
❑ If a deletion is made at the start or end of a region, the existing data structure must be truncated
accordingly.
❑ If a regionbetweentwo other regions is deleted, the existing data structure is reduced in size, and
a new data structure is created for the resultant new region.

A further important standard operation is the search for a region associated with a specific virtual address
in userspace. Before explaining the optimizations mentioned above, let’s discuss the helper function used
to do this.

4.5.1 Associating Virtual Addresses with a Region


By reference to a virtual address,find_vmafinds the first region in user address space whose end isafter
the given address and therefore satisfies theaddr < vm_area_struct->vm_endcondition. As parameters,
the function requires not only the virtual address (addr) but also a pointer to themm_structinstance of
the relevant process whose address space is to be scanned.

<mm/mmap.c>
struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long addr)
{
struct vm_area_struct *vma = NULL;

if (mm) {
/* Check the cache first. */
Free download pdf