Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


wolfgang@meitner>dmesg
...
Freeing unused kernel memory: 308k freed
...

In comparison with today’s typical main memory sizes, the approximately 300 KiB freed are not gigantic
but are a significant contribution. The removal of initialization data is important, particularly on hand-
held or embedded systems, which, by their very nature, make do with little memory.

3.5 Management of Physical Memory


Responsibility for memory management is assumed by the buddy system once kernel initialization has
been completed. The buddy system is based on a relatively simple but nevertheless surprisingly powerful
algorithm that has been with us for almost 40 years. It combines two key characteristics of a good memory
allocator — speed and efficiency.

3.5.1 Structure of the Buddy System


An instance ofstruct pageis available for each physical page of memory (a page frame) in the sys-
tem. Each memory zone is associated with an instance ofstruct zonethat holds the central array for
managing buddy data.

<mmzone.h>
struct zone {
...
/*
* free areas of different sizes
*/
struct free_area free_area[MAX_ORDER];
...
};

free_areais an auxiliary data structure we have not yet met. It is defined as follows:

<mmzone.h>
struct free_area {
struct list_head free_list[MIGRATE_TYPES];
unsigned long nr_free;
};

nr_freespecifies the number of free page blocks in the current area (counting is page by page for the
zeroth area, by two-page pairs for order 1, by sets of four pages for order 2, etc.).free_listis used to
link page lists. As discussed in Chapter 1, the page lists contain contiguous memory areas of the same
size. While the definition provides more than one page list, I ignore this fact for a moment and come back
to why there are different lists below.

Theorderis a very important term in buddy systems. It describes the quantified units in which memory
can be allocated. The size of a memory block is 2order,whereordermay extend from 0 toMAX_ORDER.
Free download pdf