Back to the 2017 paper

Module 4: Memory Organization

201714m

Explain the concept of virtual memory with the help of a diagram. Explain how virtual address is mapped to actual physical address.

Worked SolutionAI Assisted

Virtual Memory Concept

Virtual memory is a memory management technique that gives program illusion of large contiguous main memory (e.g. 44 GB) while physically only part resides in RAM; remainder kept on secondary storage (disk). Address generated by CPU (virtual/logical) is translated to physical via MMU.

CPU generates              MMU + Page Table + TLB                Main Memory / Disk
Virtual Address  ----->   Translation  -----> Physical Address ---> RAM (if present)
  32-bit                    VPN -> PFN       32-bit              else Page Fault -> Disk
  • Virtual address space >>>> Physical address space (e.g. 2322^{32} virtual vs 2282^{28} physical).
  • Transparent to programmer, allows multiprogramming, protection, demand paging.
  • Uses locality – only active pages kept in RAM.

Diagram: Paged Virtual Memory Mapping

Virtual Address (32b)
+----------------------+------------------+
| Virtual Page Number  | Page Offset      |
|  VPN (20b)           |  OFFSET (12b)    |  -> 4KB pages
+-----------+----------+-----+------------+
            |                  |
            v                  |
     +--------------+          |
     | Page Table   | TLB      |
     | (in RAM)     | cache    |
     | VPN -> PFN   |          |
     +------+-------+          |
            |                  |
            v                  v
Physical Address (32b)
+----------------------+------------------+
| Physical Frame Number| Offset           |
|  PFN (20b)           | (12b same)       |
+----------------------+------------------+

RAM: [Frame 0][Frame 1]...[Frame N]   Disk: swap space with all pages

Virtual to Physical Mapping Steps (Paging)

Assume page size 44 KB =212=2^{12} B ⇒\Rightarrow offset 1212 bits, VPN 2020 bits for 3232-bit virtual.

  1. CPU generates virtual address VA=(VPN,offset)VA = (VPN, offset).
  2. MMU looks up TLB (Translation Lookaside Buffer) – cache of page table.
    • TLB hit: get PFN immediately.
    • TLB miss: access page table in RAM (pointed by Page Table Base Register - PTBR). May be multi-level (e.g. 2-level for 32-bit).
  3. Page Table Entry (PTE) contains: PFN, valid bit, dirty, protection (R/W/X), referenced.
    • If valid=1: PA=PFN×PAGE_SIZE+offsetPA = PFN \times PAGE\_SIZE + offset (concatenation).
    • If valid=0: Page Fault → trap to OS. OS loads required page from disk to free frame (using replacement e.g. LRU), updates PTE, restarts instruction.
  4. Physical address sent to cache/memory.

Example: VA=0x12345678VA=0x12345678, page 44 KB ⇒\Rightarrow VPN=0x123450x12345, offset=0x6780x678; page table maps VPN 0x12345→PFN0x00ABC0x12345 \rightarrow PFN 0x00ABC ⇒\Rightarrow PA=0x00ABC678PA=0x00ABC678.

Segmentation + Paging: Sometimes VA = segment + offset; segment table → page table. But pure paging described above is most common (x86, ARM).

Advantages: Large logical space, protection/isolation, sharing, efficient multiprogramming, demand loading.

Overhead: Translation time (mitigated by TLB >95%>95\% hit), page fault handling, fragmentation (internal).

Similar questions

Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.