CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.

Similar documents
Lecture 17: Virtual Memory II. Goals of virtual memory

Virtual vs Physical Addresses

W4118: segmentation and paging. Instructor: Junfeng Yang

COS 318: Operating Systems. Virtual Memory and Address Translation

This Unit: Virtual Memory. CIS 501 Computer Architecture. Readings. A Computer System: Hardware

CS5460: Operating Systems

Virtualization. Types of Interfaces

Memory Management Outline. Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging

Memory management basics (1) Requirements (1) Objectives. Operating Systems Part of E1.9 - Principles of Computers and Software Engineering

Virtualization in Linux KVM + QEMU

Operating Systems, 6 th ed. Test Bank Chapter 7

Uses for Virtual Machines. Virtual Machines. There are several uses for virtual machines:

Board Notes on Virtual Memory

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

Introduction. What is an Operating System?

Outline: Operating Systems

& Data Processing 2. Exercise 3: Memory Management. Dipl.-Ing. Bogdan Marin. Universität Duisburg-Essen

Hypervisor: Requirement Document (Version 3)

OpenSPARC T1 Processor

Memory management. Chapter 4: Memory Management. Memory hierarchy. In an ideal world. Basic memory management. Fixed partitions: multiple programs

Chapter 11 I/O Management and Disk Scheduling

Page 1 of 5. IS 335: Information Technology in Business Lecture Outline Operating Systems

CS5460: Operating Systems. Lecture: Virtualization 2. Anton Burtsev March, 2013

I/O. Input/Output. Types of devices. Interface. Computer hardware

Virtualization. Pradipta De

Virtualization. Jia Rao Assistant Professor in CS

Virtual Memory. How is it possible for each process to have contiguous addresses and so many of them? A System Using Virtual Addressing

Introduction to Virtual Machines

Virtual Machines. COMP 3361: Operating Systems I Winter

OPERATING SYSTEMS MEMORY MANAGEMENT

Intel s Virtualization Extensions (VT-x) So you want to build a hypervisor?

Chapter 10: Virtual Memory. Lesson 03: Page tables and address translation process using page tables

We r e going to play Final (exam) Jeopardy! "Answers:" "Questions:" - 1 -

CS 695 Topics in Virtualization and Cloud Computing. More Introduction + Processor Virtualization

Intel P6 Systemprogrammering 2007 Föreläsning 5 P6/Linux Memory System

How To Write A Page Table

How To Improve Performance On A Single Chip Computer

CSC 2405: Computer Systems II

Chapter 7 Memory Management

361 Computer Architecture Lecture 14: Cache Memory

Virtual Memory. Virtual Memory. Paging. CSE 380 Computer Operating Systems. Paging (1)

Full and Para Virtualization

System Virtual Machines

CS161: Operating Systems

Introduction to Virtual Machines

Virtualization. Explain how today s virtualization movement is actually a reinvention

COS 318: Operating Systems. Virtual Machine Monitors

6.033 Computer System Engineering

Microkernels, virtualization, exokernels. Tutorial 1 CSC469

Virtualization Technology. Zhiming Shen

File Management. Chapter 12

Chapter 1 Computer System Overview

1. Computer System Structure and Components

Chapter 5 Cloud Resource Virtualization

Operating System Overview. Otto J. Anshus

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Hardware Based Virtualization Technologies. Elsie Wahlig Platform Software Architect

Computer Architecture

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

Operating Systems CSE 410, Spring File Management. Stephen Wagner Michigan State University

Origins of Operating Systems OS/360. Martin Grund HPI

Chapter 3 Operating-System Structures

IOMMU: A Detailed view

Chapter 12. Paging an Virtual Memory Systems

1 Storage Devices Summary

Chapter 2: OS Overview

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

Virtuoso and Database Scalability

Windows Server Performance Monitoring

Application Note 195. ARM11 performance monitor unit. Document number: ARM DAI 195B Issued: 15th February, 2008 Copyright ARM Limited 2007

Outline. Outline. Why virtualization? Why not virtualize? Today s data center. Cloud computing. Virtual resource pool

The Xen of Virtualization

Price/performance Modern Memory Hierarchy

This Unit: Main Memory. CIS 501 Introduction to Computer Architecture. Memory Hierarchy Review. Readings

Introduction to RISC Processor. ni logic Pvt. Ltd., Pune

OSes. Arvind Seshadri Mark Luk Ning Qu Adrian Perrig SOSP2007. CyLab of CMU. SecVisor: A Tiny Hypervisor to Provide

ARM Virtualization: CPU & MMU Issues

Lesson Objectives. To provide a grand tour of the major operating systems components To provide coverage of basic computer system organization

A Unified View of Virtual Machines

matasano Hardware Virtualization Rootkits Dino A. Dai Zovi

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

Computer Organization and Architecture. Characteristics of Memory Systems. Chapter 4 Cache Memory. Location CPU Registers and control unit memory

Virtual Memory Paging

Memory Management CS 217. Two programs can t control all of memory simultaneously

