0% found this document useful (0 votes)
4 views9 pages

Virtual Memory

Virtual memory ensures that processes can only access their own data by mapping virtual addresses to physical addresses in RAM, preventing unauthorized access. This is managed by the operating system and a hardware component called the memory management unit (MMU). Additionally, virtual memory allows for the swapping of unused RAM blocks to external storage, enabling the use of more virtual memory than the physical RAM available.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

Virtual Memory

Virtual memory ensures that processes can only access their own data by mapping virtual addresses to physical addresses in RAM, preventing unauthorized access. This is managed by the operating system and a hardware component called the memory management unit (MMU). Additionally, virtual memory allows for the swapping of unused RAM blocks to external storage, enabling the use of more virtual memory than the physical RAM available.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Virtual Memory

Abstracting from the physical RAM


Memory safety

Let’s assume our two processes from before: a web browser


and a media player app.
Both store data in memory.
What prevents the media player from accessing memory
used by the browser and steal e.g. your banking details?
Virtual memory!
Virtual memory

Goal: no process can access any memory except its own.


Mechanism:
● Each process has its own address space
● Addresses used by user programs are called
virtual addresses
● The OS maps virtual addresses to physical addresses in
RAM
Virtual memory example

Web browser process:


Virtual addresses
0000 … A300

Media player process:


Virtual addresses
0000 … B100

Physical RAM:

0000 … FFFF
Physical addresses
Virtual memory example

Web browser process:

0000 … A300
OS manages the
mapping
Media player process:

0000 … B100

Physical RAM:

0000 … FFFF
Virtual memory – OS + hardware

How does a process know which addresses to use?


● Process requests memory from OS via system call
● OS sets up mapping from virtual to physical addresses in a special
hardware module, the memory management unit (MMU)
● OS returns virtual start address of memory block to the process
So what happens when the CPU executes e.g. Load 1A20?
● The MMU translates virtual 1A20 address into the physical RAM address
● MMU also checks whether the physical address belongs to the current
process (if not, creates interrupt so OS can shut down the process)
Huge virtual memory

RAM is limited.

E.g. 8GB or 16GB may not be enough for code and data of all running processes.

Use virtual memory:

● Save currently unused blocks of RAM to external storage


● When a process tries to access this block, the MMU will raise an interrupt
(“page fault”)
● OS handles the interrupt and loads block back into RAM after storing another block
to external storage to make space (called “swapping” the blocks)

This works well if swapping isn’t too frequent!


Summary

● Virtual memory is important for safety: processes can only


access their own data
● Implemented using combination of hardware (memory
management unit) and software (part of OS)
● Same mechanism can be used to swap unused RAM
blocks to external storage – enabling use of more virtual
memory than physical RAM
EOF

You might also like