1. Preface
The series of articles about memory management in this article is mainly about the memory management knowledge lecture of Chen Li June teacher.
This lecture is divided into three topics on memory management: Hardware foundation of memory management, management of virtual address space, management of physical address space.
This paper mainly introduces the X86 architecture as an example to introduce the partner algorithm and slab assignment
2. Overview of partner Algorithms
The Linux partner algorithm divides all the free pages into max_order+1 (max_order default size is 11) block list
One node in each list points to a block containing 2 of a power page, either a block of pages or a block of abbreviations
Two page blocks of the same size and physical address contiguous are called partners
- How partner algorithms work
First in the size to meet the requirements of the block list to find whether there are free blocks, if any, directly allocated, otherwise in the larger block list of the block list;
The inverse process is the release of the block, which merges the blocks that satisfy the partnership, forming a larger block and inserting it into the corresponding block list
3. Data structures related to the partner algorithm
Each page box corresponds to a struct page instance
Each memory area is associated with a struct zone zone, which is managed with a Free_area array for the free page box
4. Example of a partner algorithm structure
Diagram Partner algorithm structure example diagram
5. Partner algorithm Allocation principle
6. Implementation of Page box assignment
7. Physical memory Allocator
Two memory allocators based on partner algorithm, per-CPU cache, and slab cache
- Partitioned page box allocator (zoned page frame allocator)
Handles memory allocation requests to contiguous page boxes. The partition page box allocator is divided into two parts: the admin area Distributor and the partner system
The Admin Area Distributor is responsible for searching a management area which can satisfy the request page frame size;
In each management area, the specific page frame assignment is the responsibility of the partner system, and for better performance, the request for a single page box is done directly by the per-CPU page box cache
Figure Partition Page Box Splitter example diagram
A variety of allocation object partitions are put into the cache, that is, each cache has a "reserve" for the same type of allocated objects
Linux Memory Management 6---partner algorithms and Slab