Chapter 16: Virtual Machines. Operating System Concepts 9 th Edition

The Quest for Speed - Memory. Cache Memory. A Solution: Memory Hierarchy. Memory Hierarchy

OPERATING SYSTEM - MEMORY MANAGEMENT

Computer Architecture Prof. Mainak Chaudhuri Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Storage. The text highlighted in green in these slides contain external hyperlinks. 1 / 14

W4118 Operating Systems. Instructor: Junfeng Yang

Intel Virtualization Technology Overview Yu Ke

Virtualization in the ARMv7 Architecture Lecture for the Embedded Systems Course CSD, University of Crete (May 20, 2014)

Midterm Exam #2 Solutions November 10, 1999 CS162 Operating Systems

Paging: Introduction A Simple Example And Overview

COS 318: Operating Systems

Virtualization. Dr. Yingwu Zhu

kvm: Kernel-based Virtual Machine for Linux

COSC 6374 Parallel Computation. Parallel I/O (I) I/O basics. Concept of a clusters

Using Linux as Hypervisor with KVM

Lecture 16: Storage Devices

Transcription:

CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont. Instructors: Vladimir Stojanovic & Nicholas Weaver http://inst.eecs.berkeley.edu/~cs61c/ 1

Bare 5-Stage Pipeline Physical Address PC Inst. Cache D Decode E + M Physical Address Data Cache W Physical Address Memory Controller Physical Address Physical Address Main Memory (DRAM) In a bare machine, the only kind of address is a physical address 2

Address Translation So, what do we want to achieve at the hardware level? Take a Virtual Address, that points to a spot in the Virtual Address Space of a particular program, and map it to a Physical Address, which points to a physical spot in DRAM of the whole machine Virtual Address Virtual Page Number Offset Physical Address PhysicalPage Number Offset 3

Address Translation Virtual Address Virtual Page Number Offset Address Translation Copy Bits Physical Address PhysicalPage Number Offset The rest of the lecture is all about implementing 4

Paged Memory Systems Processor-generated address can be split into: Virtual Page Number Offset A page table contains the physical address of the base of each page 1 0 1 2 3 0 1 2 3 0 3 Physical Memory Address Space of Program #1 Page Table of Program #1 2 Page tables make it possible to store the pages of a program non-contiguously. 5

Private (Virtual) Address Space per Program Prog 1 VA1 Page Table OS pages Prog 2 Prog 3 VA1 VA1 Page Table Physical Memory Page Table free Each prog has a page table Page table contains an entry for each prog page Physical Memory acts like a cache of pages for currently running programs. Not recently used pages are stored in secondary memory, e.g. disk (in swap partition ) 6

Where Should Page Tables Reside? Space required by the page tables (PT) is proportional to the address space, number of users,... Þ Too large to keep in registers inside CPU Idea: Keep page tables in the main memory Needs one reference to retrieve the page base address and another to access the data word Þ doubles the number of memory references! (but we can fix this using something we already know about ) 7

Page Tables in Physical Memory PT Prog1 VA1 Prog 1 Virtual Address Space VA1 PT Prog2 Physical Memory Prog 2 Virtual Address Space 8

Linear (simple) Page Table Page Table Entry (PTE) contains: 1 bit to indicate if page exists And either PPN or DPN: PPN (physical page number) for a memory-resident page DPN (disk page number) for a page on the disk Status bits for protection and usage (read, write, exec) OS sets the Page Table Base Register whenever active user process changes DPN PPN PPN PT Base Register Page Table PPN PPN DPN PPN DPN PPN PPN DPN DPN Offset VPN VPN Offset Virtual address Data Pages Data word 9

Suppose an instruction references a memory page that isn t in DRAM? We get an exception of type page fault Page fault handler does the following: If virtual page doesn t yet exist, assign an unused page in DRAM, or if page exists Initiate transfer of the page we re requesting from disk to DRAM, assigning to an unused page If no unused page is left, a page currently in DRAM is selected to be replaced (based on usage) The replaced page is written (back) to disk, page table entry that maps that VPN->PPN is marked as invalid/dpn Page table entry of the page we re requesting is updated with a (now) valid PPN 10

Size of Linear Page Table With 32-bit memory addresses, 4-KiB pages: Þ 2 32 / 2 12 = 2 20 virtual pages per user, assuming 4-Byte PTEs, Þ 2 20 PTEs, i.e, 4 MiB page table per user! Larger pages? Internal fragmentation (Not all memory in page gets used) Larger page fault penalty (more time to read from disk) What about 64-bit virtual address space??? Even 1MiB pages would require 2 44 8-Byte PTEs (128 TiB!) What is the saving grace? Most processes only use a set of high address (stack), and a set of low address (instructions, heap) 11

Hierarchical Page Table exploits sparsity of virtual address space use Virtual Address 31 22 21 12 11 p1 p2 offset 0 10-bit L1 index Root of the Current Page Table (Processor Register) 10-bit L2 index p1 Level 1 Page Table p2 Physical Memory page in primary memory page in secondary memory PTE of a nonexistent page Level 2 Page Tables Data Pages 12

