Virtual Memory Review. Page faults. Paging system summary (so far)

Similar documents
Translation Buffers (TLB s)

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Computer Systems Architecture I. CSE 560M Lecture 18 Guest Lecturer: Shakir James

Virtual to physical address translation

CSE 120 Principles of Operating Systems Spring 2017

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

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

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

ECE232: Hardware Organization and Design

Chapter 10: Virtual Memory. Lesson 05: Translation Lookaside Buffers

CSE 120 Principles of Operating Systems

CS 153 Design of Operating Systems Winter 2016

VIRTUAL MEMORY II. Jo, Heeseung

Virtual Memory. Lecture for CPSC 5155 Edward Bosworth, Ph.D. Computer Science Department Columbus State University

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

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

CS 318 Principles of Operating Systems

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, FALL 2012

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

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

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

CMSC 313 COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE PROGRAMMING LECTURE 27, SPRING 2013

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

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

ECE 341. Lecture # 18

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

Chapter 5 (Part II) Large and Fast: Exploiting Memory Hierarchy. Baback Izadi Division of Engineering Programs

Virtual Memory. User memory model so far:! In reality they share the same memory space! Separate Instruction and Data memory!!

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

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 24

Virtual Memory. Virtual Memory

Virtual Memory 2. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. P & H Chapter 5.4

Chapter Seven. Memories: Review. Exploiting Memory Hierarchy CACHE MEMORY AND VIRTUAL MEMORY

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

A Few Problems with Physical Addressing. Virtual Memory Process Abstraction, Part 2: Private Address Space

Chapter 5. Large and Fast: Exploiting Memory Hierarchy. Part II Virtual Memory

CSE 351. Virtual Memory

Reducing Hit Times. Critical Influence on cycle-time or CPI. small is always faster and can be put on chip

Virtual Memory. Reading. Sections 5.4, 5.5, 5.6, 5.8, 5.10 (2) Lecture notes from MKP and S. Yalamanchili

ADDRESS TRANSLATION AND TLB

CS 153 Design of Operating Systems Winter 2016

CS162 Operating Systems and Systems Programming Lecture 14. Caching (Finished), Demand Paging

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

P & H Chapter 5.7 (up to TLBs) Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University

CSE 141 Computer Architecture Spring Lectures 17 Virtual Memory. Announcements Office Hour

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

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

Chapter 5 B. Large and Fast: Exploiting Memory Hierarchy

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

Virtual Memory Overview

CS399 New Beginnings. Jonathan Walpole

Topic 18: Virtual Memory

The Virtual Memory Abstraction. Memory Management. Address spaces: Physical and Virtual. Address Translation

HY225 Lecture 12: DRAM and Virtual Memory

Carnegie Mellon. Bryant and O Hallaron, Computer Systems: A Programmer s Perspective, Third Edition

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

Virtual Memory: From Address Translation to Demand Paging

virtual memory Page 1 CSE 361S Disk Disk

Processes and Virtual Memory Concepts

Virtual Memory - Objectives

198:231 Intro to Computer Organization. 198:231 Introduction to Computer Organization Lecture 14

CS/COE 1550

Computer Organization and Structure. Bing-Yu Chen National Taiwan University

Multi-Process Systems: Memory (2) Memory & paging structures: free frames. Memory & paging structures. Physical memory

Opera&ng Systems ECE344

Virtual Memory. Motivations for VM Address translation Accelerating translation with TLBs

Virtual Memory. Samira Khan Apr 27, 2017

Topic 18 (updated): Virtual Memory

EECS 482 Introduction to Operating Systems

Virtual Memory, Address Translation

Memory Management. Disclaimer: some slides are adopted from book authors slides with permission 1

ADDRESS TRANSLATION AND TLB

Logical Diagram of a Set-associative Cache Accessing a Cache

Virtual Memory, Address Translation

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

John Wawrzynek & Nick Weaver

CSE 4/521 Introduction to Operating Systems. Lecture 15 Virtual Memory I (Background, Demand Paging) Summer 2018

