Operating systems · core
Virtual memory, paging and thrashing
Each process sees its own address space. The OS splits memory into pages and frames. When RAM is too small, the system can spend its time swapping.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Each process has a virtual address space. The OS and the MMU (hardware) translate virtual addresses to physical addresses.
- Memory is split into fixed-size pages (virtual) and frames (RAM). The page table maps each page to a frame, or marks it as not in RAM.
- Demand paging: a page is loaded only when first used. Unused pages can go to disk (swap or pagefile) to free RAM.
- Page fault: the CPU touches a page that is not in RAM. The OS finds a free frame (or evicts one), reads the page from disk, updates the page table and restarts the instruction. It is a normal event, not a crash.
- The TLB is a small fast cache of recent page table entries, so most translations do not read the page table in memory.
- Virtual memory is not the hard disk. The disk is only the backing store for pages that are out of RAM.
- Thrashing: programs together need more memory than RAM, so the system spends its time moving pages and the CPU waits. Signs: low CPU, high disk, heavy swap (free -h and vmstat 1 show it).
- Adding more swap only makes thrashing last longer. Stop the biggest memory users, run fewer programs, or add RAM.
The red pen
Common traps: mistake → fix
Mistake: Virtual memory is the hard disk
Fix: it is an address space; disk is only the backing store.
Mistake: A page fault is an error
Fix: it is normal and handled by the OS.
Mistake: Low CPU means the server is idle
Fix: with thrashing, the CPU waits for disk.
Mistake: More swap fixes thrashing
Fix: it hides the lack of RAM.
Easy to hard
Questions interviewers ask, easy to hard
- Explain paging and virtual memory.
- What is a page fault and what happens next?
- Why do we need a TLB?
- The lab server becomes very slow during an exam. How do you diagnose it?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.