Download presentation
Presentation is loading. Please wait.
1
CSCI206 - Computer Organization & Programming
Introduction to Virtual Memory zyBook: 12.9
2
Review Memory Map Heap has largest address Code begins near the bottom
0x7FFF FFFF is the last byte in 32-bit MIPS Code begins near the bottom 0x in MIPS 2 GB memory range
3
Problem We commonly run multiple programs on our computers (show top).
We don’t share data between programs! How do separate programs access the same memory map without conflict?
4
Virtual Memory A simulated address space is provided for each process by the operating system. These addresses are called virtual addresses. The operating system maintains a mapping between PID+virtual address to physical address.
5
Virtual Memory (aka logical memory)
6
VM - Basics Each program is given the illusion of owning a large / flat memory space Virtual memory supports a larger address space than is physically available because of spatial / temporal locality we can (usually) move some data to disk (swap) Transparent to the programmer Efficient... with a bit extra little hardware
7
How VM Works Like cache, VM is allocated in chunks called pages
The Page offset is consistent between virtual and physical Common page size is 4KB Translations stored by the OS in the Page Table In the example on the left, we have 4G VM, 1 G physical memory
8
Address range of VM The range of address for VM is somewhat independent of amount of the physical memory VM addresses for a process (program) are contiguous Physical memory addresses do not have to be contiguous
9
What is a page fault? There are more virtual addresses than physical addresses. As a result, contents of some virtual addresses are located on disk If a virtual address is needed by a program and it is currently on disk a page fault occurs The OS allocates physical RAM and move data from disk to RAM (and possibly moves other data from RAM to disk)
10
Page Table (OS) The OS stores the virtual to physical mapping in a table in memory. indexed by virtual page number. the contents are the physical page numbers.
11
Page Table Question How many pages can there be in a 32-bit system with 4 KB pages?
12
Page Table Question How many pages can there be in a 32-bit system with 4 KB pages? 4 KB nees 12 bits as offset Which leaves 20 bits to count pages, which is 2^20 ~= 1 million pages
13
Page Table Question How big is the page table for a 32-bit system with 4 KB pages?
14
Page Table Question How big is the page table for a 32-bit system with 4 KB pages? There are 2^20 entries, each with 19 bits (18 addr bits, 1 valid bit), a total of MB
15
Hardware Issues Program memory accesses use virtual addresses.
Hardware uses physical addresses to access data (RAM). How does hardware (CPU) handle a memory access?
16
Cache with Virtual Addresses?
RAM V to P ? Offset CACHE Index Tag V to P ? Does the cache use virtual addresses or physical addresses?
17
Virtual Memory Caching
All programs have their own virtual address space Therefore, two programs will refer to the same addresses, but expect to find their own data! As a result, we cannot cache using virtual addresses There is no way to tell data from each process apart using only the virtual address However, the virtual to physical translation is on the critical path for every cache access! This needs to be fast, so we create a special cache, called the translation lookaside buffer (TLB), just for caching the page table!
18
TLB Memory access begins with a TLB access to find the physical address, then access the cache. The TLB is flushed on context switches, but cache contents are not!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.