Chapter3:MemoryManagement
unsigned long flags; /* zone flags, see below */
/* Zone statistics */
atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
int prev_priority;
ZONE_PADDING(_pad2_)
/* Rarely used or read-mostly fields */
wait_queue_head_t * wait_table;
unsigned long wait_table_hash_nr_entries;
unsigned long wait_table_bits;
/* Discontig memory support fields. */
struct pglist_data *zone_pgdat;
unsigned long zone_start_pfn;
unsigned long spanned_pages; /* total size, including holes */
unsigned long present_pages; /* amount of memory (excluding holes) */
/*
- rarely used fields:
/
char name;
} ____cacheline_maxaligned_in_smp;
The striking aspect of this structure is that it is divided into several sections separated byZONE_PADDING.
This is because zone structures are very frequently accessed. On multiprocessor systems, it commonly
occurs that different CPUs try to access structure elements at the same time. Locks (examined in
Chapter 5) are therefore used to prevent them interfering with each, and giving rise to errors and
inconsistencies. The two spinlocks of the structure —zone->lockandzone->lru_lock—areoften
acquired because the kernel very frequently accesses the structure.^1
Data are processed faster they are is held in a cache of the CPU. Caches are divided into lines, and
each line is responsible for various memory areas. The kernel invokes theZONE_PADDINGmacro to
generate ‘‘padding‘‘ that is added to the structure to ensure that each lock is in its own cache line.
The compiler keyword__cacheline_maxaligned_in_smpis also used to achieve optimal cache
alignment.
The last two sections of the structure are also separated from each other by padding. As neither includes
a lock, the primary aim is to keep the data in a cache line for quick access and thus to dispense with the
need for loading the data from RAM memory, which is a slow process. The increase in size due to the
padding structures is negligible, particularly as there are relatively few instances of zone structures in
kernel memory.
What is the meaning of the structure elements? Since memory management is a complex and comprehen-
sive part of the kernel, it is not possible to cover the exact meaning of all elements at this point — a good
part of this and of following chapters will be devoted to understanding the associated data structures
and mechanisms. What I can provide, however, is an overview that gives a taste of the problems I am
about to discuss. A large number of forward references is nevertheless unavoidable.
(^1) Thelocksarethereforeknownashotspots. In Chapter 17, some tricks that are used by the kernel to reduce the pressure on these
hotspots are discussed.