Linux Kernel Architecture

(Jacob Rumans) #1

Chapter 4: Virtual Process Memory



  1. It checks whether the_PAGE_ACCESSEDbit is set in the page table entry and then deletes the
    bit. This flag is set on each access to the page by the hardware (with the additional support
    of the kernel if required by the particular architecture). The reference counter is incremented
    by 1 if the bit is set; otherwise, it is left unchanged. As a result, frequently used pages have
    a high number of references, and the opposite is true for rarely used pages. The kernel is
    therefore able to decide immediately whether a page is important based on the number of
    references.


The approach adopted for checking the number of references for pages with file-based mapping is
similar.

mm/rmap.c
static int page_referenced_file(struct page *page)
{
...
mapcount = page_mapcount(page);

vma_prio_tree_foreach(vma, &iter, &mapping->i_mmap, pgoff, pgoff) {
if ((vma->vm_flags & (VM_LOCKED|VM_MAYSHARE))
== (VM_LOCKED|VM_MAYSHARE)) {
referenced++;
break;
}
referenced += page_referenced_one(page, vma, &mapcount);
if (!mapcount)
break;
}

...
return referenced;
}

The kernel invokesvm_prio_tree_foreachto iterate over all elements of the priority tree that store a
region where the relevant page is included. As above,page_referenced_oneis invoked for each page in
order to collect all references. If a page is locked into memory (withVM_LOCKED) and may be shared by
processes (VM_MAYSHARE), the reference value is increased further because pages of this kind should not
be swapped out and are therefore given a bonus.

4.9 Managing the Heap


Managing theheap— the memory area of a process used to dynamically allocate variables and data — is
not directly visible to application programmers because it relies on various helper functions of the stan-
dard library (the most important of which ismalloc) to reserve memory areas of any size. The classic
interface betweenmallocand the kernel is thebrksystem call that expands/shrinks the heap. Recent
malloc implementations (such as those of the GNU standard library) now use a combined approach that
operates withbrkand anonymous mappings. This approach delivers better performance and certain
advantages when returning larger allocations.
Free download pdf