Virtual Memory: From Address Translation to Demand Paging

Virtual Memory II. CSE 351 Autumn Instructor: Justin Hsia

lecture 18 cache 2 TLB miss TLB - TLB (hit and miss) - instruction or data cache - cache (hit and miss)

Memory Hierarchy Requirements. Three Advantages of Virtual Memory

Computer Architecture and Engineering. CS152 Quiz #3. March 18th, Professor Krste Asanovic. Name:

CMU Introduction to Computer Architecture, Spring 2014 HW 5: Virtual Memory, Caching and Main Memory

Address spaces and memory management

!! What is virtual memory and when is it useful? !! What is demand paging? !! When should pages in memory be replaced?

Virtual Memory II CSE 351 Spring

COSC3330 Computer Architecture Lecture 20. Virtual Memory

18-447: Computer Architecture Lecture 18: Virtual Memory III. Yoongu Kim Carnegie Mellon University Spring 2013, 3/1

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

Virtual Memory. CS 3410 Computer System Organization & Programming. [K. Bala, A. Bracy, E. Sirer, and H. Weatherspoon]

Virtual Memory Oct. 29, 2002

LECTURE 4: LARGE AND FAST: EXPLOITING MEMORY HIERARCHY

EN1640: Design of Computing Systems Topic 06: Memory System

Operating Systems. Operating Systems Sina Meraji U of T

Virtual Memory 2. Today. Handling bigger address spaces Speeding translation

MEMORY MANAGEMENT UNITS

5DV118 Computer Organization and Architecture Umeå University Department of Computing Science Stephen J. Hegner

Virtual Memory. Physical Addressing. Problem 2: Capacity. Problem 1: Memory Management 11/20/15

Operating Systems. 09. Memory Management Part 1. Paul Krzyzanowski. Rutgers University. Spring 2015

Chapter 5. Large and Fast: Exploiting Memory Hierarchy

Transcription:

Lecture 22 (Wed 11/19/2008) Virtual Memory Review Lab #4 Software Simulation Due Fri Nov 21 at 5pm HW #3 Cache Simulator & code optimization Due Mon Nov 24 at 5pm More Virtual Memory 1 2 Paging system summary (so far) Addresses generated by the CPU are virtual addresses In order to access the memory hierarchy, addresses must be translated into physical addresses That translation is done on a program per program basis. Each program must have its own page table All of the address you use in assembly programming are virtual addresses The virtual address of program A and the same virtual address in program B will, in general, map to two different physical addresses 3 Page faults When a virtual address has no corresponding physical address mapping (valid bit is off in the PTE) we have a page fault On a page fault (a page fault is an exception) the faulting page must be fetched from disk (takes milliseconds) the whole page (e.g., 4 or 8KB ) must be fetched (amortize the cost of disk access) because the program is going to be idle during that page fetch, the CPU better be used by another program. On a page fault, the state of the faulting program is saved and the O.S. takes over. This is context-switching 4 1

Top level questions for paging systems When do we bring a page into main memory? Where do we put it? How do we know it s there? What happens if main memory is full? Top level answers for paging systems When do we bring a page into main memory? When there is a page fault for that page, i.e., on demand Where do we put it? No restriction; mapping is fully-associative How do we know it s there? The corresponding PTE entry has its valid bit on What happens if main memory is full We have to replace one of the virtual pages currently mapped. Replacement algorithms can be sophisticated (see CSE 451) since we have a context-switch and hence plenty of time 5 6 Translation Buffers (TLBs) To perform virtual to physical address translation we need to look-up a page table entry Since the page table is in memory, need to access memory P_addr = MEM[Pg_Tab_Base + (V_addr[31:12]<<2)] + V_addr[11:0] Too time consuming! 50+ cycles per memory reference! Hence we need to cache the page tables For that purpose special caches named translation buffers are part of the memory system Also named Translation Lookaside Buffers (TLBs) 7 TLB Organization TLB organized as caches For each entry in the TLB we ll have a tag to check that it is the right entry data which instead of being the contents of memory locations, like in a cache, will be a page table entry (PTE) TLB s are smaller than memory caches 32 to 128 entries from fully associative to direct-mapped there can be an instruction TLB, a data TLB and also distinct TLB s for user and system address spaces 8 2

