COMP303 Computer Architecture Lecture 16. Virtual Memory

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

Board Notes on Virtual Memory

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

COS 318: Operating Systems. Virtual Memory and Address Translation

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

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

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

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

Virtual vs Physical Addresses

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

361 Computer Architecture Lecture 14: Cache Memory

W4118: segmentation and paging. Instructor: Junfeng Yang

Memory ICS 233. Computer Architecture and Assembly Language Prof. Muhamed Mudawar

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

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

COMPUTER ORGANIZATION ARCHITECTURES FOR EMBEDDED COMPUTING

Addendum Intel Architecture Software Developer s Manual

Chapter 1 Computer System Overview

18-548/ Associativity 9/16/98. 7 Associativity / Memory System Architecture Philip Koopman September 16, 1998

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

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

Slide Set 8. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng

CS/COE1541: Introduction to Computer Architecture. Memory hierarchy. Sangyeun Cho. Computer Science Department University of Pittsburgh

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

Operating Systems, 6 th ed. Test Bank Chapter 7

Computer Architecture

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

StrongARM** SA-110 Microprocessor Instruction Timing

Computer Architecture Lecture 2: Instruction Set Principles (Appendix A) Chih Wei Liu 劉 志 尉 National Chiao Tung University

Operating System Overview. Otto J. Anshus

An Introduction to the ARM 7 Architecture

VIRTUAL MEMORY IN CONTEMPORARY MICROPROCESSORS

Memory Hierarchy. Arquitectura de Computadoras. Centro de Investigación n y de Estudios Avanzados del IPN. adiaz@cinvestav.mx. MemoryHierarchy- 1

CS5460: Operating Systems

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

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-12: ARM

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

Virtual Memory Paging

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

Operating Systems. Virtual Memory

Main Memory. Memories. Hauptspeicher. SIMM: single inline memory module 72 Pins. DIMM: dual inline memory module 168 Pins

Intel StrongARM SA-110 Microprocessor

4.1 PAGING MODES AND CONTROL BITS

Hypervisor: Requirement Document (Version 3)

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

OPENSPARC T1 OVERVIEW

Chapter 10: Virtual Memory. Lesson 08: Demand Paging and Page Swapping

WHITE PAPER. AMD-V Nested Paging. AMD-V Nested Paging. Issue Date: July, 2008 Revision: 1.0. Advanced Micro Devices, Inc.

Intel 8086 architecture

INSTRUCTION LEVEL PARALLELISM PART VII: REORDER BUFFER

Outline: Operating Systems

Bindel, Spring 2010 Applications of Parallel Computers (CS 5220) Week 1: Wednesday, Jan 27

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

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

How To Write A Page Table

Chapter 12. Paging an Virtual Memory Systems

Computer-System Architecture

Chapter 2: Computer-System Structures. Computer System Operation Storage Structure Storage Hierarchy Hardware Protection General System Architecture

Buffer Management 5. Buffer Management

