Memory Management
Memory management is one of the most complex and at the same time most important parts of the
kernel. It is characterized by the strong need for cooperation between the processor and the kernel
because the tasks to be performed require them to collaborate very closely. Chapter 1 provided a
brief overview of the various techniques and abstractions used by the kernel in the implementation
of memory management. This chapter examines the technical aspects of implementation in detail.
3.1 Overview
Memory management implementation covers many areas:
❑ Management of physical pages in memory.
❑ The buddy system to allocate memory in large chunks.
❑ The slab, slub, and slob allocators to allocate smaller chunks of memory.
❑ Thevmallocmechanism to allocate non-contiguous blocks of memory.
❑ The address space of processes.
As we know, the virtual address space of the processor is in general divided into two parts by
the Linux kernel. The lower and larger part is available to user processes, and the upper part is
reserved for the kernel. Whereas the lower part is modified during a context switch (between two
user processes), the kernel part of virtual address space always remains the same. On IA-32 systems,
the address space is typically divided between user processes and the kernel in a ratio of 3 : 1;
given a virtual address space of 4 GiB, 3 GiB would be available to userspace and 1 GiB for the
kernel. This ratio can be changed by modifying the relevant configuration options. However, this
has advantages only for very specific configurations and applications. For purposes of our further
investigations, I assume a ratio of 3 : 1 for now, but will come back to different ratios later.
The available physical memory is mapped into the address space of the kernel. Accesses with virtual
addresses whose offset to the start of the kernel area does not exceed the size of the available RAM
are thereforeautomaticallyassociated with physical page frames. This is practical because memory