CS162 - Operating Systems and Systems Programming. Address Translation => Paging"

Similar documents
CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

CPS104 Computer Organization and Programming Lecture 16: Virtual Memory. Robert Wagner

Multi-level Translation. CS 537 Lecture 9 Paging. Example two-level page table. Multi-level Translation Analysis

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

memory management Vaibhav Bajpai

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. April 12, 2018 L16-1

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 13: Address Translation

Virtual Memory. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T. November 15, MIT Fall 2018 L20-1

Page 1. Goals for Today" Important Aspects of Memory Multiplexing" Virtualizing Resources" CS162 Operating Systems and Systems Programming Lecture 9

Memory Management. An expensive way to run multiple processes: Swapping. CPSC 410/611 : Operating Systems. Memory Management: Paging / Segmentation 1

CS 152 Computer Architecture and Engineering. Lecture 11 - Virtual Memory and Caches

Virtual Memory: From Address Translation to Demand Paging

CS162 Operating Systems and Systems Programming Lecture 12. Address Translation. Page 1

Virtual Memory: From Address Translation to Demand Paging

CS 153 Design of Operating Systems Winter 2016

CS5460: Operating Systems Lecture 14: Memory Management (Chapter 8)

Virtual Memory. Today. Segmentation Paging A good, if common example

Virtual to physical address translation

Virtual Memory. Virtual Memory

EECS 470. Lecture 16 Virtual Memory. Fall 2018 Jon Beaumont

Memory Management. Goals of Memory Management. Mechanism. Policies

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

virtual memory Page 1 CSE 361S Disk Disk

Memory Management. Minsoo Ryu. Real-Time Computing and Communications Lab. Hanyang University.

Virtual Memory Virtual memory first used to relive programmers from the burden of managing overlays.

CS 333 Introduction to Operating Systems. Class 11 Virtual Memory (1) Jonathan Walpole Computer Science Portland State University

Topics: Memory Management (SGG, Chapter 08) 8.1, 8.2, 8.3, 8.5, 8.6 CS 3733 Operating Systems

CS252 S05. Main memory management. Memory hardware. The scale of things. Memory hardware (cont.) Bottleneck

Virtual Memory. Patterson & Hennessey Chapter 5 ELEC 5200/6200 1

Paging! 2/22! Anthony D. Joseph and Ion Stoica CS162 UCB Fall 2012! " (0xE0)" " " " (0x70)" " (0x50)"

CS 537 Lecture 6 Fast Translation - TLBs

10/7/13! Anthony D. Joseph and John Canny CS162 UCB Fall 2013! " (0xE0)" " " " (0x70)" " (0x50)"

Another View of the Memory Hierarchy. Lecture #25 Virtual Memory I Memory Hierarchy Requirements. Memory Hierarchy Requirements

Lecture 13: Virtual Memory Management. CSC 469H1F Fall 2006 Angela Demke Brown

Memory Management Minsoo Ryu Real-Time Computing and Communications Lab. Hanyang University

COSC3330 Computer Architecture Lecture 20. Virtual Memory

Virtual Memory 1. To do. q Segmentation q Paging q A hybrid system

Virtual Memory Oct. 29, 2002

CS61C : Machine Structures

Chapter 8 Memory Management

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Computer Science 146. Computer Architecture

ECE 571 Advanced Microprocessor-Based Design Lecture 12

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

CS 152 Computer Architecture and Engineering. Lecture 9 - Address Translation

CS152 Computer Architecture and Engineering Lecture 18: Virtual Memory

CS 152 Computer Architecture and Engineering. Lecture 8 - Address Translation

Motivations for Virtual Memory Virtual Memory Oct. 29, Why VM Works? Motivation #1: DRAM a Cache for Disk

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

CS 134: Operating Systems

CS450/550 Operating Systems

Operating Systems. Paging... Memory Management 2 Overview. Lecture 6 Memory management 2. Paging (contd.)

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

Memory: Page Table Structure. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

CS 152 Computer Architecture and Engineering. Lecture 8 - Address Translation

Lecture 13: Address Translation

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

CSE 451: Operating Systems Winter Page Table Management, TLBs and Other Pragmatics. Gary Kimura

CS 152 Computer Architecture and Engineering. Lecture 9 - Address Translation

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

CHAPTER 8: MEMORY MANAGEMENT. By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

Chapter 8: Memory-Management Strategies

Chapter 8. Virtual Memory

Virtual Memory. CS 351: Systems Programming Michael Saelee

ECE331: Hardware Organization and Design

