Lecture 17: Virtual Memory II. Goals of virtual memory

Similar documents
COS 318: Operating Systems. Virtual Memory and Address Translation

Virtual vs Physical Addresses

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

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

Board Notes on Virtual Memory

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

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

W4118: segmentation and paging. Instructor: Junfeng Yang

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

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

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

6.033 Computer System Engineering

Operating Systems. Virtual Memory

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

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

Storage in Database Systems. CMPSCI 445 Fall 2010

W4118 Operating Systems. Instructor: Junfeng Yang

How To Write A Page Table

HY345 Operating Systems

Addendum Intel Architecture Software Developer s Manual

Exploiting Address Space Contiguity to Accelerate TLB Miss Handling

Virtual Memory Paging

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

OPERATING SYSTEMS MEMORY MANAGEMENT

Storing Data: Disks and Files. Disks and Files. Why Not Store Everything in Main Memory? Chapter 7

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

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

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

CS5460: Operating Systems

OPERATING SYSTEM - VIRTUAL MEMORY

Operating Systems, 6 th ed. Test Bank Chapter 7

Topics in Computer System Performance and Reliability: Storage Systems!

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

Chapter 12. Paging an Virtual Memory Systems

The Classical Architecture. Storage 1 / 36

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

VIRTUAL MEMORY IN CONTEMPORARY MICROPROCESSORS

COS 318: Operating Systems. File Layout and Directories. Topics. File System Components. Steps to Open A File

The Deadlock Problem. Deadlocks. Deadlocks. Bridge Crossing Example

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

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

Computer Architecture

File Management. Chapter 12

361 Computer Architecture Lecture 14: Cache Memory

COS 318: Operating Systems

The Big Picture. Cache Memory CSE Memory Hierarchy (1/3) Disk

Virtual Machines. COMP 3361: Operating Systems I Winter

Computer Architecture

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

Paging: Introduction A Simple Example And Overview

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

Memory Hierarchy II: Main Memory

COMPUTER HARDWARE. Input- Output and Communication Memory Systems

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

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

A Deduplication File System & Course Review

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

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

A3 Computer Architecture

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

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

The Reduced Address Space (RAS) for Application Memory Authentication

Physical Data Organization

Outline: Operating Systems

A COOL AND PRACTICAL ALTERNATIVE TO TRADITIONAL HASH TABLES

Virtual Memory. Chapter 4

Outline. Cache Parameters. Lecture 5 Cache Operation

Virtual Memory Behavior in Red Hat Linux Advanced Server 2.1

File Systems Management and Examples

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

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

Chapter 11 I/O Management and Disk Scheduling

High-Performance Processing of Large Data Sets via Memory Mapping A Case Study in R and C++

The World According to the OS. Operating System Support for Database Management. Today s talk. What we see. Banking DB Application

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

Virtuoso and Database Scalability

Computer Systems Structure Main Memory Organization

AMD Opteron Quad-Core

Virtualization. Types of Interfaces

Chapter 12 File Management

Chapter 12 File Management. Roadmap

Using Synology SSD Technology to Enhance System Performance Synology Inc.

SOC architecture and design

StrongARM** SA-110 Microprocessor Instruction Timing

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

Where is the memory going? Memory usage in the 2.6 kernel

Data Storage - I: Memory Hierarchies & Disks

General Purpose Operating System Support for Multiple Page Sizes

The Lagopus SDN Software Switch. 3.1 SDN and OpenFlow. 3. Cloud Computing Technology

Virtual Memory and Address Translation

In and Out of the PostgreSQL Shared Buffer Cache

System Virtual Machines

Binary search tree with SIMD bandwidth optimization using SSE

Computer Architecture. Secure communication and encryption.

Transcription:

Lecture 17: Virtual Memory II Last Lecture: Introduction to virtual memory Today Review and continue virtual memory discussion Lecture 17 1 Goals of virtual memory Make it appear as if each process has: Its own private memory Nearly infinite-sized memory Lecture 17 2 1

A Load to Virtual Memory LW R1,0(R2) CPU Virtual Addr. 64 bits Translate Cache Physical Addr. 48 bits DRAM 1 GB 30 bits Translate from virtual space to physical space VA PA May need to go to disk Lecture 17 3 Virtual Addresses Span Memory+Disk Virtual Addresses Physical Addresses Disk Mappings changed dynamically by O/S In response to users data accesses OS manages it, triggered by hardware Lecture 17 4 2

A Load to Virtual Memory LW R1,0(R2) CPU Virtual Addr. 64 bits Translate Cache Physical Addr. 48 bits Process 1 DRAM 1 GB Process 2 30 bits Both programs can use the same set of addresses! Change translation tables to point same VA to different PA for different programs Lecture 17 5 Virtual Address Translation 63 12 11 0 Virtual Page Number (VPN) Page Offset Translation Table 29 12 11 Physical Page Number (PPN) Page Offset 0 Main Memory = 1 GB Page Size = 4KB VPN = 42 bits PPN = 18 bits Translation table aka Page Table An array of pointers Lecture 17 6 3

Page Table Construction Page Table Register valid Physical Page Number + VPN offset PPN offset Page table size (14 + 1) * 2 52 = enormous Where to put the page table? - we ll return to this question in a moment Lecture 17 7 What else can we put in this table? valid Physical Page Number What if we want a page to be read-only? What if we want a page to only hold instructions? What if we want to keep track of dirty pages? What if we want to track frequently used pages? Lecture 17 8 4

