What is virtual memory?

Why Interviewers Ask This

This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Operating Systems topics. It also reveals how well you can explain technical ideas to non-experts.

Answer

Virtual memory is a memory management technique that gives each process the illusion of having its own large, contiguous address space — even if physical RAM is smaller. The OS and hardware (MMU) transparently map virtual addresses to physical addresses. Key concepts: (1) Virtual address space: each process has its own (e.g., 0 to 2^64-1 on 64-bit systems). Addresses in the program are virtual; (2) Physical memory (RAM): actual hardware memory installed in the system; (3) Paging: both virtual and physical memory divided into fixed-size blocks. Virtual blocks = pages (typically 4KB). Physical blocks = frames. Page table maps virtual page numbers to physical frame numbers; (4) Page table: per-process data structure. Maps virtual page → physical frame (or "not in RAM — in disk"); (5) Demand paging: pages loaded from disk only when first accessed (not all upfront). Reduces memory usage; (6) Page fault: when CPU accesses a virtual page not currently in RAM — OS loads it from disk (swap space), updating page table; (7) Swap space: disk area used to store evicted pages. Much slower than RAM (milliseconds vs nanoseconds). Benefits: processes can use more memory than physically installed; memory isolation between processes (different page tables); efficient memory sharing (shared libraries map to same physical frames); simplified memory allocation. Address Translation Hardware: MMU (Memory Management Unit) + TLB (Translation Lookaside Buffer — cache of recent page table entries for fast translation).

Common Mistake

Candidates often give textbook answers here. Interviewers are more impressed when you relate the concept to a specific problem you solved in a real Operating Systems project.