Fundamentals 12 min read

Understanding Linux Memory Management: Physical, Virtual, and Page Tables

This article explains how Linux organizes physical memory, allocates pages using the buddy system and SLUB, structures virtual address spaces for user and kernel modes, and maps virtual addresses to physical memory through page tables, TLBs, and dynamic mappings.

Open Source Linux
Open Source Linux
Open Source Linux
Understanding Linux Memory Management: Physical, Virtual, and Page Tables

1. Physical Memory

Linux memory is organized into three levels: pages, zones, and nodes. A page is the basic 4 KB unit. Zones contain multiple queues to manage pages and are divided into ZONE_DMA, ZONE_NORMAL, and ZONE_HIGHMEM. Each CPU corresponds to a node that includes these zones, and memory can be allocated from other nodes when one is exhausted.

Physical Memory Organization

Pages (4 KB) are the smallest unit. Zones group pages and provide queues for management. Zones are of three types:

ZONE_DMA – for DMA‑accessible I/O data (kernel‑only).

ZONE_NORMAL – for general kernel data (kernel‑only).

ZONE_HIGHMEM – for user‑process data.

Each node represents a CPU and contains one of each zone.

Physical Memory Allocation

Linux uses two allocation strategies:

1. Large allocations

Handled by the buddy system, which groups pages into lists of power‑of‑two sizes (1, 2, 4, …, 1024 pages). When a request for a block of size (2i‑1, 2i] arrives, the allocator finds the smallest suitable block, splits larger blocks if necessary, and returns the requested size.

2. Small allocations

Handled by SLUB, which reserves a few pages as caches. SLUB maintains per‑CPU free lists; objects are taken from and returned to these lists without zeroing, improving allocation speed for small objects.

2. Organizing Virtual Addresses

Virtual addresses form a virtual address space that maps to physical memory. The space is split into user and kernel regions. In 32‑bit systems, the space is divided 1:3 between kernel (top quarter) and user (lower three‑quarters); in 64‑bit systems each gets 128 TB.

User‑mode layout

Each process has its own user virtual space containing Text (code), Data, BSS, heap, stack, and mmap regions.

Kernel‑mode layout

The kernel shares a single virtual space divided into:

Direct mapping area (≈896 MB) – a fixed offset mapping of ZONE_DMA and ZONE_NORMAL.

Dynamic mapping – allows the kernel to map any physical page in ZONE_HIGHMEM on demand.

Dynamic mappings come in three forms: dynamic (can be remapped after use), permanent (one‑to‑one until explicitly unmapped), and fixed (restricted to specific functions).

3. Mapping Virtual to Physical Addresses

Virtual addresses are translated to physical addresses via page tables. Each process has its own page table; the kernel has a single one. Both virtual and physical memory are paged in 4 KB units, and a page table entry maps a virtual page number to a physical page number.

The virtual address is divided into three fields: 10‑bit index into the page‑directory, 10‑bit index into the page‑table, and 12‑bit offset within the page.

TLB

The Translation Lookaside Buffer (TLB) caches recent virtual‑to‑physical translations in the CPU. A lookup first checks the TLB; on a miss, the page table is consulted.

Virtual Memory

Virtual memory uses a swap area on disk to hold pages that do not fit in RAM. When a page is needed, it is swapped back into physical memory, allowing programs to use more memory than physically available, albeit with performance penalties.

Summary

Linux separates virtual space into kernel and user regions. Virtual addresses are translated to physical addresses via page tables, with the TLB providing fast caching. Physical memory is managed in pages, zones, and nodes, allocated by the buddy system for large blocks and SLUB for small objects.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Memory ManagementLinuxVirtual MemoryOperating Systempage-tables
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.