Linux Kernel Architecture

(Jacob Rumans) #1

Chapter3:MemoryManagement


/* Initialize zone fields to default values,
* and call helper functions */
...
}

The kernel uses two global variables to keep track of how many pages are present in the system:
nr_kernel_pagescounts all identity mapped pages, whilenr_all_pagesalso includes high-memory
pages.

The task of the remaining part offree_area_init_coreis to initialize the list heads of thezonestruc-
ture and to initialize the various structure members to 0. Of particular interest are two helper functions
invoked:

❑ zone_pcp_initinitializes the per-CPU caches for the zone as discussed extensively in the next
section.
❑ init_currently_empty_zoneinitializes thefree_arealists and sets allpageinstances of pages
belonging to the zone to their initial defaults.memmap_init_zoneas discussed above is invoked
to initialize the pages of the zone. Also recall that all pages are attributed toMIGRATE_MOVABLEin
the beginning.
Additionally, the free lists are initialized inzone_init_free_lists:
mm/page_alloc.c
static void __meminit zone_init_free_lists(struct pglist_data *pgdat,
struct zone *zone, unsigned long size)
{
int order, t;
for_each_migratetype_order(order, t) {
INIT_LIST_HEAD(&zone->free_area[order].free_list[t]);
zone->free_area[order].nr_free = 0;
}
}

Thenumberoffreepages(nr_free) is still currently defined as 0, and this obviously does not reflect
the true situation. The correct value is not set until the bootmem allocator is disabled and normal buddy
allocation comes into effect.

3.5.4 Allocator API


As far as the interface to the buddy system is concerned, it makes no difference whether a NUMA or
a UMA architecture is used as the call syntax is the same for both. Common to all functions is the fact
that pages can only be allocated in integer powers of 2. For this reason, the desired memory size isnot
specified as parameter as it would be in themallocfunction of the C standard library or in the bootmem
allocator. Instead, the order of the allocation must be specified, and this causes the buddy system to
reserve 2orderpages in memory. Finer-grained allocationin the kernel is only possible with the help
of the slab allocator (or alternatively, the slub or slob allocators), which builds on the buddy system
(Section 3.6 gives further details).

❑ alloc_pages(mask, order)allocates 2orderpages and returns an instance ofstruct pageto rep-
resent the start of the reserved block.alloc_page(mask)is a shorter notation fororder = 0if
only one page is requested.
Free download pdf