Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Virtual Memory & Demand Paging

Lesson 20 of 31 in the free Operating System & Linux Programming notes on Siksha Sarovar, written by Rohit Jangra.

What is Virtual Memory?

Virtual memory lets a process use more address space than the physical RAM available. Pages reside on disk and are brought in only when accessed — demand paging. The illusion of a huge address space is preserved by the MMU and the page table.

Page Table Valid/Invalid Bit

Each page-table entry has a valid bit:

  • 1 → page is in memory; translation is valid.
  • 0 → page is on disk (or illegal). Access triggers a page fault.

Page Fault Sequence

Performance of Demand Paging

Effective access time = (1 - p) memory_access + p page_fault_service_time, where p is the page-fault rate.

If memory access = 100 ns and page-fault service = 8 ms = 8,000,000 ns:

  • p = 0.001 → EAT = 0.999100 + 0.0018,000,000 ≈ 8,099 ns. The system is 80x slower than no paging.
  • p = 0.0001 → EAT ≈ 900 ns. Reducing fault rate by 10x almost recovers performance.

So a low page-fault rate (under 0.001) is essential.

Pure vs Pre-paging

  • Pure demand paging — load only when faulted. Maximum laziness.
  • Pre-paging — bring in expected pages proactively (e.g., on process start).

Copy-On-Write

fork() could be ruinous if it copied every page. Instead, parent and child share pages marked read-only. The first write triggers a page fault, the kernel copies that single page, and both processes continue. This is copy-on-write (COW).

Memory-Mapped Files

mmap() maps a file into the address space. Reading and writing memory then transparently reads/writes the file. Used heavily for shared libraries and inter-process shared memory.

Page Replacement Necessity

When all frames are occupied and a fault occurs, the OS must replace an existing page. The replacement choice critically affects performance — and is the topic of the next lesson.

Locality

Demand paging works because programs exhibit locality of reference:

  • Temporal — recently accessed pages will be accessed again soon.
  • Spatial — addresses near a recent access are likely accessed.

The working set of a process is the set of pages it has touched recently. If working sets fit in memory, fault rate is low.

Summary

  • Virtual memory uses demand paging plus a valid bit to load pages on access.
  • Page faults are expensive — disk is ~80,000x slower than RAM.
  • Copy-on-write and memory-mapped files build on the same machinery.