Course contentsShow
← Computer Science
Lesson 1349 of 2,87231. Memory ManagementFree lesson

Shared Memory via Virtual Memory

How multiple processes can map the same physical pages into their virtual address spaces for efficient inter-process communication.

Shared Memory via Virtual Memory

You'll learn how multiple processes can efficiently communicate by mapping the same physical memory pages into their separate virtual address spaces.

The Core Idea

Normally, each process has its own isolated virtual address space — Process A can't access Process B's memory. But what if two processes need to share data efficiently? Virtual memory makes this possible without breaking isolation.

Here's how: the operating system can map the same physical memory pages into different virtual addresses in multiple processes. When Process A writes to its virtual address 0x5000, and Process B reads from its virtual address 0x8000, they're actually touching the same physical page — they just see it through different "windows."

The Analogy

Think of two apartments (processes) in different buildings. Normally, they're completely separate. But imagine both apartments have a door that opens into a shared storage room (the physical page). Each apartment accesses it from a different location in their floor plan, but it's the same room. Items placed there by one tenant are immediately visible to the other.

Why This Matters

Inter-Process Communication (IPC): Instead of slow mechanisms like copying data through pipes or message queues, shared memory lets processes communicate at memory speed — no kernel involvement for each read/write.

Efficiency: A large data structure can be shared without duplication. Both processes' page tables simply point to the same physical frames.

Flexibility: The OS controls which pages are shared, maintaining security while enabling cooperation.

Key Takeaway: Virtual memory enables efficient shared memory by letting multiple processes map the same physical pages into their own virtual address spaces, providing fast IPC while preserving address space isolation.