Why Virtual Memory and Paging Make Your Computer Faster and Safer
This article explains how memory serves as the main storage for processes, introduces the concepts of virtual memory and paging, and describes how page tables and multi‑level paging enable efficient address translation, isolation, and sharing in modern operating systems.
Memory
Memory is the computer's primary storage, providing each process with its own address space to store data. It is organized as a linear address space, with each byte addressed sequentially starting from 0, typically shown in hexadecimal (e.g., 0x00000003, 0x1A010CB0).
Physical address space size is limited by the width of the address bus; a 32‑bit CPU can address from 0x00000000 to 0xFFFFFFFF. Memory uses RAM (Random Access Memory), which allows constant‑time access regardless of location, unlike sequential media such as tape.
Because RAM is volatile, persistent data must be stored on external devices like hard drives.
Virtual Memory
Processes cannot directly access physical memory; they operate on virtual memory addresses that the operating system translates to real addresses. Each process has its own independent virtual address space, allowing identical virtual addresses (e.g., 0x10001000) in different processes to map to different physical locations.
Virtual addresses provide isolation, preventing one process from modifying another's data, and enable memory sharing by mapping the same physical page into multiple virtual spaces (e.g., kernel space, shared libraries).
Memory Paging
To avoid storing a mapping for every byte, Linux uses paging: memory is divided into fixed‑size pages (commonly 4 KB). The page size can be queried with: $ getconf PAGE_SIZE which returns 4096, meaning each page holds 4096 bytes.
Within a page, the lower 12 bits of an address represent the offset, while the remaining bits form the page number. The OS only needs to map page numbers to physical pages.
Multi‑Level Page Tables
Page tables store the mapping between virtual page numbers and physical pages. A single linear page table would waste space because most processes use only a small fraction of their address space. Linux therefore employs multi‑level page tables: the virtual page number is split into several parts, each indexed by a separate level of tables.
In a simplified two‑level design, the first level indexes the high‑order bits (e.g., the first 8 bits), pointing to a second‑level table that handles the remaining bits. Unused top‑level entries can be left empty, saving memory.
Multi‑level tables also allow the second‑level pages to be scattered throughout memory, making use of fragmented free space.
Overall, paging separates virtual and physical memory, improves security and stability, and enables efficient address translation in modern operating systems.
int v = 0; printf("%p", (void *)&v);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.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
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.
