Linux kernel source code reading memo at memory region operation.
Kernel manage virtual address space seen from user process as
Assigned memory regions is soreted in address order by red-black tree
mm_struct->mm_rb and manged in the unit of
vm_area_struct points the start and end addresses.
unsigned long vm_start; /* Our start address within vm_mm. */ unsigned long vm_end; /* The first byte after our end address within vm_mm. */
These data structures only manages the allocation and deallocation of memory in the kernel, Page table may be managed another place.
Almost all functions start from searching address (range) from
mm_rb. and each process have the cache to omit searching.
mm->mmap_cache in v2.6 is
task_struct->vmacache currently, and it can be stored four vma cache for each process.
vmacache_* functions are used for manipulating it.
addr < vm_end. It’s not necessary to contain the
addr in the
mm_rb, if tareget vma found, return, else NULL.
Returns the vma that overlaps with argumented address range,
That means to test the return value of
find_vma(mm, start_addr) is
end_addr <= vma.vm_start, or not.
There are functions for searching free range, and adding regions.
The relevant functions with
do_mmap has changed from v2.6.x.
populate_vma_page_range() is function to add memory to page table, not
Chapter 9 of Understanding the Linux Kernel.