Chapter3:MemoryManagement
to 1, whereasvunmapsets it to 0 because in this case only the mappings are removed but the associ-
ated physical pages are not returned to the buddy system. Figure 3-40 shows the code flow diagram for
__vunmap.
__vunmap
remove_vm_area
_ _remove_vm_area
_ _free_pages
unmap_vm_area
deallocate_pages set?
Find areas
Free kernel data structures
Figure 3-40: Code flow diagram for__vunmap.
It is not necessary to explicitly state the size of the area to be freed because this can be derived from
the information invmlist. The first task of__vunmapis therefore to scan this list in__remove_vm_area
(invoked byremove_vm_areaafter completion of locking) in order to find the associated entry.
Thevm_areainstance found is used byunmap_vm_areato remove the entries no longer needed from
the page tables. In the same way as when memory is reserved, the function works its way through the
various hierarchy levels of page management, but thistime removes the entries involved. It also updates
the CPU caches.
If the__vunmapfunction parameterdeallocate_pagesis set to a true value (invfree), the kernel iterates
over all elements ofarea->pagesin which there are pointers to thepageinstances of the physical pages
involved.__free_pageis invoked for each entry to return the page to the buddy system.
Finally, the kernel data structures used to manage the memory area must be returned.
3.5.8 Kernel Mappings
Although thevmallocfamily of functions can be used to map pages from the highmem area into the
kernel (these are then not usually directly visible in kernel space), this is not the actual purpose of these
functions. It is important to underline this fact because the kernel provides other functions for the explicit
mapping ofZONE_HIGHMEMpages into kernel space, and these are unrelated to thevmallocmechanism;
this is, therefore, a common source of confusion.
Persistent KernelMappings
Thekmapfunction must be used if highmem pages are to be mapped into kernel address space for a
longer period (as apersistent mapping).Thepagetobemappedisspecifiedbymeansofapointertopage
as the function parameter. The function creates a mapping when this is necessary (i.e., if the page really
is a highmem page) and returns the address of the data.