This chapter has discussed many aspects of memory management. Our focus lies on physical memory management, but the connection between virtual and physical memory via page tables has also been covered. Although the architecture-specific details in this area differ greatly among the various architectures supported by Linux, an architecture-independent set of data structures and functions allows generic code to manipulate the page tables. However, some architecture-specific code is required before the generic view is enabled, and this code runs during the boot process.

Once the kernel is up and running, memory management is handled by two layers: The buddy system is responsible for the management of physical page frames, while the slab allocator must handle small allocations and provides an in-kernel equivalent to the malloc function family known from userland programming.

The buddy system is centered around the idea of splitting and recombining larger continuous blocks of pages. When a continuous area becomes free, the kernel notices this automatically, and can use it once the need for a corresponding allocation arises. Since this is unfortunately not sufficient to prevent fragmentation of physical memory after longer uptimes in a satisfactory manner, recent kernels have acquired anti-fragmentation techniques that allow grouping pages by their mobility, on the one hand, and augment the kernel with a new virtual memory zone, on the other hand. Both help to avoid fragmentation by essentially decreasing the chance that coalescing of larger regions is prohibited by allocated blocks in their middle.

The slab allocator is implemented on top of the buddy system. It does not only allow to allocate small chunks of memory for arbitrary use, but additionally offers the possibility to create specific caches for often used data structures.

Initializing memory management is challenging because the data structures employed by the subsystem itself also require memory, which must be allocated from somewhere. We have seen how the kernel solves the situation by introducing a very simple boot memory allocator that is shut down after the proper allocation routines function fully.

While we have mostly focused on physical memory here, the next chapter will discuss how the virtual address space is managed by the kernel.

Continue reading here: Virtual Process Memory

Was this article helpful?

0 0