Fundamentals 13 min read

Understanding Memory, Virtual Memory, and Paging in Linux

This article explains how computer memory works, covering physical memory characteristics, address spaces, RAM's random access nature, virtual memory translation, paging mechanisms, page size queries, and multi‑level page tables that enable efficient and secure memory management in Linux.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Understanding Memory, Virtual Memory, and Paging in Linux

Memory is the computer's main storage, allocating address space for each process to store data.

Memory

Simply put, memory is a data shelf where the smallest addressable unit is typically one byte, identified by a linear address that starts at 0 and increments by 1. Hexadecimal notation (e.g., 0x00000003, 0x1A010CB0) is commonly used to represent these addresses.

The address space limit is tied to the width of the address bus; a 32‑bit CPU like Intel's 80386 can address from 0x00000000 to 0xFFFFFFFF.

Memory uses Random Access Memory (RAM), meaning access time is independent of the data's location, a key factor for predictable process execution.

While memory provides space for the kernel and running processes, it is volatile and loses data when power is removed, requiring persistent storage such as disks.

Virtual Memory

Processes cannot directly access physical memory; they operate on virtual memory addresses, which 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 distinct physical locations.

Applications see only virtual addresses, and the OS handles all translations, ensuring process isolation and enabling memory sharing without data copying.

Example in C to print a variable's address:

int v = 0;
printf("%p", (void *)&v);

Virtual memory thus protects physical memory access and facilitates shared libraries and kernel data sharing.

Memory Paging

To avoid storing a mapping for every byte, Linux uses paging, managing memory in larger units called pages (typically 4 KB). The page size can be queried with:

$ getconf PAGE_SIZE

which returns 4096, indicating each page holds 4096 bytes.

Paging reduces the number of mapping entries dramatically, as only one entry per page is needed instead of per byte.

Within a page, the lower 12 bits of an address represent the offset, while the higher bits denote the page number. The OS records only the page‑number mappings.

Address translation process
Address translation process

Multi‑Level Page Tables

Linux stores page‑number mappings in page tables. A single linear page table would waste space because many entries correspond to unused virtual pages. Therefore, Linux employs multi‑level page tables, splitting the virtual page number into several parts and using separate tables for each level.

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 (e.g., the low 12 bits). Empty entries indicate unused address ranges, allowing the OS to allocate only the necessary tables and save memory.

Multi‑level page table
Multi‑level page table

Multi‑level page tables thus provide efficient, scalable memory management, enabling Linux to handle large address spaces while keeping translation overhead low.

In summary, Linux manages memory in 4 KB pages, separates virtual and physical addresses, and uses hierarchical page tables to map them efficiently, enhancing process isolation, security, and performance.

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-tablesPaging
MaGe Linux Operations
Written by

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.

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.