VIRTUAL MEMORY II. Jo, Heeseung

EECS 482 Introduction to Operating Systems

Modern Virtual Memory Systems. Modern Virtual Memory Systems

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

CS399 New Beginnings. Jonathan Walpole

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

CS 31: Intro to Systems Virtual Memory. Kevin Webb Swarthmore College November 15, 2018

Chapter 8: Main Memory

16 Sharing Main Memory Segmentation and Paging

Page 1. Review: Address Segmentation " Review: Address Segmentation " Review: Address Segmentation "

ECE232: Hardware Organization and Design

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS 318 Principles of Operating Systems

1. Creates the illusion of an address space much larger than the physical memory

Paging. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CSE 120 Principles of Operating Systems

Virtual Memory - Objectives

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

Address Translation. Tore Larsen Material developed by: Kai Li, Princeton University

Virtual Memory. CS61, Lecture 15. Prof. Stephen Chong October 20, 2011

More on Address Translation. CS170 Fall T. Yang Some of slides from UCB CS162 by Kubiatowicz

Chapter 5B. Large and Fast: Exploiting Memory Hierarchy

Agenda. CS 61C: Great Ideas in Computer Architecture. Virtual Memory II. Goals of Virtual Memory. Memory Hierarchy Requirements

Chapter 8: Main Memory. Operating System Concepts 9 th Edition

Introduction to Operating Systems

Memory Hierarchy. Goal: Fast, unlimited storage at a reasonable cost per bit.

EITF20: Computer Architecture Part 5.1.1: Virtual Memory

Chapter 5 Memory Hierarchy Design. In-Cheol Park Dept. of EE, KAIST

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

Simple idea 1: load-time linking. Our main questions. Some terminology. Simple idea 2: base + bound register. Protection mechanics.

New-School Machine Structures. Overarching Theme for Today. Agenda. Review: Memory Management. The Problem 8/1/2011

Chapter 8: Main Memory

CSE 120 Principles of Operating Systems Spring 2017

Learning Outcomes. An understanding of page-based virtual memory in depth. Including the R3000 s support for virtual memory.

Transcription:

CS162 - Operating Systems and Systems Programming Address Translation => Paging" David E. Culler! http://cs162.eecs.berkeley.edu/! Lecture #15! Oct 3, 2014!! Reading: A&D 8.1-2, 8.3.1. 9.7 HW 3 out (due 10/13) Proj 1 Final 10/8, 10/10

Virtual Memory Concepts" Segmentation! virtual addressing scheme constructed as a collection of variable sized objects!» big objects (code, static data, heap, stack)!» smaller objects (???)! addresses of the form <seg id><offset>! are translated into!» a physical memory address (holding the data),!» an address translation fault, or!» a violation (seg fault) due to range or mode! by indexing into a segment table for STE!» base : bounds : access bits! or through segment registers (ala x86)! 15.2!

Virtual Memory Concepts" Segmentation! virtual addressing scheme constructed as a collection of variable sized objects! Paging! virtual addressing scheme in which a flat address space is broken into fixed size chunks! addresses are of the form <page#><offset>!» no particular semantic content! are translated into!» a physical memory address (holding the data),!» an address translation fault (page fault), or!» a violation (seg fault) due to range or mode! by indexing into a page table for PTE!» frame # : access bits! 15.3!

Where does a process live when it is not in memory?" 15.4!

Virtual-Physical Address Translation" Process! instruction! Operating System! virtual address! fault! protection fault! not present! address translation! mechanism! physical address! Memory! Disk! 15.5!

What Mechanism for Translation?" Segmentation! instruction! fault! address translation! mechanism! offset! variable! length! segment! 15.6!

What Mechanism for Translation?" Segmentation!! instruction! Paging! fault! address translation! mechanism! offset! variable! length! segment! instruction! fault! address translation! mechanism! fixed! length! page! 15.7!

Address Translation Structures" Segment table! ST[seg#] := base addr length flags! VA(s, o) => PA = ST[s].base + o! Page Table! PT[pg# ] = frame # flags! VA(p : o) => PA = PT[p].frame : o! Paged Segments! 2-Level Page Table! Inverted Page Table! 15.8!

Who does what when?" Process! virtual address! instruction! retry" exception! MMU! page fault! page#! PT! physical address! frame#! offset! Operating System! Page Fault Handler! update PT entry! load page from disk! scheduler! 15.9!

Issues for address translation mechanism" Fault occurs if any step along the VA => PA translation cannot complete! protection or length violation! page or segment not present (non-existent or on disk)! internal lookup steps! Page tables (and segment tables) reside in memory! how much memory to they take?! Virtual address space is (typically) large compared to physical memory space! 15.10!

