Translation Lookaside Buffer

Slides:



Advertisements
Similar presentations
EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
Advertisements

Computer Organization CS224 Fall 2012 Lesson 44. Virtual Memory  Use main memory as a “cache” for secondary (disk) storage l Managed jointly by CPU hardware.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
CS 153 Design of Operating Systems Spring 2015
CS 333 Introduction to Operating Systems Class 12 - Virtual Memory (2) Jonathan Walpole Computer Science Portland State University.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
Memory Management (II)
Memory Management and Paging CSCI 3753 Operating Systems Spring 2005 Prof. Rick Han.
CS 333 Introduction to Operating Systems Class 11 – Virtual Memory (1)
Translation Buffers (TLB’s)
Virtual Memory and Paging J. Nelson Amaral. Large Data Sets Size of address space: – 32-bit machines: 2 32 = 4 GB – 64-bit machines: 2 64 = a huge number.
Computer Architecture Lecture 28 Fasih ur Rehman.
CS 153 Design of Operating Systems Spring 2015 Lecture 17: Paging.
Operating Systems ECE344 Ding Yuan Paging Lecture 8: Paging.
Virtual Memory Expanding Memory Multiple Concurrent Processes.
CS399 New Beginnings Jonathan Walpole. Virtual Memory (1)
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Virtual Memory Hardware.
4.3 Virtual Memory. Virtual memory  Want to run programs (code+stack+data) larger than available memory.  Overlays programmer divides program into pieces.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Demand Paging.
Processes and Virtual Memory
CS2100 Computer Organisation Virtual Memory – Own reading only (AY2015/6) Semester 1.
Virtual Memory Ch. 8 & 9 Silberschatz Operating Systems Book.
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)
CS161 – Design and Architecture of Computer
CMSC 611: Advanced Computer Architecture
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Memory Hierarchy Ideal memory is fast, large, and inexpensive
Non Contiguous Memory Allocation
Virtual Memory Chapter 7.4.
ECE232: Hardware Organization and Design
CS161 – Design and Architecture of Computer
CSE 120 Principles of Operating
Lecture Topics: 11/19 Paging Page tables Memory protection, validation
A Real Problem What if you wanted to run a program that needs more memory than you have? September 11, 2018.
CS703 - Advanced Operating Systems
Section 9: Virtual Memory (VM)
Page Table Implementation
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.
Some Real Problem What if a program needs more memory than the machine has? even if individual programs fit in memory, how can we run multiple programs?
Memory Hierarchy Virtual Memory, Address Translation
Morgan Kaufmann Publishers
CS510 Operating System Foundations
CSE 153 Design of Operating Systems Winter 2018
Lecture 28: Virtual Memory-Address Translation
Virtual Memory 3 Hakim Weatherspoon CS 3410, Spring 2011
Andy Wang Operating Systems COP 4610 / CGS 5765
Andy Wang Operating Systems COP 4610 / CGS 5765
Virtual Memory Hardware
Translation Lookaside Buffer
CSE 451: Operating Systems Autumn 2005 Memory Management
Translation Buffers (TLB’s)
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
CSE 451: Operating Systems Autumn 2004 Page Tables, TLBs, and Other Pragmatics Hank Levy 1.
Translation Buffers (TLB’s)
CSC3050 – Computer Architecture
CSE 451: Operating Systems Autumn 2003 Lecture 10 Paging & TLBs
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Lecture 8: Efficient Address Translation
Translation Lookaside Buffers
Paging and Segmentation
CSE 451: Operating Systems Winter 2005 Page Tables, TLBs, and Other Pragmatics Steve Gribble 1.
CSE 153 Design of Operating Systems Winter 2019
Translation Buffers (TLBs)
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.
Andy Wang Operating Systems COP 4610 / CGS 5765
Review What are the advantages/disadvantages of pages versus segments?
4.3 Virtual Memory.
Presentation transcript:

Translation Lookaside Buffer

Outline Translation lookaside buffer Memory protection

Speeding up Address Translation Paging MMU maps virtual to physical address on each memory access using page tables in memory Every memory access requires additional accesses This address translation can sped up by using a cache of page mappings

Translation Lookaside Buffer (TLB) TLB is a h/w cache of page table entries (PTE) TLB has small nr. of entries (e.g., 64) TLB exploits locality, programs need few pages at a time Each TLB entry contains key: page number Data: page table entry TLB is part of processor The TLB cache is fast because it is an associative cache (either fully associative or set-associative) V: is the entry valid or not? W: is the page writable? C: is the page cacheable? when not cacheable, processor should bypass the cache when accessing the page, e.g., to access memory-mapped device registers D: has a writable page been written to (is it dirty with respect to the data on disk)? R: has a page been referenced? unused: unused by hardware, can be used by OS virtual page number (VPN) V: valid W: writeable C: Cacheable D: Dirty (set by hardware) R: Referenced (set by hardware) TLB entry 31 12 11 frame number (PFN) unused R D C W V Page table entry

