Article directory
1. Partition partner allocator
in the first two blogs
- [Linux Kernel Memory Management] Partner Allocator ① (Partner Allocator Introduction | Page Block, Order | Partner)
- [Linux Kernel Memory Management] Partner Allocator ② (Partner Allocator Allocating Memory Process)
, explains the basic partner allocator concept, and the memory allocation process;
The concept of partition buddy allocator: The Linux kernel adds support for "memory node" and "memory area" based on the basic partner allocator , which is "Partition Buddy Allocator" , the English name is "Zond Buddy Allocator";
The partition partner allocator focuses on a specific memory region of a specific memory node;
Features of "Partition Partner Allocator":
- The physical memory is grouped according to mobility to prevent memory fragmentation;
- Optimized "single page memory allocation" , reduced lock contention between CPUs, increased per ;
Second, the partition partner allocator source data structure
1. free_area free area array
The members in the memory area zone
structure are the array data structuresfree_area
used to maintain free page blocks, and the subscript index of the array corresponds to the page block order;free_area
That free_area[0]
is to say, it means 0 0Level 0 page block free memory, whichfree_area[2]
means2 2Level 2 page block free memory;
struct zone {
...
/* free areas of different sizes */
struct free_area free_area[MAX_ORDER];
...
}
Source code path: linux-4.12\include\linux\mmzone.h #453
"memory area" struct zone
structure location:
Source code path: linux-4.12\include\linux\mmzone.h #350
2. MAX_ORDER macro definition (the maximum order of pages in the free area)
struct free_area free_area[MAX_ORDER];
The value of the MAX_ORDER
macro is 11 1111 ,
MAX_ORDER
is the largest order 11 111 1 , the partner allocator can allocate a maximum of2 10 2^{10}210 page blocks, or10 101 0 -order page block;
free_area[10]
means 10 101 0 -order page block free memory, which is2 10 2^{10}210 page blocks ;
#ifndef CONFIG_FORCE_MAX_ZONEORDER
The function is to determine whether a CONFIG_FORCE_MAX_ZONEORDER
macro definition is defined. The function of the macro definition is to "specify the maximum order". If not specified, the specified maximum order is 11 1111 ;
MAX_ORDER
Macro definition source code:
/* Free memory management - zoned buddy allocator. */
#ifndef CONFIG_FORCE_MAX_ZONEORDER
#define MAX_ORDER 11
#else
#define MAX_ORDER CONFIG_FORCE_MAX_ZONEORDER
#endif
#define MAX_ORDER_NR_PAGES (1 << (MAX_ORDER - 1))
Source path: linux-4.12\include\linux\mmzone.h #24