Inserting Regions

insert_vm_struct is the standard function used by the kernel to insert new regions. The actual work is delegated to two helper functions, as the code flow diagram in Figure 4-11 shows.

find_vma_prepare is first invoked to obtain the information listed below by reference to the start address of the new region and of the address space involved (mm_struct).

□ The vm_area_struct instance of the preceding address space.

□ The parent node (in the red-black tree) in which the node for the new region is held.

□ The leaf node (of the red-black tree) that contains the region itself.

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 using vma_link. After some preparatory work, the function delegates the real work to insert_vm_struct, which performs three insert operations as the code flow diagram shows.

□ _vma_link_list puts the new region on the linear list of regions of the process; only the predecessor and successor region found using find_vma_prepare are needed to do this.7

□ _vma_link_rb links the new region into the data structures of the red-black tree, as the name suggests.

□ _anon_vma_link adds the vm_area_struct instance to the linked list of anonymous mappings discussed above.

Finally, vma link file links the relevant address_space and the mapping in the case of file mappings and also adds the region to the prio tree using vma_prio_tree_insert, which handles multiple identical regions as described above.

Continue reading here: Creating Regions

Was this article helpful?

0 0