Translation Lookaside Buffer

Slides:



Advertisements
Similar presentations
CSCC69: Operating Systems
Advertisements

EECS 470 Virtual Memory Lecture 15. Why Use Virtual Memory? Decouples size of physical memory from programmer visible virtual memory Provides a convenient.
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)
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.
© 2004, D. J. Foreman 1 Virtual Memory. © 2004, D. J. Foreman 2 Objectives  Avoid copy/restore entire address space  Avoid unusable holes in memory.
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
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)
CS203 – Advanced Computer Architecture Virtual Memory.
CS161 – Design and Architecture of Computer
Translation Lookaside Buffer
CMSC 611: Advanced Computer Architecture
MODERN OPERATING SYSTEMS Third Edition ANDREW S
Memory Hierarchy Ideal memory is fast, large, and inexpensive
Virtual Memory Acknowledgment
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
From Address Translation to Demand Paging
CS703 - Advanced Operating Systems
Today How was the midterm review? Lab4 due today.
Page Table Implementation
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
CSE 451: Operating Systems Winter 2011 Page Table Management, TLBs, and Other Pragmatics Mark Zbikowski Gary Kimura 1.
Andy Wang Operating Systems COP 4610 / CGS 5765
Virtual Memory Hardware
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 Lecture 10 Paging & TLBs
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.
Sarah Diesburg Operating Systems CS 3430
Andy Wang Operating Systems COP 4610 / CGS 5765
CSE 451: Operating Systems Winter 2012 Page Table Management, TLBs, and Other Pragmatics Mark Zbikowski Gary Kimura 1.
Review What are the advantages/disadvantages of pages versus segments?
CSE 451: Operating Systems Winter 2009 Module 11a Page Table Management, TLBs, and Other Pragmatics Mark Zbikowski Gary Kimura 1.
4.3 Virtual Memory.
Sarah Diesburg Operating Systems COP 4610
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 Linear Page Table vaddr = 0x01005a6f offset = vaddr & 0xfff = 0xa6f pg = vaddr >> 12 = 0x1005 fr = ptr[pg].frame = 0xe paddr = (fr << 12) | offset = 0xea6f Two-Level Page Table vaddr = 0x01005a6f offset = vaddr & 0xfff = 0xa6f pg2 = (vaddr >> 12) & 0x3ff = 0x5 pg1 = vaddr >> (12+10) = 0x4 pt_2 = ptr[pg1].frame << 12 = 0xa000 fr = pt_2[pg2].frame = 0xe paddr = (fr << 12) | offset = 0xea6f

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 the current thread id in a specific register OS updates register on context switch Hardware maintains an id tag with each TLB entry On TLB fill, TLB tag is assigned current thread id On TLB lookup, TLB hit occurs only when TLB tag matches current thread id Enables space multiplexing of cache entries Reduces need for invalidation significantly

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

Software Managed 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 a TLB entry 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