Memory & Executables v2.4 Arch Guide

Virtual Memory Architecture, Operating Systems & Loading Dynamics

Module 1

Foundations of Memory Management

Understanding physical memory constraints, virtual memory abstraction, fixed-size chunks, and reference patterns.

Paging Mechanism

Paging provides a non-contiguous virtual address space abstraction. Physical RAM is divided into fixed-size physical frames, and a process's virtual memory is divided into virtual pages of identical size.

  • Eliminates external fragmentation entirely
  • Enables lazy loading and memory protection
  • Simplifies physical memory allocation

VPN, PFN & Offsets

A Virtual Address is split into two components: the Virtual Page Number (VPN) and the Offset. Page alignment ensures lower bits directly specify position within the page.

Offset Bits = log₂(Page Size)
VPN = Virtual Address >> Offset Bits
Offset = Virtual Address & (Page Size - 1)

Locality of Reference

Programs do not access memory uniformly. Memory access patterns display high predictability across time and spatial proximity.

Temporal Locality:

Recently referenced items are likely to be accessed again soon (e.g., loop variables, stack frame).

Spatial Locality:

Items with nearby addresses are likely to be accessed together (e.g., array traversals, sequential instructions).

Virtual Memory to Physical Frame Mapping Abstraction

When a program accesses memory address 0x3A4F with a 4KB page size (12-bit offset = 4096 bytes):

  1. The lower 12 bits (0xA4F) represent the Offset within the page.
  2. The remaining upper bits (0x3) form the Virtual Page Number (VPN).
  3. The Memory Management Unit (MMU) translates VPN 0x3 into a physical frame number (e.g., PFN 0x12).
  4. The final physical memory location is constructed by appending the offset: 0x12A4F.
32-Bit Address Breakdown (4KB Pages)
VPN (Bits 31–12) [20 Bits]
Offset (Bits 11–0) [12 Bits]
Translate via MMU / Page Table ↓ Direct Copy ↓
PFN (Physical Frame Number)
Offset (Unchanged)