Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory


insert_vm_struct

find_vma_prepare

vma_link

_ _vma_link

_ _vma_link_list

_ _vma_link_rb

_ _anon_vma_link

_ _vma_link_file

Figure 4-11: Code flow diagram for
insert_vm_struct.

It’s common knowledge that C permits functions to return just one variable — consequently, the above
function returns only a pointer to the successor region as its direct result; the remaining information is
supplied by means of pointer arguments.

The information found is sufficient to incorporate the new region into the existing data structures
of the process usingvma_link. After some preparatory work, the function delegates the real
work toinsert_vm_struct, which performs three insert operations as the code flow diagram
shows.

❑ __vma_link_listputs the new region on the linear list of regions of the process; only the prede-
cessor and successor region found usingfind_vma_prepareare needed to do this.^7
❑ __vma_link_rblinks the new region into the data structures of the red-black tree, as the name
suggests.
❑ __anon_vma_linkadds thevm_area_structinstance to the linked list of anonymous mappings
discussed above.

Finally,__vma_link_filelinks the relevantaddress_spaceand the mapping in the case of file mappings
and also adds the region to the prio tree usingvma_prio_tree_insert, which handles multiple identical
regions as described above.

4.5.4 Creating Regions


Before a new memory region can be inserted into thedata structures, the kernel must establish where
there is enough free space in virtual address space for a region of a given size. This job is assigned to the
get_unmapped_areahelper function.

(^7) If there is no predecessor region because the new region is the new start region or because no regions are defined for the address
space, the information in the red-black tree is used to set the pointers correctly.

Free download pdf