1 Virtual Memory and Address Translation. 2 Review Program addresses are virtual addresses.  Relative offset of program regions can not change during.

Slides:



Advertisements
Similar presentations
Memory.
Advertisements

Operating Systems Lecture 10 Issues in Paging and Virtual Memory Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard. Zhiqing.
Operating Systems Lecture Notes Memory Management Matthew Dailey Some material © Silberschatz, Galvin, and Gagne, 2002.
OS Fall’02 Virtual Memory Operating Systems Fall 2002.
CS 153 Design of Operating Systems Spring 2015
CS 153 Design of Operating Systems Spring 2015
Memory/Storage Architecture Lab Computer Architecture Virtual Memory.
Paging and Virtual Memory. Memory management: Review  Fixed partitioning, dynamic partitioning  Problems Internal/external fragmentation A process can.
Memory Management.
Chapter 3.2 : Virtual Memory
1 Chapter 8 Virtual Memory Virtual memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.
Chapter 7: Main Memory CS 170, Fall Memory Management Background Swapping Contiguous Memory Allocation Paging Structure of the Page Table Segmentation.
Virtual Memory I Chapter 8.
03/22/2004CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
A. Frank - P. Weisberg Operating Systems Simple/Basic Paging.
Silberschatz, Galvin and Gagne  Operating System Concepts Segmentation Memory-management scheme that supports user view of memory. A program.
Main Memory. Background Program must be brought (from disk) into memory and placed within a process for it to be run Main memory and registers are only.
03/17/2008CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying the textbook.
1 Tuesday, July 04, 2006 "Programs expand to fill the memory available to hold them." - Modified Parkinson’s Law.
Chapter 8: Main Memory.
Chapter 8: Main Memory. 8.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 8: Memory Management Background Swapping Contiguous.
Chapter 8 Memory Management Dr. Yingwu Zhu. Outline Background Basic Concepts Memory Allocation.
8.4 paging Paging is a memory-management scheme that permits the physical address space of a process to be non-contiguous. The basic method for implementation.
Cosc 2150: Computer Organization Chapter 6, Part 2 Virtual Memory.
1 Chapter 3.2 : Virtual Memory What is virtual memory? What is virtual memory? Virtual memory management schemes Virtual memory management schemes Paging.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming  To allocate scarce memory resources.
Chapter 8 – Main Memory (Pgs ). Overview  Everything to do with memory is complicated by the fact that more than 1 program can be in memory.
Computer Architecture and Operating Systems CS 3230: Operating System Section Lecture OS-8 Memory Management (2) Department of Computer Science and Software.
© 2004, D. J. Foreman 1 Virtual Memory. © 2004, D. J. Foreman 2 Objectives  Avoid copy/restore entire address space  Avoid unusable holes in memory.
1 Address Translation Memory Allocation –Linked lists –Bit maps Options for managing memory –Base and Bound –Segmentation –Paging Paged page tables Inverted.
1 Memory Management (b). 2 Paging  Logical address space of a process can be noncontiguous; process is allocated physical memory whenever the latter.
By Teacher Asma Aleisa Year 1433 H.   Goals of memory management  To provide a convenient abstraction for programming.  To allocate scarce memory.
Virtual Memory 1 1.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
Operating Systems Unit 7: – Virtual Memory organization Operating Systems.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Page Table Implementation. Readings r Silbershatz et al:
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
Lectures 8 & 9 Virtual Memory - Paging & Segmentation System Design.
8.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Fragmentation External Fragmentation – total memory space exists to satisfy.
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”
CS203 – Advanced Computer Architecture Virtual Memory.
Chapter 7: Main Memory CS 170, Fall Program Execution & Memory Management Program execution Swapping Contiguous Memory Allocation Paging Structure.
W4118 Operating Systems Instructor: Junfeng Yang.
CS161 – Design and Architecture of Computer
Memory.
Memory COMPUTER ARCHITECTURE
CS161 – Design and Architecture of Computer
CSE 120 Principles of Operating
CS703 - Advanced Operating Systems
Chapter 8: Main Memory.
Operating System Concepts
Lecture 14 Virtual Memory and the Alpha Memory Hierarchy
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 8 11/24/2018.
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 12/1/2018.
Memory Management-I 1.
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
Virtual Memory Overcoming main memory size limitation
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Memory Management Lectures notes from the text supplement by Siberschatz and Galvin Modified by B.Ramamurthy Chapter 9 4/5/2019.
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Paging and Segmentation
CS703 - Advanced Operating Systems
Virtual Memory Use main memory as a “cache” for secondary (disk) storage Managed jointly by CPU hardware and the operating system (OS) Programs share main.
Virtual Memory 1 1.
Presentation transcript:

1 Virtual Memory and Address Translation