Bit of historical perspective" 60 s Multics Timesharing & Segmentation! 70 s Unix on PDP-11 16-bit mini computerer! vax780 32-bit minicomputer => VMS &BSD Unix! 32-bit virtual addresses (4 GB), MBs of RAM, ~GB of disk! <1980 personal computer, i8086! 16 bit word size! < 640kb physical memory (2^20)! segments provided additional 4 bits!» PA 20 = SegReg 16 * 16 + Addr 16! 1982 workstation:! MC68000 32/16 bit machine, large (24 bit) PA! i80286 16 bit, segment descriptors => seg registers, complex! mid 80s: 32-bit microprocessor arrives! i80386 (segments + paging)! 15.11!

Admin break" Project! Slip days! Pressure Relief Valve! 15.12!

15.13!

Bit of historical perspective" vax780 32-bit minicomputer! few MBs of RAM (PA ~20+ bits), GB disk, 4 GB VA space! 16-bit micros! 32-bit microprocessor arrives! i80386 (segments + paging), MC680x0! RISC, SPARC, MIPS, M88000! 10s MBs of RAM, GBs of disk! => Mapping GBs of Virt. Address Space requires MBs of RAM for page tables!! multi-level translation (page the page table!!!)! 15.14!

Page Table Resouces" page#:offset! memory! instruction! PT base reg! page#! PT for current process! PTE! MMU! fault! MMU hardware performs 2 memory operations for every inst fetch, load, or store! PT for each process in memory! offset! 4 GB VAS / 4 KB page => 1 M PTEs = 4 MB! used sparsely! user page! 15.15!

How has OS design choices been influenced by technological change? " 15.16!

two-level page table" Virtual " Address:" 10 bits" 10 bits" 12 bits" Virtual" P1 index" Virtual" P2 index" Offset" Physical" Address:" Physical" Page #" Offset" 4KB PageTablePtr" 4 bytes" Tree of Page Tables! Tables fixed size (1024 entries)! On context-switch: save single PageTablePtr register! Valid bits on Page Table Entries! Don t need every 2 nd -level table! Even when exist, 2 nd -level tables can reside on disk if not in use! 4 bytes 15.17!

Example: Two-Level Paging" Virtual memory view" 1111 1111" 1111 0000" 1100 0000" 1000 0000" 0100 0000" stack! heap! data! Page Table" (level 1)" 111! 110 null! 101 null! 100! 011 null! 010! 001 null! 000! Page Tables" (level 2)" 11 11101 " 10 11100" 01 10111" 00 10110" 11 null " 10 10000" 01 01111" 00 01110" 11 01101 " 10 01100" 01 01011" 00 01010" Physical memory view" stack! stack! heap! data! 1110 0000" 0111 000" 0101 000" page2 #! 0000 0000" code! 11 00101 " 10 00100" 01 00011" 00 00010" code! 0001 0000" 0000 0000" page1 #! offset" 15.18!

Example: Two-Level Paging" 1001 0000" (0x90)" Virtual memory view" stack! heap! data! Page Table" (level 1)" 111! 110 null! 101 null! 100! 011 null! 010! 001 null! 000! Page Tables" (level 2)" 11 11101 " 10 11100" 01 10111" 00 10110" 11 null " 10 10000" 01 01111" 00 01110" 11 01101 " 10 01100" 01 01011" 00 01010" Physical memory view" stack! stack! heap! data! 1110 0000" 1000 0000" (0x80)" code! 11 00101 " 10 00100" 01 00011" 00 00010" code! 0001 0000" 0000 0000" 15.19!

Question " How many memory accesses per fetch, load, or store with 2-level page table?! Where can a page fault occur?! 15.20!

Multi-level Translation Analysis" Pros:! Only need to allocate as many page table entries as we need for application size is proportional to usage!» In other words, sparse address spaces are easy! Easy memory allocation! Easy Sharing!» Share at segment or page level (need additional reference counting)! Cons:! One pointer per page (typically 4K 16K pages today)! Page tables need to be contiguous!» However, previous example keeps tables to exactly one page in size! Two (or more, if >2 levels) lookups per reference!» Seems very expensive!! 15.21!

So how do we make address translation go fast?" Large memories are slow (larger the slower)! Fast memories are small! Really fast storage (registers) are really small! How do we get a small average memory access time for a LARGE memory?! Harness probability! temporal locality: recently access things likely to be accessed again soon! spatial locality: things near recently accessed thing are likely to be accessed soon too! AMAT = P hit x Time hit + (1-P hit ) x Time miss! Caching!!!! 15.22!

