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

Similar documents
CS399 New Beginnings. Jonathan Walpole

CS399 New Beginnings. Jonathan Walpole

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

Memory Management. Goals of Memory Management. Mechanism. Policies

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

Virtual to physical address translation

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

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

Virtual Memory: From Address Translation to Demand Paging

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

Chapter 4 Memory Management

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

DAT (cont d) Assume a page size of 256 bytes. physical addresses. Note: Virtual address (page #) is not stored, but is used as an index into the table

ECE232: Hardware Organization and Design

Memory Management. Dr. Yingwu Zhu

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

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

Memory Management. Dr. Yingwu Zhu

21 Lecture: More VM Announcements From last time: Virtual Memory (Fotheringham, 1961)

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

CSE 120 Principles of Operating Systems Spring 2017

Computer Architecture. R. Poss

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

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

VIRTUAL MEMORY II. Jo, Heeseung

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

Memory Management. Chapter 4 Memory Management. Multiprogramming with Fixed Partitions. Ideally programmers want memory that is.

CS 318 Principles of Operating Systems

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

ADDRESS TRANSLATION AND TLB

Address Translation. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

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

ADDRESS TRANSLATION AND TLB

CS510 Operating System Foundations. Jonathan Walpole

Virtual Memory: From Address Translation to Demand Paging

CSE 120 Principles of Operating Systems

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

Chapter 3 - Memory Management

Memory Management - Demand Paging and Multi-level Page Tables

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

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

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

Virtual Memory - Objectives

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

CS307 Operating Systems Main Memory

Modeling Page Replacement: Stack Algorithms. Design Issues for Paging Systems

Pipelined processors and Hazards

CPE300: Digital System Architecture and Design

Readings and References. Virtual Memory. Virtual Memory. Virtual Memory VPN. Reading. CSE Computer Systems December 5, 2001.

CS 153 Design of Operating Systems Winter 2016

CS 333 Introduction to Operating Systems Class 2 OS-Related Hardware & Software The Process Concept

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

CS 153 Design of Operating Systems Winter 2016

Virtual Memory. Today. Handling bigger address spaces Speeding translation

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

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time.

16 Sharing Main Memory Segmentation and Paging

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

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

CS 61C: Great Ideas in Computer Architecture. Lecture 23: Virtual Memory. Bernhard Boser & Randy Katz

2-Level Page Tables. Virtual Address Space: 2 32 bytes. Offset or Displacement field in VA: 12 bits

Main Memory (Fig. 7.13) Main Memory

Lecture 21: Virtual Memory. Spring 2018 Jason Tang

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

Page 1. Review: Address Segmentation " Review: Address Segmentation " Review: Address Segmentation "

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

CS3600 SYSTEMS AND NETWORKS

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

Random-Access Memory (RAM) Systemprogrammering 2007 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics

Virtual Memory. Virtual Memory

ECE 571 Advanced Microprocessor-Based Design Lecture 12

Performance of Various Levels of Storage. Movement between levels of storage hierarchy can be explicit or implicit

Memory Management Topics. CS 537 Lecture 11 Memory. Virtualizing Resources

Random-Access Memory (RAM) Systemprogrammering 2009 Föreläsning 4 Virtual Memory. Locality. The CPU-Memory Gap. Topics! The memory hierarchy

Memory Management (2)

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

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

CS 3733 Operating Systems:

15 Sharing Main Memory Segmentation and Paging

Computer Architecture. Lecture 8: Virtual Memory

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

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

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

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

Chapter 4 Memory Management. Memory Management

CS307: Operating Systems

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

Computer Systems. Virtual Memory. Han, Hwansoo

John Wawrzynek & Nick Weaver

Virtual Memory. Motivation:

CSE 4/521 Introduction to Operating Systems. Lecture 14 Main Memory III (Paging, Structure of Page Table) Summer 2018

Page 1. Goals for Today" TLB organization" CS162 Operating Systems and Systems Programming Lecture 11. Page Allocation and Replacement"

Processes and Tasks What comprises the state of a running program (a process or task)?

Modern Virtual Memory Systems. Modern Virtual Memory Systems

CS370 Operating Systems

Processes and Virtual Memory Concepts

Translation Buffers (TLB s)

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

ECE 571 Advanced Microprocessor-Based Design Lecture 13

Chapter 8 Memory Management

Transcription:

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

Virtual addresses Virtual memory addresses (what the process uses) Page number plus byte offset in page Low order n bits are the byte offset Remaining high order bits are the page number bit 31 bit n-1 bit 2 bits 12 bits page number offset Example: 32 bit virtual address Page size = 2 12 = 4KB Address space size = 2 32 bytes = 4GB

Physical addresses Physical memory addresses (what memory uses) Page frame number plus byte offset in page Low order n bits are the byte offset Remaining high order bits are the page bit 24 bit n-1 bit 12 bits 12 bits Page offset Example: 24 bit physical address Page frame size = 2 12 = 4KB Max physical memory size = 2 24 bytes = 16MB

Address translation Complete set of address mappings for a process are stored in a page table in memory But accessing the table for every address translation is too expensive So hardware support is used to map page numbers to s at full CPU speed Memory management unit (MMU) has multiple registers for multiple pages and knows how to access page tables Also called a translation look aside buffer (TLB) Essentially a cache of page table entries

The BLITZ architecture The page table mapping: Page --> Frame Virtual Address (24 bit in Blitz): 23 11 bits Physical Address (32 bit in Blitz): 31 19 bits

The BLITZ page table An array of page table entries Kept in memory 2 11 pages in a virtual address space ---> 2K entries in the table Each entry is 4 bytes long 19 bits The Frame Number 1 bit Valid Bit 1 bit Writable Bit 1 bit Dirty Bit 1 bit Referenced Bit 9 bits Unused (and available for OS algorithms)

The BLITZ page table Two page table related registers in the CPU Page Table Base Register Page Table Length Register These define the page table for the current process Must be saved and restored on process context switch Bits in the CPU status register System Mode Interrupts Enabled Paging Enabled 1 = Perform page table translation for every memory access = Do not do translation

The BLITZ page table A page table entry 31 19 bits dirty bit referenced bit writable bit valid bit

The BLITZ page table The full page table page table base register 1 2 2K 31 Indexed by the page number

The BLITZ page table 23 page number offset page table base register virtual address 1 2 2K 31

The BLITZ page table 23 page number offset page table base register virtual address 1 2 2K 31 31 physical address

The BLITZ page table 23 page number offset page table base register virtual address 1 2 2K 31 31 offset physical address

The BLITZ page table 23 page number offset page table base register virtual address 1 2 2K 31 31 offset physical address

The BLITZ page table 23 page number offset page table base register virtual address 1 2 2K 31 31 offset physical address

Page tables When and why do we access a page table? On every instruction to translate virtual to physical addresses?

Page tables When and why do we access a page table? On every instruction to translate virtual to physical addresses? NO! In real machines it is only accessed On TLB miss faults to refill the TLB During process creation and destruction When a process allocates or frees memory?

Translation Lookaside Buffer (TLB) Problem: MMU can t go to page table on every memory access!

Translation Lookaside Buffer (TLB) Problem: MMU can t go to page table on every memory access! Solution: Cache the page table entries in a hardware cache Small number of entries (e.g., 64) Each entry contains Page number Other stuff from page table entry Associatively indexed on page number (ie. You can do a lookup in a single cycle)

Translation lookaside buffer CPU p o page # frame # TLB Hit Physical memory f o TLB Page Table

Hardware operation of TLB Key Page Number 23 17 92 5 12 Frame Number Other 37 5 24 19 6

Hardware operation of TLB 23 virtual address page number offset Key Page Number 23 17 92 5 12 Frame Number Other 37 5 24 19 6 31 offset physical address

Hardware operation of TLB 23 virtual address page number offset Key Page Number 23 17 92 5 12 Frame Number Other 37 5 24 19 6 31 offset physical address

Hardware operation of TLB 23 virtual address page number offset Key Page Number 23 17 92 5 12 Frame Number Other 37 5 24 19 6 31 offset physical address

Hardware operation of TLB 23 virtual address page number offset Key Page Number 23 17 92 5 12 Frame Number Other 37 5 24 19 6 31 offset physical address

Hardware operation of TLB 23 virtual address page number offset Key Page Number 23 17 92 5 12 Frame Number Other 37 5 24 19 6 31 offset physical address

Software operation of TLB What if the entry is not in the TLB? Go look in the page table in memory Find the right entry Move it into the TLB But which TLB entry should be replaced?

Software operation of TLB Hardware TLB refill Page tables in specific location and format TLB hardware handles its own misses Replacement policy fixed by hardware Software refill Hardware generates trap (TLB miss fault) Lets the OS deal with the problem Page tables become entirely a OS data structure! Replacement policy managed in software

Software operation of TLB What should we do with the TLB on a context switch? How can we prevent the next process from using the last process s address mappings? Option 1: empty the TLB New process will generate faults until its pulls enough of its own entries into the TLB Option 2: just clear the Valid Bit New process will generate faults until its pulls enough of its own entries into the TLB Option 3: the hardware maintains a process id tag on each TLB entry Hardware compares this to a process id held in a specific register on every translation

Page tables Do we access a page table when a process allocates or frees memory?

Page tables Do we access a page table when a process allocates or frees memory? Not necessarily Library routines (malloc) can service small requests from a pool of free memory already allocated within a process address space When these routines run out of space a new page must be allocated and its entry inserted into the page table This allocation is requested using a system call

Page table design issues Page table size depends on Page size Virtual address length Memory used for page tables is overhead! How can we save space? and still find entries quickly? Three options Single-level page tables Multi-level page tables Inverted page tables

Single-level page tables A Virtual Address (32 bit): 2-bits 12-bits page number offset Single-level page table frames in memory

Single-level page tables 2-bits page number 12-bits offset Single-level page table frames in memory

Single-level page tables 2-bits page number 12-bits offset Single-level page table frames in memory Problem: requires one page table entry per virtual page!

Single-level page tables 2-bits page number 12-bits offset Single-level page table frames in memory 32 bit addresses and 4KB pages means 2 2 page table entries per process

Multi-level page tables frames in memory Top-level Page table 2nd-level tables

Multi-level page tables A Virtual Address: 1-bits 1-bits 12-bits PT1 PT2 offset frames in memory Top-level Page table 2nd-level tables

Multi-level page tables A Virtual Address: 1-bits 1-bits 12-bits PT1 PT2 offset frames in memory Top-level Page table 2nd-level tables

Multi-level page tables A Virtual Address: 1-bits 1-bits 12-bits PT1 PT2 offset frames in memory Top-level Page table 2nd-level tables

Multi-level page tables A Virtual Address: 1-bits 1-bits 12-bits PT1 PT2 offset frames in memory Top-level Page table 2nd-level tables

Multi-level page tables A Virtual Address: 1-bits 1-bits 12-bits PT1 PT2 offset frames in memory Top-level Page table 2nd-level tables

Multi-level page tables A Virtual Address: 1-bits 1-bits 12-bits PT1 PT2 offset frames in memory Top-level Page table 2nd-level tables

Multi-level page tables Ok, but how exactly does this save space?

Multi-level page tables Ok, but how exactly does this save space? Not all pages within a virtual address space are allocated Not only do they not have a page frame, but that range of virtual addresses is not being used So no need to maintain complete information about it Some intermediate page tables are empty and not needed We could also page the page table This saves space but slows access a lot!

VM puzzle