2 Review Program addresses are virtual addresses.  Relative offset of program regions can not change during program execution. E.g., heap can not move further from code.  Virtual addresses == physical address inconvenient.  Program location is compiled into the program. A single offset register allows the OS to place a process’ virtual address space anywhere in physical memory.  Virtual address space must be smaller than physical.  Program is swapped out of old location and swapped into new. Segmentation creates external fragmentation and requires large regions of contiguous physical memory.  We look to fixed sized units, memory pages, to solve the problem.

3 Virtual Memory Concept Key problem: How can one support programs that require more memory than is physically available?  How can we support programs that do not use all of their memory at once? Hide physical size of memory from users  Memory is a “large” virtual address space of 2 n bytes  Only portions of VAS are in physical memory at any one time (increase memory utilization). Issues  Placement strategies  Where to place programs in physical memory  Replacement strategies  What to do when there exist more processes than can fit in memory  Load control strategies  Determining how many processes can be in memory at one time 0 2 n -1 Program P’s VAS

4 Realizing Virtual Memory Paging Physical memory partitioned into equal sized page frames  Page frames avoid external fragmentation. (0,0) (f MAX -1,o MAX -1) PA: fo (f,o)(f,o) f o Physical Memory 1 log 2 o max log 2 (f max  o max ) A memory address is a pair (f, o) f — frame number (f max frames) o — frame offset (o max bytes/frames) Physical address = o max  f + o

5 0 Physical Address Specifications Frame/Offset pair v. An absolute index Example: A 16-bit address space with (o max =) 512 byte page frames  Addressing location (3, 6) = 1, PA: 16 (0,0) (3,6) f o Physical Memory , ,542 0

6 Questions The offset is the same in a virtual address and a physical address.  A. True  B. False If your level 1 data cache is equal to or smaller than 2 number of page offset bits then address translation is not necessary for indexing the data cache.  A. True  B. False

7 Realizing Virtual Memory Paging A process’s virtual address space is partitioned into equal sized pages  page = page frame (0,0) 2 n -1 = (p MAX -1,o MAX -1) po (p,o)(p,o) p VA: o Virtual Address Space 1 log 2 o MAX log 2 (p max  o max ) A virtual address is a pair (p, o) p— page number (p max pages) o— page offset (o max bytes/pages) Virtual address = o max  p + o

8 Paging Mapping virtual addresses to physical addresses Pages map to frames Pages are contiguous in a VAS...  But pages are arbitrarily located in physical memory, and  Not all pages mapped at all times Virtual Address Space (p1,o1)(p1,o1) (p2,o2)(p2,o2) Physical Memory (f1,o1)(f1,o1) (f2,o2)(f2,o2)

9 Frames and pages Only mapping virtual pages that are in use does what?  A. Increases memory utilization.  B. Increases performance for user applications.  C. Allows an OS to run more programs concurrently.  D. Gives the OS freedom to move virtual pages in the virtual address space. Address translation is  A. Frequent  B. Infrequent Changing address mappings is  A. Frequent  B. Infrequent

10 Page Table Paging Virtual address translation A page table maps virtual pages to physical frames CPU (p,o)(p,o) p P’s Virtual Address Space Physical Memory po (f,o)(f,o) fo Physical Addresses Program P Program P Virtual Addresses f

11 Virtual Address Translation Details Page table structure Contents:  Flags — dirty bit, resident bit, clock/reference bit  Frame number 10 Page Table p po fo Physical Addresses Virtual Addresses f 0 PTBR CPU + 1 table per process Part of process’s state

Virtual Address Translation Details Example A system with 16-bit addresses  32 KB of physical memory  1024 byte pages CPU Page Table Physical Memory 15 po (4,1023) fo Physical Addresses Virtual Addresses P’s Virtual Address Space (3,1023) (4,0) (0,0)

13 Virtual Address Translation Performance Issues Problem — VM reference requires 2 memory references!  One access to get the page table entry  One access to get the data Page table can be very large; a part of the page table can be on disk.  For a machine with 64-bit addresses and 1024 byte pages, what is the size of a page table? What to do?  Most computing problems are solved by some form of…  Caching  Indirection

14 Virtual Address Translation Using TLBs to Speedup Address Translation Cache recently accessed page-to-frame translations in a TLB  For TLB hit, physical page number obtained in 1 cycle  For TLB miss, translation is updated in TLB  Has high hit ratio (why?) Page Table po fo Physical Addresses Virtual Addresses CPU TLB f KeyValue p p f ? X

15 Dealing With Large Page Tables Multi-level paging Add additional levels of indirection to the page table by sub-dividing page number into k parts  Create a “tree” of page tables  TLB still used, just not shown  The architecture determines the number of levels of page table Third-Level Page Tables p2p2 o Virtual Address First-Level Page Table p3p3 Second-Level Page Tables p1p1 p1p1 p2p2 p3p3