MT2 Grades 59% 13

Administrivia Upcoming Lecture Schedule 04/18: VM (today) 04/20: I/O: DMA, Disks 04/22: Networking 04/25: Dependability: Parity, ECC (+ HKN reviews) 04/27: RAID Last day of new material 04/29: Summary, What s Next? 14

Administrivia Project 4 programming competition rules posted Project 5 released due on 4/26 Guerrilla Session: Virtual Memory Wed 4/20 3-5 PM @ 241 Cory Sat 4/22 1-3 PM @ 521 Cory Last HW (3) Virtual Memory Due 05/01 15

Address Translation & Protection Kernel/User Mode Virtual Address Virtual Page No. (VPN) offset Read/Write Protection Check Address Translation Exception? Physical Address Physical Page No. (PPN) offset Every instruction and data access needs address translation and protection checks A good VM design needs to be fast (~ one cycle) and space efficient 16

Translation Lookaside Buffers (TLB) Address translation is very expensive! In a two-level page table, each reference becomes several memory accesses Solution: Cache some translations in TLB TLB hit Þ Single-Cycle Translation TLB miss Þ Page-Table Walk to refill virtual address VPN offset V R W D tag PPN (VPN = virtual page number) (PPN = physical page number) hit? physical address PPN offset 17

TLB Designs Typically 32-128 entries, usually fully associative Each entry maps a large page, hence less spatial locality across pages => more likely that two entries conflict Sometimes larger TLBs (256-512 entries) are 4-8 way setassociative Larger systems sometimes have multi-level (L1 and L2) TLBs Random or FIFO replacement policy TLB Reach : Size of largest virtual address space that can be simultaneously mapped by TLB Example: 64 TLB entries, 4KiB pages, one page per entry TLB Reach =? 18

VM-related events in pipeline PC Inst TLB Inst. Cache D Decode E + M Data TLB Data Cache W TLB miss? Page Fault? Protection violation? TLB miss? Page Fault? Protection violation? Handling a TLB miss needs a hardware or software mechanism to refill TLB usually done in hardware now Handling a page fault (e.g., page is on disk) needs a precise trap so software handler can easily resume after retrieving page Handling protection violation may abort process 19

Hierarchical Page Table Walk: SPARC v8 Virtual Address Context Table Register Context Register Context Table root ptr Index 1 Index 2 Index 3 Offset 31 23 17 11 0 L1 Table PTP L2 Table PTP L3 Table PTE 31 11 0 Physical Address PPN Offset MMU does this table walk in hardware on a TLB miss 20

Page-Based Virtual-Memory Machine (Hardware Page-Table Walk) Page Fault? Protection violation? Virtual Address PC Inst. TLB Physical Address Inst. Cache D Decode E + M Page Fault? Protection violation? Virtual Address Data TLB Physical Address Data Cache W Miss? P Register Miss? Hardware Page Table Walker Physical Address Memory Controller Main Memory (DRAM) Physical Address Physical Address Assumes page tables held in untranslated physical memory 21

Address Translation: putting it all together Virtual Address TLB Lookup hardware hardware or software software miss hit Page Table Walk Protection Check the page is Ï memory Î memory denied permitted Page Fault (OS loads page) Where? Update TLB Protection Fault SEGFAULT Physical Address (to cache) 22

Modern Virtual Memory Systems Illusion of a large, private, uniform store Protection & Privacy several users, each with their private address space and one or more shared address spaces page table ºname space Demand Paging Provides the ability to run programs larger than the primary memory OS user i Swapping Store (Disk) Primary Memory Hides differences in machine configurations The price is address translation on each memory reference VA mapping TLB PA 23

Clicker Question Let s try to extrapolate from caches Which one is false? A. # offset bits in V.A. = log 2 (page size) B. # offset bits in P.A. = log 2 (page size) C. # VPN bits in V.A. = log 2 (# of physical pages) D. # PPN bits in P.A. = log 2 (# of physical pages) E. A single-level page table contains a PTE for every possible VPN in the system 24

Conclusion: VM features track historical uses Bare machine, only physical addresses One program owned entire machine Batch-style multiprogramming Several programs sharing CPU while waiting for I/O Base & bound: translation and protection between programs (not virtual memory) Problem with external fragmentation (holes in memory), needed occasional memory defragmentation as new jobs arrived 25

Conclusion: VM features track historical uses Time sharing More interactive programs, waiting for user. Also, more jobs/second. Motivated move to fixed-size page translation and protection, no external fragmentation (but now internal fragmentation, wasted bytes in page) Motivated adoption of virtual memory to allow more jobs to share limited physical memory resources while holding working set in memory Virtual Machine Monitors Run multiple operating systems on one machine Idea from 1970s IBM mainframes, now common on laptops e.g., run Windows on top of Mac OS X Hardware support for two levels of translation/protection Guest OS virtual -> Guest OS physical -> Host machine physical Also basis of Cloud Computing Virtual machine instances on EC2 26