wire / wire-format / page-allocator
The Linux page allocator uses the buddy system for physical page allocation. Memory is divided into blocks of power-of-2 pages (order 0 = 1 page, order 1 = 2 pages, ..., order 10 = 1024 pages = 4MB). Free blocks are kept in per-order free lists. Allocation: find smallest free block >= requested size, split if larger (buddy). Deallocation: coalesce with buddy if free. Per-zone (DMA, DMA32, Normal, Movable, Device) and per-node (NUMA).
aka: Linux page allocator (buddy system)
spec: Linux kernel (buddy allocator)
The Linux page allocator uses the buddy system for physical page allocation. Memory is divided into blocks of power-of-2 pages (order 0 = 1 page, order 1 = 2 pages, ..., order 10 = 1024 pages = 4MB). Free blocks are kept in per-order free lists. Allocation: find smallest free block >= requested size, split if larger (buddy). Deallocation: coalesce with buddy if free. Per-zone (DMA, DMA32, Normal, Movable, Device) and per-node (NUMA).
| field | size | meaning |
|---|---|---|
| Order | 0-10 (or higher) | Order n = 2^n pages. Order 0 = 1 page (4KB), order 10 = 1024 pages (4MB). |
| Free list | per order, per zone | Doubly-linked list of free blocks of each order. |
| Allocation | O(log n) | Find smallest free block >= requested. If larger, split (buddy). May allocate from higher order. |
| Deallocation | O(log n) | Free block. Check if buddy is free; if so, coalesce. Repeat. |
| Zones | per node | DMA (0-16MB), DMA32 (0-4GB), Normal (4GB+), Movable, Device. Each zone has its own free lists. |
| NUMA | per node | Each NUMA node has its own zones. Allocation prefers local node. |
| Fragmentation | metric | External fragmentation: free memory split into small blocks. Compaction (memory compaction) defragments. |
| Watermarks | per zone | min, low, high watermarks. When free memory drops below 'low', kswapd (reclaim) starts. Below 'min', direct reclaim (blocking). |
example:
00 00 00 00
Buddy allocator (placeholder)
agent: curl -H 'accept: application/json' wire.phall.io/wire-format/page-allocator
or /wire-format/page-allocator.json