16.7. Freeing Page Frames

Page frames can be freed in several possible ways:

  • By reclaiming an unused page frame within a cache. Depending on the type of cache, the following functions are used:

    shrink_mmap( )

    Used for the page cache, swap cache, and buffer cache

    shrink_dcache_memory( )

    Used for the dentry cache

    kmem_cache_reap( )

    Used for the slab cache (see Section 6.2.7 in Chapter 6)

  • By swapping out a page belonging to an anonymous memory region of a process or a modified page belonging to a private memory mapping.

  • By swapping out a page belonging to an IPC shared memory region.

As we shall see shortly, the choice among these possibilities is done in a rather empirical way, with very little support from theory. The situation is somewhat similar to evaluating the factors that determine the dynamic priority of a process. The main objective is to get a tuning of the parameters that achieve good system performance, without asking too many questions about why it works.

16.7.1. Monitoring the Free Memory

Besides the nr_free_pages variable, which expresses the current number of free page frames, the kernel relies on two values, a kind of low and high watermark. These values are stored in a structure called freepages (it also has a low field that is no longer used in Linux 2.2):

min

Minimum number of page frames reserved to the kernel to perform crucial operations (e.g., for swapping pages to disk). (free_area_init( ) initializes this field to 2n, where n denotes the size of primary ...

Get Understanding the Linux Kernel 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.