TLB Operations Similar to operations on any cache TLB lookup TLB cache miss handling TLB cache invalidate

TLB Lookup CPU p o Physical memory TLB hit f o TLB TLB miss Page Table page nr p f frame nr f o TLB f diagram shows fully associative cache TLB lookup: TLB h/w performs associative lookup, indexed by page nr. If match found, MMU uses frame nr. to access physical address TLB miss p Page Table

TLB Cache Miss Handling If TLB lookup fails, then page table is looked up for correct entry, and TLB cache is filled Choice of which TLB entry is replaced is called TLB replacement policy TLB cache misses can be handled by hardware or OS we will see dirty bits later

TLB Miss in Hardware or Software Hardware Managed TLB (x86) TLB handles misses in hardware Hardware defines page table format and uses page table register to locate page table in physical memory TLB replacement policy fixed by hardware Software Managed TLB (MIPS, SPARC, HP PA) Hardware generates trap called TLB miss fault OS handles TLB miss, similar to exception handling OS figures out the correct page table entry, adds it in TLB CPU has instructions for modifying TLB Page tables become entirely a OS data structure H/w doesn’t have a page table register TLB replacement policy managed in software

TLB Cache Invalidate TLB is a cache of page table entries, needs to be kept consistent with page table Whenever OS modifies any page table entry, it needs to invalidate TLB entry E.g., on a context switch to another address space, TLB entries are invalidated, which prevents use of mappings of last address space This is what really adds to the cost of context switching Why? We need a way to reduce this cost Why does TLB entry invalidation add to the cost of a context switch? Because after a context switch, we need to warm the cache, so every memory access requires accessing the page table. Recall that accessing the page table adds additional physical memory accesses for each physical memory access. For example, for a three-level page table, we add three memory accesses to each memory access, dramatically slowing the program, until the TLB is filled (and so the TLB miss rate is reduced).

TLB Cache Invalidate Options Clear TLB Empty TLB by clearing the valid bit of all entries Next thread will generate misses initially Eventually, its caches enough of its own entries in the TLB Tagged TLB Hardware maintains an id tag on each TLB entry Hardware maintains the current thread id in a specific register OS updates register on context switch Hardware compares current thread id with each TLB tag on each translation Enables space multiplexing of cache entries No invalidation is needed

Memory Protection Each memory partition may need different protection Text region: read, execute, no write Stack and data regions: read, write, no execute We can use MMU to implement page-level protection Page table entry has protection bits (e.g., page is writable) Page protection is enforced during address translation E.g., generate protection fault when read-only page is written hardware may or may not have execute bit. sometimes, read => execute. c is caching or disable caching in processor cache (not TLB cache) protection bits 31 13 12 PFN unused R D C W V Page table entry

Speeding Up Protection Enforcement Checking page table on each memory access is slow TLB can cache page-level protection bits TLB checks whether memory accesses are valid on each memory access If memory access is inconsistent with protection bits, TLB generates protection fault OS needs to invalidate TLB entry when page protection is changed Dirty

TLB Faults When a TLB fault occurs, it can be: TLB miss fault: no matching page number was found Read fault: A read was attempted but no entry matched Write fault: A write was attempted but no entry matched TLB protection fault: a matching page number was found, but protection bits are inconsistent with operation Read-only fault: A write to a word in a page was attempted but write-bit was not set (page is marked read-only) No-execute fault: The execution of an instruction in a page was attempted but the execute-bit was not set (page is marked non-executable)

Summary Paging MMU adds significant performance overhead because each memory access requires additional memory accesses to the page table TLB is a cache of page table entries Indexed by page number, returns frame number TLB miss handling can be performed in h/w or s/w When performed in software, hardware only knows about TLB, not page table OS needs to invalidate TLB entries when it modifies the corresponding page table entry Paging MMU can be used to provide page level memory protection

Think Time What is the purpose of a TLB? What is a TLB-miss fault? What are the benefits of using a hardware managed TLB? What are the benefits of a software managed TLB? What is a protection fault? purpose of TLB: speeds up address translation by keeping cache of virtual -> physical mapping, i.e., cache of page to frame mapping TLB miss fault: TLB doesn't contain valid page mapping H/w TLB: TLB-miss handling is fast S/w TLB: more flexibility with TLB-miss handling (e.g., OS can implement different TLB replacement policies) protection fault: Page access is inconsistent with protection bits associated with page