2 Recall from Tuesday Our solution to fragmentation is to split up a process s address space into smaller chunks. Physical Memory OS Process 3 Process 3 OS: Place Process 3 Process 1 Process 2 Process 3 Process 1 Process 3 Process 2
3 Recall from Tuesday We support virtual addressing by translating addresses at runtime. Base + Bound 0 P 2 We can t achieve this using base and bound registers unless each process s memory is all in one block. 0 N 2-1 P 2 < y/n? N-1 P 1 P 3
4 How can we do both? We want to support translation of virtual addresses to physical addresses on-the-fly. We want to split up each process s address space to use physical memory more efficiently. The solution is paging.
5 Paging Vocabulary For each process, the virtual address space is divided into fixed-size pages. For the system, the physical memory is divided into fixed-size frames. The size of a page is equal to that of a frame. Often 4 KB in practice.
6 Main Idea ANY virtual page can be stored in any available frame. Makes finding an appropriately-sized memory gap very easy they re all the same size. For each process, OS keeps a table mapping each virtual page to physical frame.
7 Main Idea ANY virtual page can be stored in any available frame. Makes finding an appropriately-sized memory gap very easy they re all the same size. Virtual Memory (OS Mapping) Physical Memory Implications for fragmentation? External: goes away. No more awkwardly-sized, unusable gaps. Internal: About the same. Process can always request memory and not use it.
8 Addressing Like we did with caching, we re going to chop up memory addresses into partitions. Virtual addresses: High-order bits: page # Low-order bits: offset within the page Physical addresses: High-order bits: frame # Low-order bits: offset within the frame
9 Example: 32-bit virtual addresses Suppose we have 8-KB (8192-byte) pages. We need enough bits to individually address each byte in the page. How many bits do we need to address 8192 items?
10 Example: 32-bit virtual addresses Suppose we have 8-KB (8192-byte) pages. We need enough bits to individually address each byte in the page. How many bits do we need to address 8192 items? 2 13 = 8192, so we need 13 bits. Lowest 13 bits: offset within page.
11 Example: 32-bit virtual addresses We ll call these bits p. We ll call these bits i. Suppose we have 8-KB (8192-byte) pages. We need enough bits to individually address each byte in the page. How many bits do we need to address 8192 items? 2 13 = 8192, so we need 13 bits. Lowest 13 bits: offset within page. Remaining 19 bits: page number.
12 Address Partitioning Virtual address: We ll call these bits p. We ll call these bits i. OS Page Table For Process Where is this page in physical memory? (In which frame?) Once we ve found the frame, which byte(s) do we want to access? Physical address: We ll call these bits f. We ll (still) call these bits i.
13 Address Translation Page p Logical Address Offset i Page Table V R D Frame Perm Physical Address Physical Memory
14 Page Table One table per process Table entry elements V: valid bit R: referenced bit D: dirty bit Frame: location in phy mem Perm: access permissions PTBR PTSR V R D Frame Perm Table parameters in memory Page table base register Page table size register
15 Address Translation Logical Address Page p Offset i Virtual address = p + i Physical address = f + i V R D Frame Perm First, do a series of checks Physical Address
16 Check if Page p is Within Range Page p Logical Address Offset i PTBR PTSR V R D Frame Perm p < PTSR Physical Address
17 Check if Page Table Entry p is Valid Page p Logical Address Offset i PTBR PTSR V R D Frame Perm V == 1 Physical Address
18 Check if Operation is Permitted Page p Logical Address Offset i PTBR PTSR V R D Frame Perm Perm (op) Physical Address
19 Translate Address Page p Logical Address Offset i PTBR PTSR V R D Frame Perm concat Physical Address
20 Physical Address by Concatenation Logical Address Page p Offset i PTBR PTSR V R D Frame Perm Frame f Physical Address Offset i
21 Sizing the Page Table Page p Logical Address Offset i Number of bits n specifies max size of table, where number of entries = 2 n V R D Frame Perm Number of bits specifies page size Number of bits needed to address physical memory in units of frames
22 Example of Sizing the Page Table Page p: 20 bits Offset i: 12 bits V R D Frame Perm 32 bit virtual addresses, 1 GB physical memory Address partition: 20 bit page number, 12 bit offset
23 How many entries (rows) will there be in this page table? A. 2 12, because that s how many the offset field can address B. 2 20, because that s how many the page field can address C. 2 30, because that s how many we need to address 1 GB D. 2 32, because that s the size of the entire address space
24 Example of Sizing the Page Table Page p: 20 bits Offset i: 12 bits 20 bits to address 2 20 = 1 M entries V R D Frame Perm How big is a frame? 32 bit virtual addresses, 1 GB physical memory Address partition: 20 bit page number, 12 bit offset
25 What will be the frame size, in bytes? A. 2 12, because that s how many bytes the offset field can address B. 2 20, because that s how many bytes the page field can address C. 2 30, because that s how many bytes we need to address 1 GB D. 2 32, because that s the size of the entire address space
26 Example of Sizing the Page Table Page p: 20 bits Offset i: 12 bits 20 bits to address 2 20 = 1 M entries V R D Frame Perm Page size = frame size = 2 12 = 4096 bytes 32 bit virtual addresses, 1 GB physical memory Address partition: 20 bit page number, 12 bit offset
27 How many bits do we need to store the frame number? Page p: 20 bits Offset i: 12 bits 20 bits to address 2 20 = 1 M entries V R D Frame Perm Page size = frame size = 2 12 = 4096 bytes? 32 bit virtual addresses, 1 GB physical memory Address partition: 20 bit page number, 12 bit offset A: 12 B: 18 C: 20 D: 30 E: 32
28 Example of Sizing the Page Table Page p: 20 bits Offset i: 12 bits 20 bits to address 2 20 = 1 M entries 18 bits to address 2 30 /2 12 frames V R D Frame Perm Page size = frame size = 2 12 = 4096 bytes Size of an entry? 32 bit virtual addresses, 1 GB physical memory Address partition: 20 bit page number, 12 bit offset
29 How big is an entry, in bytes? (Round to a power of two bytes.) Page p: 20 bits Offset i: 12 bits 20 bits to address 2 20 = 1 M entries 18 bits to address 2 30 /2 12 frames V R D Frame Perm Page size = frame size = 2 12 = 4096 bytes Size of an entry? 32 bit virtual addresses, 1 GB physical memory Address partition: 20 bit page number, 12 bit offset A: 1 B: 2 C: 4 D: 8 E:16
30 Example of Sizing the Page Table Page p: 20 bits Offset i: 12 bits 20 bits to address 2 20 = 1 M entries 18 bits to address 2 30 /2 12 frames V R D Frame Perm Page size = frame size = 2 12 = 4096 bytes 4 bytes needed to contain 24 ( ) bits Total table size? 32 bit virtual addresses, 1 GB physical memory Address partition: 20 bit page number, 12 bit offset
31 Example of Sizing the Page Table Page p: 20 bits Offset i: 12 bits 20 bits to address 2 20 = 1 M entries 18 bits to address 2 30 /2 12 frames V R D Frame Perm Page size = frame size = 2 12 = 4096 bytes 4 bytes needed to contain 24 ( ) bits Table size = 1 M x 4 = 4 MB 32 bit virtual addresses, 1 GB physical memory Address partition: 20 bit page number, 12 bit offset
32 Concerns 4 MB of bookkeeping for every process? 200 processes -> 800 MB just to store page tables We re going to need a ton of memory just for page tables We need to do a lookup in our page table, which is in memory, every time a process accesses memory. Isn t that slowing down memory by a factor of 2?
33 Multi-Level Page Tables (You re not responsible for this. Take an OS class for the details.) Logical Address 1st-level Page d 2nd-level Page p Offset i V R D Frame Points to (base) frame containing 2nd-level page table V R D Frame concat Reduces memory usage SIGNIFICANTLY: only allocate page table space when we need it. More memory accesses though Physical Address
34 Caching the page table Each lookup costs another memory reference For each reference, additional references required Slows machine down by factor of 2 or more Take advantage of locality Most references are to a small number of pages Keep translations of these in high-speed memory (a cache for page translation)
35 VM Implications Not all pieces need to be in memory Need only piece being referenced Other pieces can be on disk Bring pieces in only when needed Illusion: there is much more memory What s needed to support this idea? A way to identify whether a piece is in memory A way to bring in pieces (from where, to where?) Relocation (which we have)
36 Sample Contents of Page Table Entry Valid Ref Dirty Frame number Prot: rwx Valid: is entry valid (page in physical memory)? Ref: has this page been referenced yet? Dirty: has this page been modified? Frame: what frame is this page in? Protection: what are the allowable operations? read/write/execute
37 Page faults A page fault occurs when we try to access a virtual address that has no corresponding physical address. mechanism for handling a page fault: 1. read in the virtual page from disk Location kept in kernel data structure. 2. store it in a physical memory frame May need to kick something else out. 3. Update PTE with frame num & valid bit = 1 4. Restart instruction that caused the page fault
38 Page Faults are Expensive Disk: 5-6 orders magnitude slower than RAM Very expensive; but if very rare, tolerable Example RAM access time: 100 nsec Disk access time: 10 msec p = page fault probability Effective access time: p 10,000,000 nsec If p = 0.1%, effective access time = 10,100 nsec!
39 Handing faults from disk seems very expensive. How can we get away with this in practice? A. We have lots of memory, and it isn t usually full. B. We use special hardware to speed things up. C. We tend to use the same pages over and over. D. This is too common & expensive to do in practice!
40 Principle of Locality Not all pieces referenced uniformly over time Make sure most referenced pieces in memory If not, thrashing: constant fetching of pieces References cluster in time/space Will be to same or neighboring areas Allows prediction based on past
41 Page Replacement Goal: remove page(s) not exhibiting locality Page replacement is about which page(s) to remove when to remove them How to do it in the cheapest way possible Least amount of additional hardware Least amount of software overhead
42 Basic Page Replacement Algorithms FIFO: select page that is oldest Simple: use frame ordering Doesn t perform very well (oldest may be popular) OPT: select page to be used furthest in future Optimal, but requires future knowledge Establishes best case, good for comparisons LRU: select page that was least recently used Predict future based on past; works given locality Costly: time-stamp pages each access, find least Goal: minimize replacements (maximize locality)
43 Summary We give each process a virtual address space to simplify process execution. OS maintains mapping of virtual address to physical memory locations in a page table. One page table for every process Provides the abstraction of very large memory: not all pages need be resident in memory Bring pages in from disk on demand
44 Worksheet example Step through the stream of Virtual Addresses from the CPU: Show how the bits of each address are used for each Virtual Address & its Physical Address mapping Translate each VA to its PA using the appropriate PTE Update PTEs appropriately as you go Show the history of the contents of RAM as these addresses are accessed Which virtual page of which process does it store Implement a FIFO page replacement policy for RAM 44
Virtual Memory 1 To do q Segmentation q Paging q A hybrid system Address spaces and multiple processes IBM OS/360 Split memory in n parts (possible!= sizes) A process per partition Program Code Heap Operating
Recall: Address Space Map 13: Memory Management Biggest Virtual Address Stack (Space for local variables etc. For each nested procedure call) Sometimes Reserved for OS Stack Pointer Last Modified: 6/21/2004
The Virtual Memory Abstraction Memory Management Physical Memory Unprotected address space Limited size Shared physical frames Easy to share data Virtual Memory Programs are isolated Arbitrary size All
Virtual Memory Today Segmentation Paging A good, if common example Virtual memory system Goals Transparency Programs should not know that memory is virtualized; the OS +HW multiplex memory among processes
Lecture 1: Demand Paging CSE 10: Principles of Operating Systems Alex C. Snoeren HW 3 Due 11/9 Complete Address Translation We started this topic with the high-level problem of translating virtual addresses
Virtual Memory 1 Chapter 8 Characteristics of Paging and Segmentation Memory references are dynamically translated into physical addresses at run time E.g., process may be swapped in and out of main memory
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology November 9, 2015
ECE468 Computer Organization and Architecture Virtual Memory ECE468 vm.1 Review: The Principle of Locality Probability of reference 0 Address Space 2 The Principle of Locality: Program access a relatively
Memory Allocation Copyright : University of Illinois CS 241 Staff 1 Recap: Virtual Addresses A virtual address is a memory address that a process uses to access its own memory Virtual address actual physical
ECE468 Computer Organization and Architecture Virtual Memory If I can see it and I can touch it, it s real. If I can t see it but I can touch it, it s invisible. If I can see it but I can t touch it, it
Memory Objectives Master the concepts of hierarchical memory organization. Understand how each level of memory contributes to system performance, and how the performance is measured. Master the concepts
Paging algorithms CS 241 February 10, 2012 Copyright : University of Illinois CS 241 Staff 1 Announcements MP2 due Tuesday Fabulous Prizes Wednesday! 2 Paging On heavily-loaded systems, memory can fill
CSC400 - Operating Systems 10: Virtual Memory Management J. Sumey Introduction virtual memory management: concerned with the actual management operations of a virtual memory system fetch strategies: when
Constructive Computer Architecture Virtual Memory: From Address Translation to Demand Paging Arvind Computer Science & Artificial Intelligence Lab. Massachusetts Institute of Technology November 12, 2014
CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8) Important from last time We re trying to build efficient virtual address spaces Why?? Virtual / physical translation is done by HW and
Computer Systems Virtual Memory Han, Hwansoo A System Using Physical Addressing CPU Physical address (PA) 4 Main memory : : 2: 3: 4: 5: 6: 7: 8:... M-: Data word Used in simple systems like embedded microcontrollers
Virtual Memory Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. L16-1 Reminder: Operating Systems Goals of OS: Protection and privacy: Processes cannot access each other s data Abstraction:
Operating System Principles: Memory Management Swapping, Paging, and Virtual Memory Operating Systems Peter Reiher Page 1 Outline Swapping Paging Virtual memory Page 2 Swapping What if we don t have enough
Memory Management To provide a detailed description of various ways of organizing memory hardware To discuss various memory-management techniques, including paging and segmentation To provide a detailed
Virtual Memory 11/8/16 (election day) Vote! Recall: the job of the OS The OS is an interface layer between a user s programs and hardware. Program Operating System Computer Hardware It provides an abstract
CSCI-GA.2250-001 Operating Systems Lecture 6: Memory Management II Hubertus Franke firstname.lastname@example.org What is the problem? Not enough memory Have enough memory is not possible with current technology
CS 153 Design of Operating Systems Winter 2016 Lecture 16: Memory Management and Paging Announcement Homework 2 is out To be posted on ilearn today Due in a week (the end of Feb 19 th ). 2 Recap: Fixed
CS161 Design and Architecture of Computer Systems Cache $$$$$ Memory Systems! How can we supply the CPU with enough data to keep it busy?! We will focus on memory issues,! which are frequently bottlenecks
Address spaces and memory management Review of processes Process = one or more threads in an address space Thread = stream of executing instructions Address space = memory space used by threads Address
Virtual Memory CS 3410 Computer System Organization & Programming These slides are the product of many rounds of teaching CS 3410 by Professors Weatherspoon, Bala, Bracy, and Sirer. Where are we now and
Memory Management: Virtual Memory and Paging Operating Systems Peter Reiher Page 1 Outline Paging Swapping and demand paging Virtual memory Page 2 Paging What is paging? What problem does it solve? How
CS450/550 Operating Systems Lecture 4 memory Palden Lama Department of Computer Science CS450/550 Memory.1 Review: Summary of Chapter 3 Deadlocks and its modeling Deadlock detection Deadlock recovery Deadlock
CS 61C: Great Ideas in Computer Architecture Virtual II Guest Lecturer: Justin Hsia Agenda Review of Last Lecture Goals of Virtual Page Tables Translation Lookaside Buffer (TLB) Administrivia VM Performance
Chapter 5 Large and Fast: Exploiting Memory Hierarchy Memory Technology Static RAM (SRAM) 0.5ns 2.5ns, $2000 $5000 per GB Dynamic RAM (DRAM) 50ns 70ns, $20 $75 per GB Magnetic disk 5ms 20ms, $0.20 $2 per
Pipelined processors and Hazards Two options Processor HLL Compiler ALU LU Output Program Control unit 1. Either the control unit can be smart, i,e. it can delay instruction phases to avoid hazards. Processor
20-EECE-4029 Operating Systems Spring, 2013 John Franco Second Exam name: Question 1: Translation Look-aside Buffer (a) Describe the TLB. Include its location, why it is located there, its contents, and
CSE 120 Principles of Operating Systems Fall 2016 Lecture 11: Page Replacement Geoffrey M. Voelker Administrivia Lab time This week: Thu 4pm, Sat 2pm Next week: Tue, Wed At Washington University in St.
Swapping Jin-Soo Kim (email@example.com) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Swapping Support processes when not enough physical memory User program should be independent
Virtual to physical address translation Virtual memory with paging Page table per process Page table entry includes present bit frame number modify bit flags for protection and sharing. Page tables can
CS 61C: Great Ideas in Computer Architecture Virtual Memory Instructor: Justin Hsia 7/30/2012 Summer 2012 Lecture #24 1 Review of Last Lecture (1/2) Multiple instruction issue increases max speedup, but
LECTURE 12 Virtual Memory VIRTUAL MEMORY Just as a cache can provide fast, easy access to recently-used code and data, main memory acts as a cache for magnetic disk. The mechanism by which this is accomplished
Address Translation Jinkyu Jeong (firstname.lastname@example.org) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Today s Topics How to reduce the size of page tables? How to reduce the time for
Locality A principle that makes having a memory hierarchy a good idea If an item is referenced, temporal locality: it will tend to be referenced again soon spatial locality: nearby items will tend to be
Virtual Memory 2 To do q Handling bigger address spaces q Speeding translation Considerations with page tables Two key issues with page tables Mapping must be fast Done on every memory reference, at least
Memory Management Design, Spring 2011 Department of Computer Science Rutgers Sakai: 01:198:416 Sp11 (https://sakai.rutgers.edu) Memory Management Goals of Memory Management Convenient abstraction for programming
Virtual Memory: Concepts 5-23: Introduction to Computer Systems 7 th Lecture, March 2, 27 Instructors: Franz Franchetti & Seth Copen Goldstein Hmmm, How Does This Work?! Process Process 2 Process n Solution:
Lecture #15: Translation, protection, sharing Review -- 1 min Goals of virtual memory: protection relocation sharing illusion of infinite memory minimal overhead o space o time Last time: we ended with
Our main questions! How is protection enforced?! How are processes relocated?! How is ory partitioned? Simple idea 1: load-time linking! Link as usual, but keep the list of references! At load time, determine
Virtual memory Operations and policies Chapters 3.4. 3.6 Week 2: 17.9.2009 Tiina Niklander 1 Policies and methods Fetch policy (Noutopolitiikka) When to load page to memory? Placement policy (Sijoituspolitiikka
Review Address Segmentation " CS162 Operating Systems and Systems Programming Lecture 10 Caches and TLBs" February 23, 2011! Ion Stoica! http//inst.eecs.berkeley.edu/~cs162! 1111 0000" 1110 000" Seg #"
MEMORY MANAGEMENT Requirements: Relocation (to different memory areas) Protection (run time, usually implemented together with relocation) Sharing (and also protection) Logical organization Physical organization
Memory Management Dr. Yingwu Zhu Big picture Main memory is a resource A process/thread is being executing, the instructions & data must be in memory Assumption: Main memory is super big to hold a program
CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring 2003 Lecture 15: Caching: Demand Paged Virtual Memory 15.0 Main Points: Concept of paging to disk Replacement policies
Virtual Memory CSCI 315 Operating Systems Design Department of Computer Science Notice: The slides for this lecture have been largely based on those from an earlier edition of the course text Operating
Memory Management 1. Describe the sequence of instruction-execution life cycle? A typical instruction-execution life cycle: Fetches (load) an instruction from specific memory address. Decode the instruction
Virtual Memory Design and Implementation To do q Page replacement algorithms q Design and implementation issues q Next: Last on virtualization VMMs Loading pages When should the OS load pages? On demand
1 Memory Management Address Binding The normal procedures is to select one of the processes in the input queue and to load that process into memory. As the process executed, it accesses instructions and
UNIT-III STORAGE MANAGEMENT Memory Management: Background In general, to rum a program, it must be brought into memory. Input queue collection of processes on the disk that are waiting to be brought into
This Unit: CSE 560 Computer Systems Architecture App App App System software Mem I/O The operating system () A super-application Hardware support for an Page tables and address translation s and hierarchy
Chapter 5 Large and Fast: Exploiting Memory Hierarchy Processor-Memory Performance Gap 10000 µproc 55%/year (2X/1.5yr) Performance 1000 100 10 1 1980 1983 1986 1989 Moore s Law Processor-Memory Performance
Chapter 8 Main Memory 8.1, 8.2, 8.3, 8.4, 8.5 Chapter 9 Virtual memory 9.1, 9.2, 9.3 https://www.akkadia.org/drepper/cpumemory.pdf Images from Silberschatz Pacific University 1 How does the OS manage memory?
Virtual Memory I wish we were still doing NAND gates Study Chapters 7.4-7.8 Finally! A lecture on something I understand PAGE FAULTS! L23 Virtual Memory 1 You can never be too rich, too good looking, or
Memory Hierarchy Mehran Rezaei What types of memory do we have? Registers Cache (Static RAM) Main Memory (Dynamic RAM) Disk (Magnetic Disk) Option : Build It Out of Fast SRAM About 5- ns access Decoders
Chapter 5 Large and Fast: Exploiting Memory Hierarchy Processor-Memory Performance Gap 10000 µproc 55%/year (2X/1.5yr) Performance 1000 100 10 1 1980 1983 1986 1989 Moore s Law Processor-Memory Performance
CS162 Operating Systems and Systems Programming Lecture 14 Caching (Finished), Demand Paging October 11 th, 2017 Neeraja J. Yadwadkar http://cs162.eecs.berkeley.edu Recall: Caching Concept Cache: a repository
Virtual Memory L21 Virtual Memory 1 Lessons from History There is only one mistake that can be made in computer design that is difficult to recover from not having enough address bits for memory addressing
Memory Management Where we re going Chapter 3 Memory Management: Virtual Memory Understanding Operating Systems, Fourth Edition Disadvantages of early schemes: Required storing entire program in memory
Operating Systems Memory Management Mathieu Delalandre University of Tours, Tours city, France email@example.com 1 Operating Systems Memory Management 1. Introduction 2. Contiguous memory
CS 5523 Operating Systems: Memory Management Instructor: Dr Tongping Liu Thank Dr Dakai Zhu, Dr Palden Lama, and Dr Tim Richards (UMASS) for providing their slides Outline Simple memory management: swap
Address Translation Tore Larsen Material developed by: Kai Li, Princeton University Topics Virtual memory Virtualization Protection Address translation Base and bound Segmentation Paging Translation look-ahead
Operating System 1 (ECS-501) Unit- IV Memory Management 1.1 Bare Machine: 1.1.1 Introduction: It has the ability to recover the operating system of a machine to the identical state it was at a given point
Virtual Memory: Mechanisms CS439: Principles of Computer Systems February 28, 2018 Last Time Physical addresses in physical memory Virtual/logical addresses in process address space Relocation Algorithms