Course contentsShow
← Linux
Lesson 1791 of 1,81915. Kernel Concepts for Systems AdministratorsFree lesson

Virtual memory and page tables

You will explain how the kernel maps virtual addresses to physical RAM.

In this lesson, you will learn how the Linux kernel translates a program's abstract "virtual" memory addresses into the actual physical RAM locations required by your CPU.

The Illusion of Contiguous Memory

Every user-space process operates under the assumption that it owns a massive, contiguous block of private memory. In reality, that memory is fragmented, scattered across physical RAM modules, or even swapped out to disk. The kernel maintains this illusion through Virtual Memory, acting as the intermediary between the CPU’s request for data and the physical hardware.

The Role of Page Tables

To track where each piece of a process resides, the kernel creates a multi-level data structure called a Page Table. Think of a page table as a massive, tiered index. When a process tries to access a virtual address (e.g., 0x7ffee1b), the CPU's Memory Management Unit (MMU) traverses this table to find the corresponding physical frame.

If the page is in RAM, the MMU retrieves the physical address. If the page is not in RAM, the MMU triggers a Page Fault, signaling the kernel to pause the process, load the required data from disk into a free physical frame, update the page table, and then resume the process.

The Translation Process

The address translation happens at the hardware level, but the kernel manages the structures:

Virtual Address (CPU) 
       |
[Page Table Level 4] -> [Page Directory] -> [Page Table] -> [Physical RAM]

Each level narrows down the location, much like a hierarchical file system points you to a specific file on a drive. For example, if you examine the memory maps of a process via /proc/<pid>/maps, you are seeing the high-level representation of these mappings. However, the true "heavy lifting" is performed by the kernel, which dynamically allocates and reclaims these physical frames to ensure that even if you have 8GB of RAM, your processes can collectively access 16GB or more of virtual space.

By decoupling virtual addresses from physical hardware, the kernel ensures that processes are isolated from one another, preventing a rogue application from reading or overwriting the memory belonging to the kernel or another process.

Key Takeaway: Virtual memory uses hierarchical page tables as a translation map, allowing the kernel to provide each process with a private, isolated memory space while efficiently managing limited physical RAM.