Session 3: Virtual Memory
Table of Contents
Intro
Session 3 ran on Thursday, 8th October in AT7.14. The session covered an exploration into Virtual Memory, why it’s needed because of problems with Physical Memory, and some talk about Paging. This session was ran by Kacper and Archie.
NOTE: This session wasn’t best-prepared due to us having other commitments (mostly academics), so we do apologise that this content is probably not the best / up to par with previous sessions.
Session Content + Resources
Session Slides (Click Me!) Session slides were made with content generally available on the internet + some content from Operating System Concepts 10th Edition (2018) by A.Silberschatz (especially the nice diagrams).
Physical Memory
CPUs can complete accesses to registers very quickly (usually within one clock cycle), but accesses to RAM often take multiple clock cycles and result in CPU stalling.
This isn’t terrible for multithreaded CPUs which can sidestep this issue, but what if all the threads stall? Or alternatively, what about 60 years ago when the first computers didn’t have the luxury of multithreading?
Von Neumann and others came up with the solution of caching and a memory hierarchy. The idea was to create multiple levels of memory, with more expensive, fast-access memory closer to the processor (e.g. L1, L2 caches) and the slower-access memory like RAM and Disk storage further away. If we then store frequently accessed memory locations and their surroundings (temporal and spatial locality), we can cut down on how many times we need to actually access RAM and cause CPU stalls.
Address Spaces & User Processes
How do user processes actually get to use memory? What tells us where one process’ memory region ‘starts’ and ’ends’? The Operating System, running in kernel mode (needs to use privileged CPU instructions), manages base and limit registers for different processes. These indidcate where a process’ memory block starts (i.e. at the base), and where it ends (at the base + limit).

The base and limit registers should only be modifiable by the Operating System. If any user process was able to edit its own base and limit registers, let alone the base and limit registers of other processes, you could get malicious processes trying to overwrite other memory locations or accessing memory they shouldn’t be.
Some useful-to-know terminology + concepts
- Logical address / Virtual address: an address generated by the CPU
- Phyiscal address: What is seen by the Memory Management Unit (MMU) when it’s talking to physical storage devices
- Logical & Physical addresses get bound together at compile time - i.e. virtual addresses have a mapping to physical addresses!
- Physical Address Space: the set of all physical addresses
- Virtual Address Space: the set of all virtual addresses generated by a program
- The runtime mapping from virtual to physical addresses is done by the hardware device known as the Memory Management Unit (MMU).
- As this is done, the base register ‘becomes’ the relocation register which stores the offset / virtual-to-physical translated version of the base register.

Limitations of Physical Memory
- User processes must occupy contiguous areas of memory
- We can’t divide processes’ memory chunks into smaller pieces to make them fit (technically we can, read the next bullet point); imagine it as the entire process coming as one package.
- Memory fragmentation: ‘gaps’ left in our memory through the loading and unloading of small memory chunks, which then can’t easily be reused for large memory chunks. We then need to split up the large memory chunks into smaller ones and store them in separate gaps, but to then read from them as one we’d have to retrieve all the individual fragments… slows down file reading & processing.
- Security isn’t great; if all of our processes share the same (physical) memory space, it’s possible that a malicious process could find a way to peak into the memory of other processes which may contain private / sensitive information (e.g. bank account info).
- What happens if we run out of physical memory? We don’t have an infinite budget so we can’t just keep buying RAM, especially with the current market prices (thanks AI..)
Introducing Virtual Memory
So, we need something to fix all of those limitations. Luckily, some really smart people came up with Virtual Memory which is the holy grail to solving those issues. The key ideas we’ll focus on are what solves our limitations:
- Uses a concept known as paging to move data between RAM and Disk, effectively extending the size of our memory massively (in fact, it can be said that virtual memory size is infinite, though this is mainly due to a very large virtual address space).
- We effectively treat RAM & Disk like a cache; inactive programs tend to get their memory put away onto the disk and they only get it fetched if we tab back in (i.e. tabbing in and out of a user program).
- Isolates user processes’ memory spaces into their own, secure areas so that we can stop worrying about a malicious process accessing other processes’ memory.
Slightly more detail:
Each program on your computer is given its own, private range of virtual memory addresses. From the program’s view, it thinks that it’s being given the entire address space to use at its disposal (i.e. it thinks it starts at memory location
0).Virtual memory is split into discrete blocks known as pages - the size of these is determined by the CPU and MMU.
The MMU and Operating System provide a mapping from virtual memory addresses into actual physical addresses in your RAM (as said before). These physical addresses are called page frames, so you can think of it as each page maps to its own page frame
(virtual) page --> page frame (physical).Because of this mapping, we can counter memory fragmentation because we can split up a large memory chunk into multiple pages, which go to separate page frames that don’t necessarily have to be next to each other.
Paging
Paging write-up to be done later, sorry for inconvenience!

End of Post
If you have any questions, join our discord and ask away!
42 49 54 53 49 47 20 3C 33 20 59 4F 55
