Last Class. Demand Paged Virtual Memory. Today: Demand Paged Virtual Memory. Demand Paged Virtual Memory

Similar documents
Last Class: Demand Paged Virtual Memory

Allocating Memory. Where does malloc get memory? See mmap.c 1-2

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 15: Caching: Demand Paged Virtual Memory

Course Outline. Processes CPU Scheduling Synchronization & Deadlock Memory Management File Systems & I/O Distributed Systems

Caching and Demand-Paged Virtual Memory

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

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

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

Lecture#16: VM, thrashing, Replacement, Cache state

Lecture 14: Cache & Virtual Memory

ECE7995 Caching and Prefetching Techniques in Computer Systems. Lecture 8: Buffer Cache in Main Memory (I)

All Paging Schemes Depend on Locality. VM Page Replacement. Paging. Demand Paging

Virtual Memory Design and Implementation

CS 153 Design of Operating Systems Winter 2016

Lecture 12: Demand Paging

Virtual Memory. Today.! Virtual memory! Page replacement algorithms! Modeling page replacement algorithms

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

CS162 Operating Systems and Systems Programming Lecture 14. Caching and Demand Paging

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

Basic Memory Management

Virtual memory. Virtual memory - Swapping. Large virtual memory. Processes

Page 1. CS162 Operating Systems and Systems Programming Lecture 14. Caching and Demand Paging

VIRTUAL MEMORY READING: CHAPTER 9

Operating Systems (1DT020 & 1TT802) Lecture 9 Memory Management : Demand paging & page replacement. Léon Mugwaneza

CS370 Operating Systems

Address spaces and memory management

CS510 Operating System Foundations. Jonathan Walpole

Operating Systems. Operating Systems Sina Meraji U of T

CS370 Operating Systems

Virtual Memory. Virtual Memory. Demand Paging. valid-invalid bit. Virtual Memory Larger than Physical Memory

CSE 120 Principles of Operating Systems

CIS Operating Systems Memory Management Page Replacement. Professor Qiang Zeng Spring 2018

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

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

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Operating System - Virtual Memory

CS162 Operating Systems and Systems Programming Lecture 11 Page Allocation and Replacement"

!! What is virtual memory and when is it useful? !! What is demand paging? !! When should pages in memory be replaced?

CIS Operating Systems Memory Management Cache Replacement & Review. Professor Qiang Zeng Fall 2017

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

Outline. 1 Paging. 2 Eviction policies. 3 Thrashing 1 / 28

Memory Organization MEMORY ORGANIZATION. Memory Hierarchy. Main Memory. Auxiliary Memory. Associative Memory. Cache Memory.

Paging algorithms. CS 241 February 10, Copyright : University of Illinois CS 241 Staff 1

CS 333 Introduction to Operating Systems. Class 14 Page Replacement. Jonathan Walpole Computer Science Portland State University

Page Replacement. (and other virtual memory policies) Kevin Webb Swarthmore College March 27, 2018

CS 333 Introduction to Operating Systems. Class 14 Page Replacement. Jonathan Walpole Computer Science Portland State University

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

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

Virtual Memory III. Jo, Heeseung

Virtual Memory. ICS332 Operating Systems

CS 4410 Operating Systems. Page Replacement (2) Summer 2016 Cornell University

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

CS370 Operating Systems

3/3/2014! Anthony D. Joseph!!CS162! UCB Spring 2014!

Memory: Paging System

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Operating Systems. Overview Virtual memory part 2. Page replacement algorithms. Lecture 7 Memory management 3: Virtual memory

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

Reminder: Mechanics of address translation. Paged virtual memory. Reminder: Page Table Entries (PTEs) Demand paging. Page faults

CSE 153 Design of Operating Systems

Past: Making physical memory pretty

Virtual Memory Design and Implementation

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

Virtual Memory Design and Implementation

CS450/550 Operating Systems

CSE 410 Final Exam Sample Solution 6/08/10

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory. Demand Paging

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

Memory Management! How the hardware and OS give application pgms:" The illusion of a large contiguous address space" Protection against each other"

Page Replacement Algorithms

EECS 482 Introduction to Operating Systems

HY225 Lecture 12: DRAM and Virtual Memory

Operating Systems Lecture 6: Memory Management II

Principles of Operating Systems

Locality and Data Accesses video is wrong one notes when video is correct

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

Memory Management. Goals of this Lecture. Motivation for Memory Hierarchy

Topic 18: Virtual Memory

CS162 Operating Systems and Systems Programming Lecture 14. Caching and Demand Paging

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

Where are we in the course?

Swapping. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Chapter 6 Memory 11/3/2015. Chapter 6 Objectives. 6.2 Types of Memory. 6.1 Introduction

Swapping. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Memory management, part 2: outline

Memory. Objectives. Introduction. 6.2 Types of Memory

CS370 Operating Systems

Demand- Paged Virtual Memory

Wednesday, November 4, 2009

a process may be swapped in and out of main memory such that it occupies different regions

Chapter 10: Virtual Memory. Background

Virtual Memory. Chapter 8

Memory Management! Goals of this Lecture!

Caching and Demand- Paged Virtual Memory

Virtual Memory Outline

Chapter 8 Virtual Memory

Introduction to Virtual Memory Management

Wednesday, November 22, 2017

Transcription:

Last Class Segmentation User view of programs Each program consists of a number of segments Segmented Paging: combine the best features of paging and segmentation Today: Demand Paged Virtual Memory Up to now, the virtual address space of a process fit in memory, and we assumed it was all in memory. OS illusions:ac 1. treat disk (or other backing store) as a much larger, but much slower main memory 2. analogous to the way in which main memory is a much larger, but much slower, cache or set of registers The illusion of an infinite virtual memory enables 1. a process to be larger than physical memory, and 2. a process to execute even if all of the process is not in memory 3. Allow more processes than fit in memory to run concurrently. Lecture 14, page 2 Lecture 14, page 3 Demand Paged Virtual Memory Demand Paged Virtual Memory Demand Paging uses a memory as a cache for the disk The page table (memory map) indicates if the page is on disk or memory using a valid bit Once a page is brought from disk into memory, the OS updates the page table and the valid bit For efficiency reasons, memory accesses must reference pages that are in memory the vast majority of the time Else the effective memory access time will approach that of the disk Key Idea: Locality---the working set size of a process must fit in memory, and must stay there. (90/10 rule.) Lecture 14, page 4 Lecture 14, page 5

When to load a page? When to load a page? At process start time: the virtual address space must be no larger than the physical memory. Overlays: application programmer indicates when to load and remove pages. Allows virtual address space to be larger than physical address space Difficult to do and is error-prone Request paging: process tells an OS before it needs a page, and then when it is through with a page. Demand paging: OS loads a page the first time it is referenced. May remove a page from memory to make room for the new page Process must give up the CPU while the page is being loaded Page-fault: interrupt that occurs when an instruction references a page that is not in memory. Pre-paging: OS guesses in advance which pages the process will need and pre-loads them into memory Allows more overlap of CPU and I/O if the OS guesses correctly. If the OS is wrong => page fault Errors may result in removing useful pages. Difficult to get right due to branches in code. Lecture 14, page 6 Lecture 14, page 7 Implementation of Demand Paging A copy of the entire program must be stored on disk. (Why?) Valid bit in page table indicates if page is in memory. 1: in memory 0: not in memory (either on disk or bogus address) If the page is not in memory, trap to the OS on first the reference The OS checks that the address is valid. If so, it 1. selects a page to replace (page replacement algorithm) 2. invalidates the old page in the page table 3. starts loading new page into memory from disk 4. context switches to another process while I/O is being done 5. gets interrupt that page is loaded in memory 6. updates the page table entry 7. continues faulting process (why not continue current process?) Swap Space What happens when a page is removed from memory? If the page contained code, we could simply remove it since it can be reloaded from the disk. If the page contained data, we need to save the data so that it can be reloaded if the process it belongs to refers to it again. Swap space: A portion of the disk is reserved for storing pages that are evicted from memory At any given time, a page of virtual memory might exist in one or more of: The file system Physical memory Swap space Page table must be more sophisticated so that it knows where to find a page Lecture 14, page 8 Lecture 14, page 9

Performance of Demand Paging Theoretically, a process could access a new page with each instruction. Fortunately, processes typically exhibit locality of reference Temporal locality: if a process accesses an item in memory, it will tend to reference the same item again soon. Spatial locality: if a process accesses an item in memory, it will tend to reference an adjacent item soon. Let p be the probability of a page fault (0 p 1). Effective access time = (1-p) x ma + p x page fault time If memory access time is 200 ns and a page fault takes 25 ms Effective access time = (1-p) x 200 + p x 25,000,000 If we want the effective access time to be only 10% slower than memory access time, what value must p have? Updating the TLB In some implementations, the hardware loads the TLB on a TLB miss. If the TLB hit rate is very high, use software to load the TLB 1. Valid bit in the TLB indicates if page is in memory. 2. on a TLB hit, use the frame number to access memory 3. trap on a TLB miss, the OS then a) checks if the page is in memory b) if page is in memory, OS picks a TLB entry to replace and then fills it in the new entry c) if page is not in memory, OS picks a TLB entry to replace and fills it in as follows i. invalidates TLB entry ii. perform page fault operations as described earlier iii. updates TLB entry iv. restarts faulting process All of this is still functionally transparent to the user. Lecture 14, page 10 Lecture 14, page 11 Transparent Page Faults How does the OS transparently restart a faulting instruction? Need hardware support to save 1. the faulting instruction, 2. the CPU state. What about instructions with side-effects? (CISC) mov a, (r10)+ : moves a into the address contained in register 10 and increments register 10. Solution: unwind side effects Transparent Page Faults Block transfer instructions where the source and destination overlap can't be undone. Solution: check that all pages between the starting and ending addresses of the source and destination are in memory before starting the block transfer Lecture 14, page 12 Lecture 14, page 13

Page Replacement Algorithms On a page fault, we need to choose a page to evict Random: amazingly, this algorithm works pretty well. FIFO: First-In, First-Out. Throw out the oldest page. Simple to implement, but the OS can easily throw out a page that is being accessed frequently. MIN: (a.k.a. OPT) Look into the future and throw out the page that will be accessed farthest in the future (provably optimal [Belady'66]). Problem? LRU: Least Recently Used. Approximation of MIN that works well if the recent past is a good predictor of the future. Throw out the page that has not been used in the longest time. Example: FIFO 3 page Frames 4 virtual Pages: A B C D Reference stream: FIFO: First-In-First-Out Lecture 14, page 14 Lecture 14, page 15 Example: MIN Example: LRU MIN: Look into the future and throw out the page that will be accessed farthest in the future. LRU: Least Recently Used. Throw out the page that has not been used in the longest time. Lecture 14, page 16 Lecture 14, page 17

Example: LRU When will LRU perform badly? Summary Benefits of demand paging: Virtual address space can be larger than physical address space. Processes can run without being fully loaded into memory. Processes start faster because they only need to load a few pages (for code and data) to start running. Processes can share memory more effectively, reducing the costs when a context switch occurs. A good page replacement algorithm can reduce the number of page faults and improve performance Lecture 14, page 18 Lecture 14, page 19