Where are we depending on caching already?" When we load a page from disk to memory (page fault)! we are likely to access it many times while it is resident! ~ 10 ms (0.001 s) to load it! @ 1 GHz that is 10 million cycles! we are likely to access other items in the page! 4KB => much larger pages! 15.23!

Translation Look Aside Buffer (TLB)" Process! virtual address! memory! memory! instruction! page fault! MMU! page#! PT! frame#! TLB! =?! page # frame #! offset! TLB holds mapping (page # -> frame #) for recently accessed pages! on hit, avoid reading PT! on miss, read PTE into TLB! 15.24!

RAM?" 15.25!

Costs" 15.26!

How has OS design choices been influenced by technological change? " 15.27!

Bit of historical perspective" vax780 32-bit minicomputer! few MBs of RAM (PA ~20+ bits), GB disk, 4 GB VA space! 16-bit micros! mid 80 s 32-bit microprocessor arrives! i80386 (segments + paging)! RISC, SPARC, MIPS, M8800! 10s MBs of RAM, GBs of disk! => Mapping GBs of Virt. Address Space requires MBs of RAM for page tables!! multi-level translation (page the page table!!!)! ~10 GBs of RAM (!!!) => VA < PA again! ~2005 64-bit processors arrive! VA >> PA! 15.28!

Inverted Page Table" With all previous examples ( Forward Page Tables )! Size of page tables is at least as large as amount of virtual memory allocated to ALL processes! Physical memory may be much, much less!» Much of process space may be out on disk or not in use! Virtual" Page #" Offset" Process ID" Hash" Table"! Answer: use a hash table! Called an Inverted Page Table! Size is independent of virtual address space! Directly related to amount of phy mem (1 entry per phy page)! Very attractive option for 64-bit address spaces (IA64, PowerPC, UltraSPARC)! Cons: Complexity of managing hash chains in hardware! Physical" Page #" Offset" 15.29!

Summary: Inverted Table" Virtual memory view" 1111 1111" 1110 0000" stack! Inverted Table" Hash(procID & virt. page #) = " phys. page #" Physical memory view" stack! 1110 0000" 1100 0000" 1000 0000" 0100 0000" 0000 0000" heap! data! code! h(11111) =" 11101" h(11110) =" 11100" h(11101) = 10111 " " h(11100) = 10110" " h(10010)= 10000" " h(10001)= 01111" " h(10000)=" 01110" h(01011)= " 01101 " h(01010)= 01100" " h(01001)= 01011" " h(01000)= 01010 " " h(00011)= 00101 " " h(00010)= 00100 " " h(00001)= 00011 " " h(00000)= 00010" " stack! heap! data! code! 1011 0000" 0111 0000" 0101 0000" 0001 0000" 0000 0000" page #!offset" 15.30!

Address Translation Comparison" Advantages" Segmentation! Fast context switching: Segment mapping maintained by CPU! Paging (single-level page)! Paged segmentation! Two-level pages! No external fragmentation, fast easy allocation! Table size ~ # of pages in virtual memory, fast easy allocation! Inverted Table! Table size ~ # of pages in physical memory! Disadvantages" External fragmentation! Large table size ~ virtual memory! Internal fragmentation! Multiple memory references per page access! Hash function more complex! Aliasing! 15.31!

Summary of Translation" Memory is a resource that must be multiplexed! Controlled Overlap: only shared when appropriate! Translation: Change virtual addresses into physical addresses! Protection: Prevent unauthorized sharing of resources! Simple Protection through segmentation! Base + Limit registers restrict memory accessible to user! Can be used to translate as well! Page Tables! Memory divided into fixed-sized chunks of memory! Offset of virtual address same as physical address! Multi-Level Tables! Virtual address mapped to series of tables! Permit sparse population of address space! Inverted page table: size of page table related to physical memory size! 15.32!

Segments vs Pages" Segments reflects a design philosophy that hardware capability should closely match software structure.! object oriented program => hardware protection of objects => OS management of object placement in the storage hierarchy! Challenge of segment size! large segments => easy translation, memory allocation hard! small segments => translation overhead! code, data, stack, heap, shared library (just a few)! Main value is sharing! in a flat address space, where does a shared library go?! Segments don t match programming languages well! what is the structure of a pointer? seg:offest vs addr! is it unique?! Large flat address space is simpler & empty space facilitates sharing! 15.33!