How To Write To A Linux Memory Map On A Microsoft Zseries (Amd64) On A Linux (Amd32) (

OpenSPARC T1 Processor

Lecture 3: Modern GPUs A Hardware Perspective Mohamed Zahran (aka Z) mzahran@cs.nyu.edu

Computer Organization and Components

Operating Systems. Lecture 03. February 11, 2013

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

Why Latency Lags Bandwidth, and What it Means to Computing

EE361: Digital Computer Organization Course Syllabus

Execution Cycle. Pipelining. IF and ID Stages. Simple MIPS Instruction Formats

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

SOC architecture and design

Full and Para Virtualization

CS161: Operating Systems

Pentium vs. Power PC Computer Architecture and PCI Bus Interface

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

Big Picture. IC220 Set #11: Storage and I/O I/O. Outline. Important but neglected

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

Virtual Machines. COMP 3361: Operating Systems I Winter

Operating Systems: Basic Concepts and History

OPERATING SYSTEMS MEMORY MANAGEMENT

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

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

Giving credit where credit is due

Enabling Technologies for Distributed Computing

Paging: Introduction A Simple Example And Overview

Peter J. Denning, Naval Postgraduate School, Monterey, California

The Xen of Virtualization

CS:APP Chapter 4 Computer Architecture. Wrap-Up. William J. Taffe Plymouth State University. using the slides of

W4118 Operating Systems. Instructor: Junfeng Yang

x64 Servers: Do you want 64 or 32 bit apps with that server?

Chapter 6, The Operating System Machine Level

Operating System Impact on SMT Architecture


Development of Type-2 Hypervisor for MIPS64 Based Systems

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

OPERATING SYSTEM - VIRTUAL MEMORY

Computer Architecture

LSN 2 Computer Processors

EE282 Computer Architecture and Organization Midterm Exam February 13, (Total Time = 120 minutes, Total Points = 100)

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

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-17: Memory organisation, and types of memory

Transcription:

COMP303 Computer Architecture Lecture 6 Virtual Memory

What is virtual memory? Virtual Address Space Physical Address Space Disk storage Virtual memory => treat main memory as a cache for the disk Terminology: blocks in this cache are called Pages Typical size of a page: 4K 64K Page table maps virtual page numbers to physical frames

Virtual Memory Virtual memory (VM) allows main memory (DRAM) to act like a cache for secondary storage (magnetic disk). VM address translation provides a mapping from the virtual address of the processor to the physical address in main memory and secondary storage. VM provides the following benefits Allows multiple programs to share the same physical memory Allows programmers to write code (or compilers to generate code) as though they have a very large amount of main memory Automatically handles bringing in data from disk Cache terms vs. VM terms Cache block => page Cache miss => page fault

Virtual and Physical Addresses A virtual address consists of a virtual page number and a page offset. The virtual page number gets translated to a physical page number. The page offset is not changed 20 bits Virtual Page Number 2 bits Page offset Virtual Address Translation Physical Page Number 8 bits Page offset 2 bits Physical Address

Address Translation Virtual Address Virtual Page number Page offset Page table Main memory

Address Translation with Page Tables A page table translates a virtual page number into a physical page number. A page table register indicates the start of the page table. The virtual page number is used as an index into the page table that contains The physical page number A valid bit that indicates if the page is present in main memory A dirty bit to indicate if the page has been written Protection information about the page (read only, read/write, etc.) Since page tables contain a mapping for every virtual page, no tags are required.

Page Table Diagram Page table register Virtual address 3 30 29 28................... 5 4 3 2 0 9....... 2 0 Virtual Page Number Page offset Valid 20 Physical Page Number 2 Page Table If 0 then page is not presented in memory 8 29 28 27................... 5 4 3 2 0 9....... 2 0 Physical Page Number Page offset Physical address

Accessing Main Memory or Disk (See Figure 7.22 on page 58) If the valid bit of the page table is zero, this means that the page is not in main memory. In this case, a page fault occurs, and the missing page is read in from disk. Virtual page number Valid Page table Physical page or disk address Physical memory 0 0 0 Disk storage

Determining Page Table Size Assume 32-bit virtual address 30-bit physical address 4 KB pages => 2 bit page offset Each page table entry is one word (4 bytes) How large is the page table? Virtual page number = 32-2 = 20 bits Number of entries = number of pages = 2^20 Total size = number of entries x bytes/entry = 2^20 x 4 = 4 Mbytes Each process running needs its own page table Since page tables are very large, they are almost always stored in main memory, which makes them slow.

Large Address Spaces Two-level Page Tables 32-bit address: 0 0 2 P index P2 index page offset K PTEs 4KB PTE: Page Table Entry 4 bytes 4 GB virtual address space 4 KB of PTE 4 MB of PTE2 paged, holes 4 bytes

Caching Virtual Addresses CPU VA PA miss Translation Cache data hit Main Memory Virtual memory seems to be really slow: Must access memory on load/store -- even cache hits! Worse, if translation is not completely in memory, may need to go to disk before hitting in cache! Solution: Caching! Keep track of most common translations and place them in a Translation Lookaside Buffer (TLB)

Making address translation practical: TLB Virtual memory => memory acts like a cache for the disk Page table maps virtual page numbers to physical frames Translation Look-aside Buffer (TLB) is a cache for translations Virtual Address Space Physical Address Space virtual address page off Page Table 2 0 Disk storage 3 TLB frame page 2 2 0 5 physical address page off

Translation-Lookaside Buffer (TLB) A TLB acts as a cache for the page table, by storing physical addresses of pages that have been recently accessed. Virtual page number Valid Tag TLB Physical page address 0 Physical memory Page table Physical page or Valid disk address 0 0 0 Disk storage

MIPS R2000 TLB and Cache Virtual address 3 30 29......... 5 4 3 2 0... 0 TLB TLB hit 20 Valid Dirty Tag Data = = = = = = 20 2 Physical page number Page offset Physical address Physical tag address Cache index Byte offset 2 Valid Tag Data Cache Cache hit = Data 32

TLB and Cache Operation (See Figure 7.26 on page 594) On a memory access, the following operations occur. Virtual address TLB access TLB miss exception No TLB hit Yes Physical address No Write Yes Cache miss stall No Try to read data from cache Cache hit Write protection exception Yes Deliver data to the CPU No Write access bit on Yes Write data into cache, update the tag, and put the data and the address into the write buffer

Cache and Main Memory Parameters Parameter L Cache Main Memory Block (page) size 6-28 bytes 4096-65,536 bytes Hit time -2 cycles 40-00 cycles Miss Penalty 8-00 cycles to 6 million cycles Miss rate 0.5-0% 0.0000-0.00% Memory size 6 KB to MB 6 MB to 8 GB

4 Qs for Virtual Memory Q: Where can a block be placed in the upper level? Miss penalty for virtual memory is very high Have software determine location of block while accessing disk Allow blocks to be place anywhere in memory (fully associative) to reduce miss rate. Q2: How is a block found if it is in the upper level? Address divided into page number and page offset Page table and translation buffer used for address translation Q3: Which block should be replaced on a miss? Want to reduce miss rate & can handle in software Least Recently Used typically used Q4: What happens on a write? Writing to disk is very expensive Use a write-back strategy

TLB organization: include protection Virtual Address Physical Address Dirty Ref Valid Access ASID 0xFA00 0x0003 Y N Y R/W 34 0x0040 0x000 N Y Y R 0 0x004 0x00 N Y Y R 0 TLB usually organized as fully-associative cache Lookup is by Virtual Address Returns Physical Address + other info Dirty => Page modified (Y/N)? Ref => Page touched (Y/N)? Valid => TLB entry valid (Y/N)? Access => Read? Write? ASID => Which User?

TLB Characteristics The following are characteristics of TLBs TLB size : 32 to 4,096 entries Block size : or 2 page table entries (4 or 8 bytes each) Hit time: 0.5 to clock cycle Miss penalty: 0 to 00 clock cycles (go to page table) Miss rate: 0.0% to % Associative : Fully associative or set associative Write policy : Write back (replace infrequently) The MIPS R2000 TLB has the following characteristics TLB size: 64 entries Block size: entry of 64 bits (20 bit tag, valid bit, dirty bit, several bookkeeping bits) Hit time: 0.5 clock cycles Miss penalty: Average of 6 cycles Associative : Fully associative Write policy: write back

Example: R3000 pipeline includes TLB stages MIPS R3000 Pipeline Inst Fetch Dcd/ Reg ALU / E.A Memory Write Reg TLB I-Cache RF Operation WB E.A. TLB D-Cache TLB 64 entry, on-chip, fully associative, software TLB fault handler Virtual Address Space ASID V. Page Number Offset 6 20 2 0xx User segment (caching based on PT/TLB entry) 00 Kernel physical space, cached 0 Kernel physical space, uncached x Kernel virtual space Allows context switching among 64 user processes without TLB flush

Memory Protection With multiprogramming, a computer is shared by several programs or processes running concurrently Need to provide protection Need to allow sharing Mechanisms for providing protection Provide both user and supervisor (operating system) modes Provide CPU state that the user can read, but cannot write user/supervisor bit, page table pointer, and TLB Provide method to go from user to supervisor mode and vice versa system call or exception : user to supervisor system or exception return : supervisor to user Provide permissions for each page in memory Store page tables in the operating systems address space - can t be accessed directly by user.

Handling TLB Misses and Page Faults When a TLB miss occurs either Page is present in memory and update the TLB occurs if valid bit of page table is set Page is not present in memory and O.S. gets control to handle a page fault If a page fault occur, the operating system Access the page table to determine the physical location of the page on disk Chooses a physical page to replace - if the replaced page is dirty it is written to disk Reads a page from disk into the chosen physical page in main memory. Since the disk access takes so long, another process is typically allowed to run during a page fault.

Pitfall: Address space to small One of the biggest mistakes than can be made when designing an architect is to devote to few bits to the address address size limits the size of virtual memory difficult to change since many components depend on it (e.g., PC, registers, effective-address calculations) As program size increases, larger and larger address sizes are needed 8 bit: Intel 8080 (975) 6 bit: Intel 8086 (978) 24 bit: Intel 80286 (982) 32 bit: Intel 80386 (985) 64 bit: Intel Merced (Itanium) (200)

Virtual Memory Summary Virtual memory (VM) allows main memory (DRAM) to act like a cache for secondary storage (magnetic disk). Page tables and TLBs are used to translate the virtual address to a physical address The large miss penalty of virtual memory leads to different strategies from cache Fully associative LRU or LRU approximation Write-back Done by software