Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


N_HIGH_MEMORY, /* The node has regular or high memory */
#else
N_HIGH_MEMORY = N_NORMAL_MEMORY,
#endif
N_CPU, /* The node has one or more cpus */
NR_NODE_STATES
};

The statesN_POSSIBLE,N_ONLINE,andN_CPUare required for CPU and memory hotplugging, but these
features are not considered in this book. Essential for memory management are the flagsN_HIGH_MEMORY
andN_NORMAL_MEMORY. While the first one announces that the zone is equipped with memory that may
be either regular or high memory,N_NORMAL_MEMORYis only set if non-highmem memory is present
on a node.

Two auxiliary functions are provided to set or clear, respectively, a bit in the bit-field or a specific node:

<nodemask.h>
void node_set_state(int node, enum node_states state)
void node_clear_state(int node, enum node_states state)

Additionally, the macrofor_each_node_state(__node, __state)allows for iterating over all nodes
that are in a specific state, andfor_each_online_node(node)iterates over all active nodes.

If the kernel is compiled to support only a single node, that is, using the flat memory model, the node
bitmap is not present, and the functions to manipulate it resolve to empty operations that simply do
nothing.

Memory Zones


The kernel uses thezonesstructure to describe a zone. It is defined as follows:


struct zone {
/* Fields commonly accessed by the page allocator */
unsigned long pages_min, pages_low, pages_high;
unsigned long lowmem_reserve[MAX_NR_ZONES];

struct per_cpu_pageset pageset[NR_CPUS];

/*
* free areas of different sizes
*/
spinlock_t lock;
struct free_area free_area[MAX_ORDER];

ZONE_PADDING(_pad1_)

/* Fields commonly accessed by the page reclaim scanner */
spinlock_t lru_lock;
struct list_head active_list;
struct list_head inactive_list;
unsigned long nr_scan_active;
unsigned long nr_scan_inactive;
unsigned long pages_scanned; /* since last reclaim */
Free download pdf