Understanding Linux Memory Management: Physical, Virtual, and Page Tables
This article explains how Linux organizes physical memory into pages, zones, and nodes, allocates memory using the buddy system and SLUB, structures virtual address spaces for user and kernel, and maps virtual addresses to physical memory through page tables, dynamic mapping, and TLB caching.
Physical Memory Organization
Linux divides physical memory into three hierarchical levels:
Page : the basic unit, typically 4 KB.
Zone : groups pages into multiple queues. Zones include ZONE_DMA (for DMA‑capable I/O), ZONE_NORMAL (kernel data), and ZONE_HIGHMEM (user process data).
Node : each CPU has a node containing one of each zone; memory can be borrowed from other nodes when a CPU’s local memory is exhausted.
Physical Memory Allocation
Linux uses two allocation strategies:
Buddy System (large allocations) : pages are grouped into blocks of sizes 2^n pages (1, 2, 4, …, 1024). When a request for a block of size 2i pages arrives, the allocator checks the corresponding free list; if empty, it splits a larger block.
SLUB (small allocations) : suitable for objects and other small data. SLUB extracts a few pages as caches, maintains free lists, and hands out memory without zero‑clearing each time.
Virtual Address Organization
Virtual addresses form a virtual address space that maps to physical memory. The space is split into user‑mode and kernel‑mode regions.
On 32‑bit systems the split is roughly 1:3 (kernel:user).
On 64‑bit systems each mode can address up to 128 TB.
User‑mode layout includes sections for text, data, BSS, heap, stack, and mmap regions, each described by a struct created when the process starts.
Kernel‑mode layout is shared by all kernel code and consists of:
Direct‑mapped area (≈ 896 MB) where virtual addresses map linearly to ZONE_DMA and ZONE_NORMAL .
Dynamic mapping area, which can map any physical page (including ZONE_HIGHMEM ) on demand.
Mapping Virtual to Physical Memory
Linux uses page tables to translate virtual addresses to physical addresses. Each process has its own page table; the kernel has a single global table.
Both virtual and physical memory are divided into 4 KB pages, creating a one‑to‑one correspondence between virtual pages and physical pages.
The 32‑bit virtual address is split into three fields:
10 bits: index into the first‑level page‑table directory.
10 bits: index into the second‑level page‑table entry.
12 bits: offset within the 4 KB page.
This scheme reduces the need for large contiguous memory for page tables; each 4 KB page can store 1 K page‑table entries.
On 64‑bit systems a five‑level page‑table hierarchy is used.
TLB and Virtual Memory
The Translation Lookaside Buffer (TLB) caches recent virtual‑to‑physical translations inside the CPU. A lookup first checks the TLB; a miss triggers a page‑table walk.
Virtual memory extends usable memory by swapping out inactive pages to a disk‑based swap partition. When a swapped‑out page is accessed, a page‑fault occurs, the kernel loads the page back into RAM, and updates the page table.
Summary
Linux separates memory into kernel and user virtual spaces, each mapped to physical memory via page tables. Physical memory is organized into pages, zones, and nodes, with allocation handled by the buddy system for large blocks and SLUB for small objects. Dynamic mapping and TLB caching enable flexible, efficient address translation, while virtual memory and swap allow programs to use more memory than physically available.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
