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

Why SLAB?

Slab architecture

../_images/slab-overview.png

Cache descriptors

SLAB descriptors

Slab detailed architecture

../_images/slab-detailed-arch.png

Generic vs specific caches

Object descriptors

../_images/slab-object-descriptors.png

Object descriptors

SLAB coloring

../_images/slab-coloring.png

Virtual memory management

Address space descriptors

 

../_images/ditaa-0eda95a3f39dfac448fd07589656b123d3548328.png

Address space descriptors

Allocating virtual memory

Freeing virtual memory

Linux virtual memory management

Linux virtual memory management

../_images/page-fault-handling.png