Virtual Memory. Today. Handling bigger address spaces Speeding translation

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

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

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

Virtual Memory. Yannis Smaragdakis, U. Athens

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

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

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

CS 550 Operating Systems Spring Memory Management: Paging

CS 153 Design of Operating Systems Winter 2016

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

20. Paging: Smaller Tables

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

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

Main Memory (Part II)

Virtual to physical address translation

Beyond Physical Memory: Mechanisms

CSE 120 Principles of Operating Systems Spring 2017

Chapter 8 Main Memory

CSE 120 Principles of Operating Systems

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

CS3600 SYSTEMS AND NETWORKS

Virtual Memory. Samira Khan Apr 27, 2017

Memory Management. Dr. Yingwu Zhu

Paging: Smaller Tables

CS 537 Lecture 6 Fast Translation - TLBs

CS 3733 Operating Systems:

CS 318 Principles of Operating Systems

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

CS370 Operating Systems

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

Virtual memory - Paging

The process. one problem

Virtual memory Paging

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

Paging: Faster Translations (TLBs)

Virtual Memory. Kevin Webb Swarthmore College March 8, 2018

ECE 571 Advanced Microprocessor-Based Design Lecture 13

Virtual Memory: From Address Translation to Demand Paging

CHAPTER 8 - MEMORY MANAGEMENT STRATEGIES

CS399 New Beginnings. Jonathan Walpole

Chapter 8: Memory-Management Strategies

Memory Management. Dr. Yingwu Zhu

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

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

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

Chapter 9 Memory Management

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

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

Goals of Memory Management

Chapter 8 Memory Management

Paging: Faster Translations (TLBs)

Lecture 8 Memory Management Strategies (chapter 8)

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

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

Operating System Labs. Yuanbin Wu

CS307 Operating Systems Main Memory

Memory Management. Memory Management

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Operating System Labs. Yuanbin Wu

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

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

ECE 571 Advanced Microprocessor-Based Design Lecture 12

Chapter 8: Memory Management

Chapter 9: Memory Management. Background

CS 5523 Operating Systems: Memory Management (SGG-8)

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

Virtual Memory: From Address Translation to Demand Paging

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

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

Chapter 8: Main Memory

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

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

Virtual Memory. Motivation:

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

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

Memory Management. Memory

16 Sharing Main Memory Segmentation and Paging

Virtual Memory. Virtual Memory

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Chapter 8: Main Memory

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

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

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

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

COS 318: Operating Systems. Virtual Memory and Address Translation

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

Chapter 8: Main Memory

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

Page Tables. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

CS307: Operating Systems

SMD149 - Operating Systems - Memory

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

Opera&ng Systems ECE344

CPS 104 Computer Organization and Programming Lecture 20: Virtual Memory

Main Memory. CISC3595, Spring 2015 X. Zhang Fordham University

CS3350B Computer Architecture

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

Transcription:

Virtual Memory 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, page tables will be large 32 bit addresses & 4KB page 12 bit offset, 2 bit page # ~ 1million PTE (2 2 ) 64 bit addresses & 4KB page 2 52 pages ~ 4.5x1 15!!! Simplest solutions Page table in registers Fast during execution, $$$ & slow to context switch Page table in memory & Page Table Base Register (PTBR) Fast to context switch & cheap, but slow during execution 2

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 more I/O time, getting page from disk most of the time goes into seek and rotational delay! Larger page tables 3

Page table and page sizes Average process size s bytes Page size p bytes Page entry size e bytes Approximate number of pages needed per process s/p occupying s/p*e bytes of page table space overhead = se / p + p/2 Taking first derivative respect to p and equating it to zero -s e / p 2 + 1/2 = p = 2se Internal fragmentation s = 1MB e = 8 bytes è Optimal p = 4KB 4

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 5

A hybrid approach pages and segments As 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 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 Offset 6

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

Hierarchical page table 8 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 32-bit proc. middle directory of size 1 Virtual address Global directory Middle directory Page table Offset Page table Page middle directory + Page size Page directory + + Page frame in physical memory cr3 register + 9

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 1

Inverted and hashed page tables Slow inverted page tables hash tables may help Different virtual page number might map to identical hash values use a collision-chain mechanism Problem poor cache locality 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 Also Translation Lookaside Buffers (TLB) 11

And now a short break 12

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? 13

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 Cache the virtual-to-physical translations in the hardware A better name would be address-translation cache Traditionally managed by the MMU 14

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 15

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 16

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 17

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 (memory management unit MMU) Knows where page tables are in memory OS maintains them, HW access them directly E.g., Intel x86 Software loaded TLB (OS) TLB miss faults to OS, OS finds page table entry & loads TLB Must be fast CPU ISA has instructions for TLB manipulation OS gets to pick the page table format E.g. MIPS R1k, Sun s SPARC v9 18

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) 19

Managing TLBs What happens on a process context switch? Remember, each process typically has its own page tables Need to invalidate all the entries in TLB! (flush TLB) 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 2

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 21

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 22

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 23

Next time Virtual memory policies Some other design issues 24