16 Dealing With Large Page Tables Multi-level paging Example: Two-level paging Second-Level Page Table p1p1 o 1 10 fo Physical Addresses Virtual Addresses CPU First-Level Page Table page table p2p2 f p1p1 PTBR p2p Memory

17 The Problem of Large Address Spaces With large address spaces (64-bits) forward mapped page tables become cumbersome.  E.g. 5 levels of tables. Instead of making tables proportional to size of virtual address space, make them proportional to the size of physical address space.  Virtual address space is growing faster than physical. Use one entry for each physical page with a hash table  Translation table occupies a very small fraction of physical memory  Size of translation table is independent of VM size Page table has 1 entry per virtual page Hashed/Inverted page table has 1 entry per physical frame

18 Virtual Address Translation Using Page Registers (aka Hashed/Inverted Page Tables) Each frame is associated with a register containing  Residence bit: whether or not the frame is occupied  Occupier: page number of the page occupying frame  Protection bits Page registers: an example  Physical memory size: 16 MB  Page size: 4096 bytes  Number of frames: 4096  Space used for page registers (assuming 8 bytes/register): 32 Kbytes  Percentage overhead introduced by page registers: 0.2%  Size of virtual memory: irrelevant

19 Page Registers How does a virtual address become a physical address? CPU generates virtual addresses, where is the physical page?  Hash the virtual address  Must deal with conflicts TLB caches recent translations, so page lookup can take several steps  Hash the address  Check the tag of the entry  Possibly rehash/traverse list of conflicting entries TLB is limited in size  Difficult to make large and accessible in a single cycle.  They consume a lot of power (27% of on-chip for StrongARM)

20 Indexing Hashed Page Tables Using Hash Tables Hash page numbers to find corresponding frame number  Page frame number is not explicitly stored (1 frame per entry)  Protection, dirty, used, resident bits also in entry h(PID, p) po 1169 fo Physical Addresses Virtual Address PTBR CPU Hash PID Inverted Page Table 1 0 page Memory 0 f max – 1 f max – 2 running PID + 1 =? tag check

21 Searching Hahed Page Tables Using Hash Tables Page registers are placed in an array Page i is placed in slot f(i) where f is an agreed-upon hash function To lookup page i, perform the following:  Compute f(i) and use it as an index into the table of page registers  Extract the corresponding page register  Check if the register tag contains i, if so, we have a hit  Otherwise, we have a miss

22 Searching Hashed Page Tables Using Hash Tables (Cont’d.) Minor complication  Since the number of pages is usually larger than the number of slots in a hash table, two or more items may hash to the same location Two different entries that map to same location are said to collide Many standard techniques for dealing with collisions  Use a linked list of items that hash to a particular table entry  Rehash index until the key is found or an empty table entry is reached (open hashing)

23 Questions Why use hashed/inverted page tables?  A. Forward mapped page tables are too slow.  B. Forward mapped page tables don’t scale to larger virtual address spaces.  C. Inverted pages tables have a simpler lookup algorithm, so the hardware that implements them is simpler.  D. Inverted page tables allow a virtual page to be anywhere in physical memory.

24 Virtual Memory (Paging) The bigger picture A process’s VAS is its context  Contains its code, data, and stack Code pages are stored in a user’s file on disk  Some are currently residing in memory; most are not Data and stack pages are also stored in a file  Although this file is typically not visible to users  File only exists while a program is executing OS determines which portions of a process’s VAS are mapped in memory at any one time Code Data Stack File System (Disk) OS/MMU Physical Memory

25 Virtual Memory Page fault handling References to non-mapped pages generate a page fault Program P’s VAS Disk CPU Physical Memory Page Table 0 OS resumes/initiates some other process Read of page completes OS maps the missing page into memory OS restart the faulting process Page fault handling steps: Processor runs the interrupt handler OS blocks the running process OS starts read of the unmapped page

26 Virtual Memory Performance Page fault handling analysis To understand the overhead of paging, compute the effective memory access time (EAT)  EAT = memory access time  probability of a page hit + page fault service time  probability of a page fault Example:  Memory access time: 60 ns  Disk access time: 25 ms  Let p = the probability of a page fault  EAT = 60(1–p) + 25,000,000p To realize an EAT within 5% of minimum, what is the largest value of p we can tolerate?

27 Vista reading from the pagefile

28 Vista writing to the pagefile

29 Virtual Memory Summary Physical and virtual memory partitioned into equal size units Size of VAS unrelated to size of physical memory Virtual pages are mapped to physical frames Simple placement strategy There is no external fragmentation Key to good performance is minimizing page faults

30 Segmentation vs. Paging Segmentation has what advantages over paging?  A. Fine-grained protection.  B. Easier to manage transfer of segments to/from the disk.  C. Requires less hardware support  D. No external fragmentation Paging has what advantages over segmentation?  A. Fine-grained protection.  B. Easier to manage transfer of pages to/from the disk.  C. Requires less hardware support.  D. No external fragmentation.