Implementing the PFRA
The page frame reclaiming algorithm must take care of many
kinds of pages owned by User Mode processes, disk caches and memory
caches; moreover, it has to obey several heuristic rules. Thus, it is
not surprising that the PFRA is composed of a large number of functions.
Figure 17-3 shows the
main PFRA functions; an arrow denotes a function invocation, thus for
instance try_to_free_pages( )
invokes
shrink_caches( )
, shrink_slab( )
, and out_of_memory( )
.
As you can see, there are several “entry points” for the PFRA. Actually, page frame reclaiming is performed on essentially three occasions:
- Low on memory reclaiming
The kernel detects a “low on memory” condition.
- Hibernation reclaiming
The kernel must free memory because it is entering in the suspend-to-disk state (we don’t further discuss this case).
- Periodic reclaiming
A kernel thread is activated periodically to perform memory reclaiming, if necessary.
Figure 17-3. The main functions of the PFRA
Low on memory reclaiming is activated in the following cases:
The
grow_buffers( )
function, invoked by_ _getblk( )
, fails to allocate a new buffer page (see the section "Searching Blocks in the Page Cache" in Chapter 15).The
alloc_page_buffers( )
function, invoked bycreate_empty_buffers( )
, fails to allocate the temporary buffer heads for a page (see the section "Reading and Writing a File" in Chapter 16).The
_ _alloc_pages( ...
Get Understanding the Linux Kernel, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.