SO2 Lecture 07 - Memory Management

Memory Management

Physical Memory Management

Memory zones

Non-Uniform Memory Access

Page allocation

/* Allocates 2^order contiguous pages and returns a pointer to the
 * descriptor for the first page
struct page *alloc_pages(gfp_mask, order);

/* allocates a single page */
struct page *alloc_page(gfp_mask);

/* helper functions that return the kernel virtual address */
void *__get_free_pages(gfp_mask, order);
void *__get_free_page(gfp_mask);
void *__get_zero_page(gfp_mask);
void *__get_dma_pages(gfp_mask, order);

Why only allocate pages in chunks of power of 2?

The buddy algorithm

Allocating a block of size N

Freeing a block of size N

The Linux implementation

Small allocations

The SLAB allocator


Slab architecture


Cache descriptors

SLAB descriptors

Slab detailed architecture


Generic vs specific caches

Object descriptors


Object descriptors

SLAB coloring


Virtual memory management

Address space descriptors



Address space descriptors

Allocating virtual memory

Freeing virtual memory

Linux virtual memory management

Linux virtual memory management