Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


it were in RAM. Conversely, acoldpage is not held in cache. As each CPU has one or more caches on
multiprocessor systems, management must be separate for each CPU.


Even though a zone belongs to a specific NUMA node and is therefore associated
with a specific CPU, the caches of other CPUs may include pages from this zone —
ultimately, each processor can accessallpages in the system, albeit at different
speeds. The zone-specific data structuremust therefore cater not only for the CPU
associated with the NUMA node of the zone but also for all other CPUs in the
system.

pagesetis an array that holds as many entries as the maximum possible number of CPUs that the system
can accommodate.


<mmzone.h>
struct zone {
...
struct per_cpu_pageset pageset[NR_CPUS];
...
};

NR_CPUSis a configurable pre-processor constant defined at compilation time. Its value is always 1 on
uniprocessor systems, but on a kernel compiled for SMP systems, it may be between 2 and 32 (or 64 on
64-bit systems).


The value does not reflect the number of CPUs actually present in a system but the
maximum number of CPUs supported by the kernel.

The array elements are of typeper_cpu_pageset, which is defined as follows:


<mmzone.h>
struct per_cpu_pageset {
struct per_cpu_pages pcp[2]; /* 0: hot. 1: cold */
} ____cacheline_aligned_in_smp;

The structure consists of an array with two entries, the first to manage hot and the second to manage cold
pages.


The useful data are held inper_cpu_pages.^5


<mmzone.h>
struct per_cpu_pages {
int count; /* number of pages in the list */
int high; /* high watermark, emptying needed */
int batch; /* chunk size for buddy add/remove */
struct list_head list; /* the list of pages */
};

(^5) Kernel 2.6.25, which was still under development when this book was written, will replace the separate lists for hot and cold pages
by a single list. Hot pages will be kept at the beginning, while cold pages will be placed at the end. The change was introduced after
measurements had shown that having two separate lists would not provide substantial benefits compared to a single list.

Free download pdf