Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


<mmzone.h>
#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))

The typical value of this constant is 11, which means that the maximum number of pages that can be
requested in a single allocation is 2^11 =2, 048. However, this value can be changed manually if the
FORCE_MAX_ZONEORDERconfiguration option is set by the architecture-specific code. For example, the
gigantic address spaces on IA-64 systems allow for working withMAX_ORDER = 18, whereas ARM or v850
systems use smaller values such as 8 or 9. This, however, is not necessarily caused by little memory sup-
ported by the machine, but can also be becauseof memory alignment requirements. Or, as theKconfig
configuration file for the V850 architecture puts it:

arch/v850/Kconfig
# The crappy-ass zone allocator requires that the start of allocatable
# memory be aligned to the largest possible allocation.
config FORCE_MAX_ZONEORDER
int
default 8 if V850E2_SIM85E2C || V850E2_FPGA85E2C

The indices of the individual elements of thefree_area[]array are also interpreted as order parameters
and specify how many pages are present in the contiguous areas on a shared list. The zeroth array ele-
ment lists sections with one page (2^0 =1), the first lists page pairs (2^1 =2), the third manages sets of 4
pages, and so on.

How are the page areas linked? Thelistelement of thefirstpage in the block is used to keep the blocks
in a list. As a result, there is no need to introduce a new data structure to group pages that are physically
contiguous — otherwise, they wouldn’t be in a block. Figure 3-22 illustrates the situation graphically.

next
prev
struct page

0
1
2
.
.
MAX_ORDER

Figure 3-22: Linking blocks in the buddy system.

The buddiesneed notbe linked with each other. If a block is broken down into two blocks of half the size
during allocation, the kernel automatically adds the unused half to the list of next smaller blocks. If, at
some point in the future, both blocks are not in use after memory has been freed, their addresses can be
referenced to automatically determine whether they are buddies. This minimal administrative effort is a
major advantage of the buddy system.
Free download pdf