Long Article 104: Memory Management – Virtual Part I: In-Depth Page Table Operations and Virtual Memory Areas (VMA) Analysis

“Virtual memory is the cornerstone of modern operating systems, and VMA is the ‘map’ of the process address space. This article dives deep into x86 page table structures and VMA design principles, comparing Linux implementation details to build a demand-paging, higher-half kernel-mapped industrial-grade virtual memory system.”


The Core Value of Virtual Memory

Virtual memory provides three core capabilities:

  1. Address space isolation: each process has independent 4GB virtual address space
  2. Memory protection: prevents process boundary violations (e.g., user mode accessing kernel)
  3. Memory expansion: supports applications larger than physical memory via swapping

Key components:

  • Page Table: hardware-level address translation mechanism
  • VMA (Virtual Memory Area): software-level address space management

x86 Page Table Structure (32-bit)

Two-level page table structure:

  1. CR3 register: stores page directory base address (physical address)
  2. PDE (Page Directory Entry): indexed by high 10 bits, gets page table base address
  3. PTE (Page Table Entry): indexed by middle 10 bits, gets physical page frame address
  4. Physical address = page frame address + page offset

Key permission bits:

  • P (Present): 0 → triggers Page Fault (#PF)
  • R/W (Read/Write): 0 → read-only page
  • U/S (User/Supervisor): 0 → kernel mode only (Ring 0)
  • G (Global): 1 → prevents TLB flush on process switch
Last modified: 2024年10月26日

Author

Comments

Write a Reply or Comment

Your email address will not be published.