TLB organization Virtual Address to Physical Address (Revisited) Virtual page number Offset ALU hit tag Index Virtual address cache v dprot Copy of PTE TLB miss miss Main memory hit Physical address Physical frame number 9 10 Address Translation At each memory reference the hardware searches the TLB for the translation TLB hit and valid PTE the physical address is passed to the cache TLB miss, either hardware or software (depends on implementation) searches page table in memory If PTE is valid, contents of the PTE loaded in the TLB and back to step above In hardware the TLB miss takes 10-100 cycles In software takes up to 100-1000 cycles In either case, no context-switch Context-switch takes more cycles than a TLB miss If PTE is invalid, we have a page fault (even on a TLB hit) TLB Management TLBs are caches If small (e.g. 32 entries), can be fully associative Current trend: larger (about 128 entries); separate TLB s for instruction and data; Some part of the TLB reserved for system TLBs are write-back. The only thing that can change is dirty bit + any other information needed for page replacement algorithm (see CSE 451) MIPS 3000 TLB (old) 64 entries: fully associative. Random replacement; 8 entries used by system On TLB miss, we have a trap; software takes over but no context-switch 11 12 3

TLB Management (continued) At context-switch, the virtual page translations in the TLB are not valid for the new task Invalidate the TLB (set all valid bits to 0) Or append a Process ID (PID) number to the tag in the TLB. When a new task takes over, the O.S. creates a new PID. PID are recycled and entries corresponding to old PID are invalidated Paging systems -- Hardware/software interactions Page tables Managed by the O.S. Address of the start of the page table for a given process is found in a special register which is part of the state of the process The O.S. has its own page table The O.S. knows where the pages are stored on disk Page fault When a program attempts to access a location which is part of a page that is not in main memory, we have a page fault 13 14 Page fault detection (simplified) Page fault is an exception Detected by the hardware (invalid bit in PTE either in TLB or page table) To resolve a page fault takes millions of cycles (disk I/O) The program that has a page fault must be interrupted A page fault occurs in the middle of an instruction In order to restart the program later, the state of the program must be saved and instructions must be restartable (precise exceptions) State consists of all registers, including PC and special registers (such as the one giving the start of the page table address) 15 Page fault handler (simplified) Page fault exceptions are cleared by an O.S. routine called the page fault handler which will Grab a physical frame from a free list maintained by the O.S. Find out where the faulting page resides on disk Initiate a read for that page Choose a frame to free (if needed), i.e., run a replacement algorithm If the replaced frame is dirty, initiate a write of that frame to disk Context-switch, i.e., give the CPU to a task ready to proceed 16 4

Completion of page fault When the faulting page has been read from disk (a few ms later) The disk controller will raise an interrupt (another form of exception) The O.S. will take over (context-switch) and modify the PTE (in particular, make it valid) The program that had the page fault is put on the queue of tasks ready to be run Context-switch to the program that was running before the interrupt occurred Two Extremes in Memory Hierarchy PARAMETER L1 PAGING SYSTEM block (page) size 16-64 bytes 4K-8K (also 64K) miss (fault) time 10-100 cycles Millions of cycles (20-1000 ns) (3-20 ms) miss (fault) rate 1-10% 0.00001-0.001% memory size 4K-64K Bytes (impl. depend.) Gigabytes (depends on ISA) 17 18 Other extreme differences Mapping: Restricted (L1) vs. General (Paging) Hardware assist for virtual address translation (TLB) Miss handler Hardware only for caches Software only for paging system (context-switch) Hardware and/or software for TLB Replacement algorithm Not that important for caches Very important for paging system Write policy Always write back for paging systems 19 5