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

Similar documents
Virtual Memory 2. To do. q Handling bigger address spaces q Speeding translation

Virtual Memory. Today. Handling bigger address spaces Speeding translation

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

Virtual Memory. Yannis Smaragdakis, U. Athens

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

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

CS 550 Operating Systems Spring Memory Management: Paging

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

VIRTUAL MEMORY II. Jo, Heeseung

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

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

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

CS 153 Design of Operating Systems Winter 2016

20. Paging: Smaller Tables

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

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

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

Virtual Memory. Samira Khan Apr 27, 2017

Chapter 8 Main Memory

Main Memory (Part II)

Virtual to physical address translation

CSE 120 Principles of Operating Systems Spring 2017

CSE 120 Principles of Operating Systems

20-EECE-4029 Operating Systems Spring, 2013 John Franco

CS370 Operating Systems

Virtual Memory: From Address Translation to Demand Paging

CS3600 SYSTEMS AND NETWORKS

Beyond Physical Memory: Mechanisms

Paging: Smaller Tables

CS 537 Lecture 6 Fast Translation - TLBs

Virtual memory Paging

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

CS 318 Principles of Operating Systems

CS 3733 Operating Systems:

Memory Management. Dr. Yingwu Zhu

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

Virtual Memory: From Address Translation to Demand Paging

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

Chapter 8 Memory Management

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

Chapter 8: Memory-Management Strategies

Lecture 8 Memory Management Strategies (chapter 8)

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

Paging: Faster Translations (TLBs)

COS 318: Operating Systems. Virtual Memory and Address Translation

CS399 New Beginnings. Jonathan Walpole

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

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

ECE 571 Advanced Microprocessor-Based Design Lecture 13

Virtual Memory. Virtual Memory

Operating System Labs. Yuanbin Wu

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

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

Memory Management. Dr. Yingwu Zhu

Virtual Memory. Motivation:

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Chapter 7: Main Memory. Operating System Concepts Essentials 8 th Edition

Goals of Memory Management

Virtual memory - Paging

The process. one problem

Virtual Memory: Mechanisms. CS439: Principles of Computer Systems February 28, 2018

Paging: Faster Translations (TLBs)

8.1 Background. Part Four - Memory Management. Chapter 8: Memory-Management Management Strategies. Chapter 8: Memory Management

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

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

Memory Management. Memory Management

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

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

Operating System Labs. Yuanbin Wu

Basic Memory Management

Recall: Address Space Map. 13: Memory Management. Let s be reasonable. Processes Address Space. Send it to disk. Freeing up System Memory

CS307 Operating Systems Main Memory

COSC3330 Computer Architecture Lecture 20. Virtual Memory

CIS Operating Systems Memory Management Address Translation for Paging. Professor Qiang Zeng Spring 2018

ECE 571 Advanced Microprocessor-Based Design Lecture 12

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

1. With respect to space, linked lists are and arrays are.

Chapter 8: Memory Management

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

Chapter 8: Main Memory

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

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

Chapter 9: Memory Management. Background

Chapter 8: Memory- Manage g me m nt n S tra r t a e t gie i s

Chapter 8: Main Memory

CSE 351. Virtual Memory

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

Main Memory: Address Translation

Operating Systems. Designed and Presented by Dr. Ayman Elshenawy Elsefy

Opera&ng Systems ECE344

This training session will cover the Translation Look aside Buffer or TLB

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Computer Science 146. Computer Architecture

Memory Management. Memory

Chapter 8: Memory- Management Strategies. Operating System Concepts 9 th Edition

Main Memory (Fig. 7.13) Main Memory

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

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

Transcription:

Virtual Memory 2 Today Handling bigger address spaces Speeding translation

Considerations with page tables Two key issues with page tables Mapping must be fast Done on every memory reference, at least 1 per instruction With large address spaces, large page tables 32b addresses, 4KB page 12b offset, 2b page number ~ 1 million PTE (2 2 ) 64b addresses & 4KB page 2 52 pages ~ 4.5x1 15!!! 2

