The mm Directory

The files in the mm directory implement the architecture-independent portion of memory management for the Linux kernel. This directory contains the functions for paging, allocation and deallocation of memory, and the various techniques that allow user processes to map memory ranges to their address space.

Paging and Swapping

Surprisingly, swap.c doesn’t actually implement the swapping algorithm. Instead, it deals with the kernel command-line options swap= and buff=. These options can also be tuned via the sysctl system call or by writing to the /proc/sys/vm files.

swap_state.c is in charge of maintaining the swap cache and is the most difficult file in this directory; I won’t go into detail about it, as it’s hard to understand its design, unless a good knowledge of the relevant data structures and policies has been developed in advance.

swapfile.c implements the management of swap files and devices. The swapon and swapoff system calls are defined here, the latter being very difficult code. For a comparison, several Unix systems don’t implement swapoff, and can’t stop swapping to a device or file without rebooting. swapfile.c also declares get_swap_page, which retrieves a free page from the swap pool.

vmscan.c is the code that implements paging policies. The kswapd daemon is defined in this file, as well as all the functions that scan memory and the running processes looking for pages to swap out.

Finally, page_io.c implements the low-level data transfer ...

Get Linux Device Drivers 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.