LearnThatStack Ace your next interview
Operating Systems · question
Question 5 of 56

What is virtual memory, and why does each process get its own address space?

beginner
← All Operating Systems questions
Re-explain
Visual ↓

Virtual memory gives each process a private address space, a range of addresses the OS maps onto physical RAM. Your program sees one continuous range starting near zero, even though physical memory is shared and scattered.

The hardware and OS translate every virtual address to a physical one during access. A process can only reach memory it owns, because its map has no entry for anyone else's pages.

That isolation is the main reason for separate address spaces. One process cannot read or corrupt another's data through a stray pointer. It also simplifies your code, since every program can assume the same layout. And because pages not in use can wait on disk, the machine can run programs whose combined footprint exceeds its RAM.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
Guided practice for Operating Systems One question at a time. Answer out loud, get graded, see what you missed.
See it - interactive diagram
Same virtual address, different physical frame
Process A runs alone
Virtual pages
A: page 0x40001
A: page 0x50002
Physical RAM
1Frame 31
holdsA's data
2Frame 12
holdsA's data

A sees two pages side by side. A's map sends them to RAM frames 31 and 12, where the OS found room.

Process B starts
Virtual pages
A: page 0x40001
A: page 0x50002
B: page 0x4000new3
Physical RAM
1Frame 31
holdsA's data
2Frame 12
holdsA's data
3Frame 48new
holdsB's data

B also uses address 0x4000, but B's map sends it to frame 48 and has no entry for A's frames.

B needs another page
Virtual pages
A: page 0x40001
A: page 0x5000changedon disk
B: page 0x40003
B: page 0x7000new2
Physical RAM
1Frame 31
holdsA's data
2Frame 12
holdschangedB's data
3Frame 48
holdsB's data

RAM is full, so the OS moves A's idle page to disk and gives that frame, frame 12, to B.

Both processes use address 0x4000, but each map leads to its own frame, so neither can reach the other's memory.

© LearnThatStack - diagrams may not be republished without permission.

Other questions have diagrams like this too. Sign in to ask for one where it's missing - it's free.

Create a free account
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens How interviewers actually use this question

Likely follow-ups

What you can say

  1. Virtual memory gives each process its own private range of addresses, and the OS maps that range onto physical RAM.
  2. The program sees one continuous range starting near zero, even though the physical memory under it is shared and scattered.
  3. On every access, the hardware and the OS translate the virtual address into a physical one.
  4. The main reason for separate address spaces is isolation. A process's map has no entry for anyone else's pages, so a stray pointer can't read or corrupt them.
  5. It also makes code simpler, because every program can assume the same layout.
  6. Pages not in use can wait on disk, so programs bigger than RAM combined still run, but if they keep needing those pages back, the disk becomes the bottleneck.

Weak answers to avoid

  • Says virtual memory just means swap space Paging to disk is one benefit, not the definition. Lead with per-process address spaces and translation, then mention that idle pages can wait on disk.
  • Lists features but never says why it isolates The question asks why each process gets its own space. Say it first. A process's map has no entry for other processes' pages, so stray writes can't reach them.
  • Thinks the kernel translates every address The MMU does each lookup in hardware, using page tables the OS built. The kernel runs only on a fault. Get this wrong and the TLB follow-up goes badly.
  • Assumes virtual addresses are unique system-wide Two processes can use the same virtual address for different physical pages. That overlap is the point, since each gets the same layout, mapped separately.
Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Operating Systems cheatsheet.

← Back to all Operating Systems questions
Pro · $10/mo

49 of 56 Operating Systems answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime