Understanding Memory: From Physical RAM to Virtual Paging in Linux
This article explains how computer memory works, covering physical RAM, linear addressing, the role of virtual memory, address translation, paging mechanisms, and multi‑level page tables in Linux, providing clear examples and diagrams for deeper insight.
Memory
Memory is the computer's main storage, providing each process with its own address space to store data. It consists of bytes addressed linearly, typically shown in hexadecimal (e.g., 0x00000003). The address space size depends on the CPU's address bus width; a 32‑bit CPU offers addresses from 0x00000000 to 0xFFFFFFFF.
RAM (Random Access Memory) allows random reads, meaning access time is independent of data location, which is essential for predictable process execution.
While RAM supplies volatile storage for both the kernel and running processes, it cannot retain data after power loss, so persistent storage like disks is still required.
Virtual Memory
Processes cannot directly access physical memory; they operate on virtual memory addresses. The operating system translates these virtual addresses to physical ones, isolating each process's address space and enabling memory sharing without data copying.
In C, you can print a variable's address (which is a virtual address) as follows:
int v = 0;
printf("%p", (void *)&v);Virtual memory ensures processes are unaware of physical locations, enhancing security and stability.
Memory Paging
To avoid storing a mapping for every byte, Linux uses paging, dividing memory into fixed‑size pages (commonly 4 KB). The page size can be queried with $ getconf PAGE_SIZE, which returns 4096.
Each page has a page number and an offset; the offset (the lower 12 bits) identifies the byte within the page, while the page number is used for translation via page tables.
Multi‑Level Page Tables
Linux records the virtual‑to‑physical page mappings in page tables. A single linear page table would waste space, so Linux employs multi‑level tables: the first level maps high‑order bits of the page number to a second‑level table, which then maps the remaining bits to physical pages.
This hierarchical design reduces memory usage and allows unused regions to be omitted, similar to how telephone area codes map to local directories.
Modern Linux systems may use up to three levels of page tables, but the basic principle remains the same.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
