1 2 Virtual Memory Concept • A mechanism for hiding the details of how much physical memory exists and how it’s being shared • Allows the OS to EE 457 Unit 7c – Efficiently share the physical memory between several _______ ___________ and provide ___________ against each other – Remove the need of the programmer to know _______________ is physically present and/or give the illusion of ____________ physical Virtual Memory memory than is present • Use MM as a cache for multiple programs and their data as they run using ________________________ as the home location 3 4 Memory Hierarchy & Caching Virtual Memory Motivation • Lower levels act as a cache for upper levels • Virtual memory is largely discussed in operating systems courses – We will focus on HW support for VM • Magnetic hard drive consists of Registers – Double sided surfaces/platters (with R/W head) L1 Cache – Each platter is divided into concentric tracks of small sectors that each ~ 1ns L1/L2 is a store several thousand bits “cache” for L2 Cache main memory Read/Write Head 0 • Seek Time: Time needed to ____ ms ~ 10ns Read/Write Head 1 position the read-head above Surfaces … the proper track Main Memory • Rotational delay: Time needed ____ ms Virtual memory Read/Write Head 7 ~ 100 ns to bring the right sector under Sector 0 provides each the read-head process its own Disk / Secondary Storage • Depends on rotation Track 0 Sector 1 speed (e.g. 5400 RPM) ~1-10 ms address space in Track 1 • Transfer Time: 0.1 ms secondary storage • Disk Controller Overhead: + 2.0 ms and uses main ~___ ms Sector 2 memory as a cache
5 6 Address Spaces Virtual Address Spaces Program/Process 0 • Physical address spaces • Virtual address spaces are 1 1,2,3,… Program/Process corresponds to the actual system broken into blocks called 2 1,2,3,… 3 0xffff ffff address bus width and range (i.e. ____________ 0 unused Mem 0xffff ffff 0xffff ffff main memory and I/O) 1 … • Depending on the Not Mem 2 used • Each process/program runs in its program, much of the 3 0 I/O 0xbfffffff 0 1 own private “virtual” address virtual address space will I/O 1 2 I/O 0x80000000 2 space _____________ unused 0 unused Not – Virtual address space can be larger • All ______ pages are 1 … used Mem. 2 (or smaller) than physical memory “housed” in secondary 3 0x3fffffff Mem. 0 – Virtual address spaces are protected storage (hard drive) 1 0x0000000 Mem. 0 from each other 2 0x00000000 0x00000000 3 Fictitious Virtual unused Address Spaces 32-bit _________ 32-bit ____________ … Address Space w/ Address Spaces Secondary Used/Unused Blocks in only 1 GB of Mem ( > 1GB Mem) Storage Virtual Address Space 7 8 Physical Address Space Physical Memory Usage • Physical memory is broken • HW & the OS will _____ the 0 0 1 1 into page-size blocks called virtual addresses used by the 2 2 0xffffffff 0xffffffff _________ 3 program to the physical 3 I/O I/O 0 0 and unused and unused ______________ 1 address where that page 1 un- un- … … used 2 used 2 resides area area • Multiple programs are run 3 3 0 0 0 0 0x3fffffff 0x3fffffff frame 1 frame 1 concurrently and their • If an attempt is made to 1 1 2 1 2 2 2 pages (code & data) need access a page that is not in unused 0 unused 0 0 … 3 unused unused to reside in physical physical memory, a 1 1 … 2 … 2 2 memory __________________ is 0 3 3 0 0 declared and the ____ brings • Physical memory acts as a frame 0x00000000 frame 0x00000000 1 1 in the page to physical 2 2 _____ for pages from the Physical 1GB Physical 3 3 memory (possibly evicting secondary storage as each Memory and Memory and unused unused Secondary Secondary Address Space 32-bit Address … another page) … Storage Storage program executes Space Fictitious Virtual Fictitious Virtual Address Spaces Address Spaces
9 10 VM Design Implications Page Size and Address Translation • Usually pages are _________ in size to amortize the large access time • SLOW secondary storage access on page faults (10 ms) • Example: 32-bit virtual & physical address, 1 GB physical memory, – Implies page size should be ___________ (i.e. once we’ve taken 4 KB pages the time to find data on disk, make it worthwhile by accessing a • Virtual page number to physical page frame translation performed by HW reasonably large amount of data) unit = MMU (Mem. Management Unit) – Implies the placement of pages in main memory should be __________ to reduce ___________ and maximize page hit rates 31 __ __ 0 Virtual Address Virtual Page Number Offset within page – Implies a “page fault” is going to take so much time to even access the data that we can handle them in _______ (via an __ 12 exception) rather than using HW like typical cache misses Copied Translation – Implies eviction algorithms like ______ can be used since Process reducing page miss rates will pay off greatly __ 31 30 29 __ __ 0 – Implies _________ (write-______ would be too expensive) Physical Address 00 ____________________ Offset within page 11 12 Address Translation Issues Analogy for Page Tables • A virtual page with 20-bit VPN can be sitting anywhere in the • Suppose we want to build a caller-ID mechanism for your 256K = 2 18 page frames in physical memory contacts on your cell phone – TAG = 20 + 1 = 21 bits, _________ comparators – Let us assume 1000 contacts represented by a 3-digit integer (0-999) by the cell phone (this ID can be used to look up their names) • This is impractical – We want to use a simple Look-Up Table (LUT) to translate phone numbers • Instead, most systems implement full associativity using a to contact ID’s, how shall we organize/index our LUT look-up table = PAGE TABLE 1 LUT indexed w/ 2 Sorted LUT indexed 3 LUT indexed w/ all contact ID w/ used phone #’s possible phone #’s Frame n 000 213-745-9823 213-730-2198 436 000-000-0000 null Virtual Address 001 626-454-9985 213-745-9823 000 .. VPN offset … 002 818-329-1980 323-823-7104 999 213-745-9823 000 Page Frame # … … … Frame 2 = V Tag (VPN) M 0 999 323-823-7104 818-329-1980 002 999-999-9999 null = V Tag (VPN) M 1 Does / Doesn’t Work Does / Doesn’t Work Does / Doesn’t Work Frame 1 = V Tag (VPN) M 2 = … = V Tag (VPN) M n Frame 0
13 14 Analogy for Page Tables Analogy for Page Tables • Can we use the table indexed using all possible phone numbers (because it only • Could extend to 3 levels if desired requires 1 access) but somehow reduce the size especially since much of it is unused? 1 st Level = Area code and pointers to 2 nd level tables – Do you have friends from every ________? Likely contacts are clustered in only a few. 2 nd Level = First 3-digits of local phone and pointers to 3 rd level tables • – 3 rd Level = Contact ID’s • Use a 2-level organization – 1 st level LUT is indexed on __________ and contains pointers to 2 nd level tables – 1 st Level Index = 2 nd Level Index = 3 rd Level Index = 2 nd level LUT’s indexed on __________ numbers and contains contact ID entries – Area Code Local Phone # Local Phone # 2 nd Level Index = 000 null 000 null ______________ Area Code 745 9823 000 1 st Level Index = LUT indexed w/ all 000 null 999 null 999 null If only 2 used possible phone #’s _________ … 000-0000 213 213-745 area codes 213 ____ Area Code Table Table then only ____ … Table 000-000-0000 null 000 null 999-9999 ___________ 323 .. … 000 null 000 null entries rather … 213-745-9823 000 ____ 823 7104 999 000-0000 than 10 10 … … ____ 999 null 999 null entries 999-999-9999 null ___ Table 323 323-823 … 999-9999 Table Table 15 16 Analogy for Page Tables Page Tables • If we add a friend from area code 408 we would have to add a second and • Page table is built by the OS and maintained in the _______________ at some chosen place by the OS third level table for just this entry – Allows virtual memory page placement to be fully associative in physical memory – One page table per process and indexed on virtual address – PTBR is a ____________ register pointing to the start address of currently executing process’ page table 1 st Level Index = 2 nd Level Index = 3 rd Level Index = Area Code Local Phone # Local Phone # Memory CPU Valid / PTBR = Page Table Base Reg. Page Frame Number Present 000 null 000 null Area Code 745 9823 000 31 12 11 0 000 null 999 null 999 null … Virtual Page Number Offset w/in page VA 213 213-745 213 20 Table Table … … 323 000 null 000 null … 18 823 7104 999 Page Table Size 31 12 11 0 = ____ entries * ___ bits 999 null 999 null = approx. _______________ 323 323-823 00 Phys. Frame # Offset w/in page PA Table Table
Recommend
More recommend