Considerations with page tables Two key issues with page tables Mapping must be fast With large address spaces, large page tables Simplest solutions Page table in registers Fast during execution, $$$ & slow to context switch Page table in memory & Page Table Base Register Fast to context switch & cheap, but slow during execution 3

Page table and page sizes Bigger pages Smaller page tables But more internal fragmentation Smaller pages Less internal fragmentation Less unused program in memory But larger page tables more I/O time, getting page from disk seek and rotational delays dominate Getting a bigger page would take as much time 4

Page table and page sizes Avg process size s bytes, page size p bytes Num. of pages needed per process ~ s/p Page table entry size e bytes s/p*e bytes of page table space Overhead = s/p*e + p/2 Internal fragmentation Finding the optimum Take first derivative respect to p, equating it to zero -se/p 2 + 1/2 = p = 2se s = 1MB e = 8 bytes è Optimal p = 4KB 5

Separate instruction & data spaces One address space size limit Pioneered by PDP-11: 2 address spaces, Instruction and Data spaces Double the space Each with its own page table & paging algorithm Single address space 2 32 2 32 I space 2 32 D space (free) Data (free) Data Program Program 6

A hybrid approach Pages & segments As in MULTICS Instead of a single page table, one per segment The base register of the segment points to the base of the page table 32b address 4 segments 4KB pages 31 3 29 28 27 26 25 2423 22 21 2 19 18 17 16 15 14 13 12 11 1 9 8 7 6 5 4 3 2 1 SN VPN Offset But Segmentation is not as flexible as we may want Fragmentation is still an issue Page tables can be of any size, so here we go again 7

Hierarchical or multilevel page table Another approach page the page table! Same argument you don t need the full PT Example Virtual address (32b machine, 4KB page): 2b page # + offset Since PT is paged, divide page #: Page number (1b) + Page offset in 2 nd level (1b) Pros and cons Allocate PT space as needed If carefully done, each portion of PT fits neatly within a page More effort for translation And a bit more complex 8

Hierarchical page table 9 Page table Memory Outerpage table Page table Page of page table Memory Page Table Base Register Page Directory Base Register VPN2 Offset 1 2 3 4 5 6 7 8 9 1 11 12 13 14 15 16 17 18 19 2 21 22 23 24 25 26 27 28 29 3 31 VPN2 Offset 1 2 3 4 5 6 7 8 9 1 11 12 13 14 15 16 17 18 19 2 21 22 23 24 25 26 27 28 29 3 31 VPN1

Three-level page table in Linux Designed to accommodate the 64-bit Alpha To adjust for a 32b processor middle directory of size 1 Virtual address Global directory Middle directory Page Offset Page table Page middle directory + Page size Page directory + + Page frame in physical memory cr3 register + 1

Inverted page tables Another way to save space inverted page tables Page tables are index by virtual page #, hence their size Inverted page tables one entry per page frame But to get the page you are still given a VPN Straightforward with a page table, but Linear with inverted page tables too slow mapping! Traditional page table with an entry per each 2 52 pages 2 52-1 1GB physical memory has 2 18 4KB page frames 2 18-1 Indexed by virtual page 11

Inverted and hashed page tables Slow inverted page tables hash tables may help Since different virtual page number might map to identical hash values a collision-chain mechanism 1GB physical memory has 2 18 4KB page frames 2 18-1 2 18-1 Hash table Indexed by hash on virtual page Virtual page page frame And of course caching, a.k.a. TLB 12

And now a short break Before the Internet - xkcd 13

Speeding things up a bit Simple page table 2x cost of memory lookups First into page table, a second to fetch the data Two-level page tables triple the cost! Two lookups into page table and then fetch the data And two is not enough How can we make this more efficient? 14

Speeding things up a bit Ideally, make fetching from a virtual address almost as efficient as from a physical address Observation locality of references (lot of references to few pages) Solution hardware cache inside the CPU Translation Lookaside Buffer (TLB) Cache the virtual-to-physical translations in HW A better name would be address-translation cache Traditionally managed by the MMU 15