Page Frame Management Free Link R M State OS maintains page table for each user process page frame table free page list pages evicted when number of free pages falls below a low water mark. pages evicted using a replacement policy random, FIFO, LRU, clock if M-bit is clear, need not copy the page back to disk Proc 1 Page Frame Table Lecture 17 9 How much memory does each process need? W X Y Z X Y Z W Reference four pages in sequence, mapped to three page frames Y Z W X Need to keep a process working set in memory or thrashing will occur Find working set size by increasing page frame allocation until PF/s falls below limit Swap out whole process if insufficient page frames for working set Lecture 17 10 5

Page table organization Lecture 17 11 Page Table Organization PTP 2 n-o Flat page table has size proportional to size of virtual address space can be very large for a machine with 64-bit addresses and several processes Three solutions page the page table (fixed mapping) what really needs to be locked down? multi-level page table (lower levels paged - Tree) inverted page table (hash table) Lecture 17 12 6

Multi-Level Page Table Virtual Address Dir1 Dir2 Page offset PTP Directory Directory e.g., 42-bit VA with 12-bit offset 10-bits for each of three fields 1024 4-byte entries in each table (one page) Page Directory Page Table Lecture 17 13 Inverted Page Tables Virtual Address Page Offset Hash Page Frame S = OK Only store table entries for pages in physical memory Miss in page table implies page is on disk Usual hash-table rules apply: Hash table should not be full Rule of thumb: at least twice as many hash table entries as there are pages in memory. Frame Offset Lecture 17 14 7

Summary so far Virtual memory provides Illusion of private memory system for each process Protection Relocation in memory system Demand paging But page tables can be large Motivates: paging page tables, multi-level tables, inverted page tables Next: How can we improve performance of page tables? Lecture 17 15 How Long does it Take to Access VM? Best Case Issue Load Walk page table Worst Case Fetch data using PA Use data Issue Load Walk page table Translate Fetch PTE from disk Fetch data page from disk VA PA Install new page, Use data update page table Problems Multiple memory and potentially disk accesses Can we use cache for the page-table access? How? Lecture 17 16 8

Use a cache: Translation Lookaside Buffers PID VPN Offset TLB V W R M VPN PPN PPN Offset Page = VPN Frame = PPN Store most frequently used translations in small, fast memory (cache for page table entries) Valid, Writeable, Referenced, Modified Access protection Replacement strategies Size often 128 entries Highly associative (sometimes fully assoc.) Lecture 17 17 Rare Behavior in VM system TLB Miss Translation is not in TLB but everything could be in memory Two approaches Hardware state machine walks the page table fast but inflexible Exception raised and software walks the page table Page Fault Entry not in TLB and target page not in main memory Worst case Page fault and page table and target page Lecture 17 18 9

Reducing TLB misses Same type of optimizations as for cache Associativity (many TLBs are fully associative) Capacity TLBs tend to be 32-128 entries Adjust page size Small pages Reduces internal fragmentation Speeds page movement to/from disk Large pages Can cover more physical memory with same number of TLB entries Solution typically have a variable page size Select by OS, 4KB-256KB (superpages) AMD Barcelona supports 1 GB pages! Lecture 17 19 Combining virtual memory with conventional caching Lecture 17 20 10

Virtual Memory + Caching Conflicting demands: Convenience of flexible memory management (translation) Performance of memory hierarchy (caching) Requires cooperation of O/S Data in cache implies that data is in main memory Combine VM and Caching Where do we put the Cache and the TLB???? Lecture 17 21 Physically Addressed Cache LW R1,0(R2) CPU TLB Cache DRAM Virtual Addr. 64 bits Translate first from VA PA Access cache with PA Problems? Physical Addr. 48 bits Lecture 17 22 11

Virtually Addressed Cache LW R1,0(R2) CPU Cache TLB DRAM Access cache first Only translate if going to main memory Problems? Virtual Addr. 32 bits Physical Addr. 26 bits Lecture 17 23 Virtually addressed caches give aliasing problems Can occur when switching among multiple address spaces Synonym aliasing Different VAs point to the same PA Occurs when data shared among multiple address spaces One solution always translate before going to the cache Homonym aliasing Same VA point to different PAs Occurs on context switching Two solutions: Flush TLB on process switch/system call TLB includes process ID Lecture 17 24 12

Best of Both Worlds: LW R1,0(R2) TLB CPU DRAM Cache Virtual Addr. 64 bits Physical Addr. 48 bits Virtually addressed, Physically Tagged Parallel Access Eliminate synonym problem Lecture 17 25 Virtual Index, Physical Tag Lecture 17 26 13

Other Aliasing Solutions Note virtually indexed/physically tagged put constraints on cache capacity, page size, etc. Other solutions: 21264: 8KB pages, 64KB i-cache, 2-way set associative Aliases could reside in 8 different places in cache On cache miss, invalidate any possible aliases in cache Intel Pentium 4 Virtually indexed/virtually tagged cache Check for TLB misses off line (roll back if necessary) Lecture 17 27 Virtual Memory Summary Relocation, Protection Apparent memory size >> DRAM capacity Translation From large VA space to smaller PA space Page tables hold translations Provides Separation of memory management from user programs Ability to use DRAM as cache for disk Fast translation using Translation Lookaside Buffer (TLB) Cache for page table Speed - translate in parallel with cache lookup Lecture 17 28 14

Recap: caches and virtual memory Two basic ideas: Indirection (data = memory[table[address]]) Caching Caches Uses caching idea Virtual memory Uses indirection to convert virtual->physical address Uses caching to store active pages in DRAM, inactive pages on disk Uses caching to store active page translations in TLB Lecture 17 29 Virtual memory cache policies Write back Fully associative Clever replacement policies, implemented in SW Lecture 17 30 15