Day 1: Understanding Two-Level Paging

A deep dive into memory management and how a 32-bit OS splits virtual addresses into a first-level index, a second-level index, and an offset.

Scenario for Simulation

We are simulating a memory management scenario in a 32-bit system that uses two-level paging. This setup will help illustrate how logical (virtual) addresses map to physical addresses.

32-Bit Virtual Address

A 32-bit virtual address is divided into three parts:

  • 10 bits for the first-level page table index
  • 10 bits for the second-level page table index
  • 12 bits for the offset within the page

This means each page is 4 KB in size (212 bytes). Since we need 10 bits for each level of indexing, each level has 1024 entries (210 entries).

Physical Memory

The system’s physical memory is represented as a collection of frames, each also being 4 KB in size.

Objective

  • Translate a virtual address to its corresponding physical address.
  • Simulate two processes sharing one physical frame:
    • Process A: Read-only access
    • Process B: Read-write access

Code Simulation

In my GitHub repo, I’ve included a simple C simulation demonstrating how address translation happens with a two-level page table. Feel free to check it out and experiment!