TLBs Translates virtual page #s into page frame #s Can be done in single machine cycle Implemented in hardware A fully associative cache (parallel search) Cache tags are virtual page numbers Cache values are page frame numbers With this + offset, MMU can calculate physical address A typical TLB entry might look like this VPN PFN Other bits 16

TLBs hit VPN = (VirtAddr * VPN_MASK) >> SHIFT (Success, TlbEntry) = TLB_Lookup(VPN) If (Success == True) // TLB Hit if (CanAccess(TlbEntry.ProtectBits) == True) Offset = VirtAddr & OFFSET_MASK PhysAddr = (TlbEntry.PFN << SHIFT) Offset Register = AccessMemory(PhysAddr) else RaiseException(PROTECTION_FAULT) CPU Logical address Page # Frame # TLB hit Physical address Physical memory 17

TLBs miss else // TLB Miss PTEAddr = PTBR + (VPN * sizeof(pte)) PTE = AccessMemory(PTEAddr) if (PTE.Valid == False) RaiseException(SEGMENTATION_FAULT) else TLB_Insert(VPN, PTE.PFN, PTE.ProtectBits) RetryInstruction() Logical address CPU Page # Frame # TLB hit Physical address Physical memory TLB miss --- --- f --- --- --- Page table 18

Managing TLBs Address translations mostly handled by TLB >99% of translations, but there are TLB misses If a miss, translation is placed into the TLB Who manages the TLB miss? Hardware, the memory management unit MMU Knows where page tables are in memory OS maintains them, HW access them directly E.g., Intel x86 19

Managing TLBs Software TLB management E.g. MIPS R1k, Sun s SPARC v9 Idea OS loads TLB On a TLB miss, faults to OS OS finds page table entry removes an entry from TLB enter new one restart instruction Must be fast CPU ISA has instructions for TLB manipulation OS gets to pick the page table format 2

Managing TLBs OS must ensure TLB and page tables are consistent When OS changes protection bits in an entry, it needs to invalidate the line if it is in the TLB When the TLB misses, and a new process table entry is loaded, a cached entry must be evicted How to choose a victim is called TLB replacement policy Implemented in hardware, usually simple (e.g., LRU) Could you have a TLB miss and still have the referenced page in memory? Yes, that s a soft miss ; all that s needed is to update TLB 21

Managing TLBs What happens on a process context switch? Need to invalidate all the entries in TLB! (flush) A big part of why process context switches are costly Can you think of a hardware fix to this? Add an Address Space Identifier field to the TLB 22

An example TLB From MIPS R4 software-managed TLB 32b address space with 4KB pages 2b VPN and 12b offset But TLB has only 19b for VPN! User addresses will only come from half the address space the rest is for the kernel So 19b is enough VPN ASID 1 2 3 4 5 6 7 8 9 1 11 12 13 14 15 16 17 18 19 2 21 22 23 24 25 26 27 28 29 3 31 G C D V PFN 23

An example TLB VPN translates to up to a 24b physical frame number and can thus support systems with up to 64GB of physical memory How is that?! G is for pages globally shared (so ASID is ignored) C is for coherence; D is for dirty and V is for valid Since it is software managed, OS needs instructions to manipulate it TLBP probes TLBR reads TLBWI and TLBWR to replaces a specific or a random entry 24

Effective access time Associative Lookup = ε time units Hit ratio - α - percentage of times that a page number is found in the associative registers (ratio related to TLB size) Effective Memory Access Time (EAT) TLB hit EAT = α * (ε + memory-access) + TLB miss (1 - α) (ε + 2* memory-access) Why 2? α = 8% ε = 2 nsec memory-access = 1 nsec EAT =.8 * (2 + 1) +.2 * (2 + 2 * 1) = 14 nsec 25

Next time Virtual memory policies Some other design issues 26