CS370 Operating Systems

Similar documents
CS370 Operating Systems

CS370 Operating Systems

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

Chapter 9: Virtual-Memory

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Chapter 9: Virtual Memory

Chapter 9: Virtual-Memory Management. Operating System Concepts 8 th Edition,

Virtual Memory - I. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XV. University at Buffalo.

Frequently asked questions from the previous class survey

Virtual Memory - I. Roadmap. Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSE 421/521 - Operating Systems Fall 2012

Chapter 8: Virtual Memory. Operating System Concepts

CS370 Operating Systems

CSE 4/521 Introduction to Operating Systems. Lecture 15 Virtual Memory I (Background, Demand Paging) Summer 2018

Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSC Operating Systems Spring 2007

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

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

CS370: Operating Systems [Spring 2017] Dept. Of Computer Science, Colorado State University

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - XIV Virtual Memory - I. Louisiana State University.

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

Chapter 9: Virtual Memory. Chapter 9: Virtual Memory. Objectives. Background. Virtual-address address Space

Chapter 9: Virtual Memory

Operating System Concepts

Virtual Memory Outline

CS307: Operating Systems

CS370 Operating Systems

Module 9: Virtual Memory

Chapter 10: Virtual Memory

Operating System Concepts 9 th Edition

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Demand Paging. Valid-Invalid Bit. Steps in Handling a Page Fault. Page Fault. Transfer of a Paged Memory to Contiguous Disk Space

OPERATING SYSTEM. Chapter 9: Virtual Memory

VIRTUAL MEMORY READING: CHAPTER 9

Memory Management. Virtual Memory. By : Kaushik Vaghani. Prepared By : Kaushik Vaghani

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

Chapter 3: Virtual Memory ว ตถ ประสงค. Background สามารถอธ บายข อด ในการท ระบบใช ว ธ การจ ดการหน วยความจ าแบบเสม อนได

Module 9: Virtual Memory

Chapter 9: Virtual Memory. Operating System Concepts 9th Edition

Chapter 10: Virtual Memory. Background

Chapter 10: Virtual Memory. Background. Demand Paging. Valid-Invalid Bit. Virtual Memory That is Larger Than Physical Memory

Virtual Memory - Overview. Programmers View. Virtual Physical. Virtual Physical. Program has its own virtual memory space.

Virtual Memory COMPSCI 386

Chapters 9 & 10: Memory Management and Virtual Memory

Operating System - Virtual Memory

CSC Operating Systems Spring Lecture - XIV Virtual Memory - II. Tevfik Ko!ar. Louisiana State University. March 27 th, 2008.

Page Replacement Algorithms

CSE325 Principles of Operating Systems. Virtual Memory. David P. Duggan. March 7, 2013

Where are we in the course?

Chapter 9: Virtual Memory

Virtual Memory: Page Replacement. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

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

Basic Memory Management

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

현재이이미지를표시할수없습니다. Chapter 9: Virtual Memory

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

Chapter 8 & Chapter 9 Main Memory & Virtual Memory

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

Basic Page Replacement

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

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

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

Introduction to Virtual Memory Management

Chapter 4 Memory Management

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

CS 5523 Operating Systems: Memory Management (SGG-8)

Principles of Operating Systems

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

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

Lecture 17. Edited from slides for Operating System Concepts by Silberschatz, Galvin, Gagne

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

Chapter 8: Main Memory. Operating System Concepts 8th Edition

CS370 Operating Systems

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

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

Operating System 1 (ECS-501)

Virtual Memory CHAPTER CHAPTER OBJECTIVES. 8.1 Background

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

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Chapter 9: Virtual Memory

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

Course: Operating Systems Instructor: M Umair. M Umair

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

Virtual Memory B: Objec5ves

Virtual Memory Management

1. Background. 2. Demand Paging

Even in those cases where the entire program is needed, it may not all be needed at the same time (such is the case with overlays, for example).

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

First-In-First-Out (FIFO) Algorithm

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

Background. Virtual Memory (2/2) Demand Paging Example. First-In-First-Out (FIFO) Algorithm. Page Replacement Algorithms. Performance of Demand Paging

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

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

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

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

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

Memory management, part 2: outline

CS420: Operating Systems

Swapping. Operating Systems I. Swapping. Motivation. Paging Implementation. Demand Paging. Active processes use more physical memory than system has

Memory management, part 2: outline. Operating Systems, 2017, Danny Hendler and Amnon Meisels

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

Transcription:

CS370 Operating Systems Colorado State University Yashwant K Malaiya Fall 2016 Lecture 32 Virtual Memory Slides based on Text by Silberschatz, Galvin, Gagne Various sources 1 1

Questions for you What is disk space is full, physical memory is full, and the user launches a process? If physical memory (RAM) gets to be very big, do accesses to disk reduce? Is there ever a case where adding more memory does not help? 2

Technical Perspective: Multiprogramming Contiguous allocation. Problem: external fragmentation Non-contiguous, but entire process in memory: Problem: Memory occupied by stuff needed only occasionally. Low degree of Multiprogramming. Demand Paging: Problem: page faults How to minimize page faults? 3

4 Virtual Memory That is Larger Than Physical Memory

Page Table When Some Pages Are Not in Main Memory Page 0 in Frame 4 (and disk) Page 1 in Disk 5

6 Steps in Handling a Page Fault

Performance of Demand Paging Stages in Demand Paging (worse case) 1. Trap to the operating system 2. Save the user registers and process state 3. Determine that the interrupt was a page fault 4. Check that the page reference was legal and determine the location of the page on the disk 5. Issue a read from the disk to a free frame: 1. Wait in a queue for this device until the read request is serviced 2. Wait for the device seek and/or latency time 3. Begin the transfer of the page to a free frame 6. While waiting, allocate the CPU to some other user 7. Receive an interrupt from the disk I/O subsystem (I/O completed) 8. Save the registers and process state for the other user 9. Determine that the interrupt was from the disk 10. Correct the page table and other tables to show page is now in memory 11. Wait for the CPU to be allocated to this process again 12. Restore the user registers, process state, and new page table, and then resume the interrupted instruction 7

Performance of Demand Paging (Cont.) Three major activities Service the interrupt careful coding means just several hundred instructions needed Read the page lots of time Restart the process again just a small amount of time Page Fault Rate 0 p 1 if p = 0 no page faults if p = 1, every reference is a fault Effective Access Time (EAT) Hopefully p <<1 EAT = (1 p) x memory access time + p (page fault overhead + swap page out + swap page in ) Page swap time = seek time + latency time 8

Demand Paging Example Memory access time = 200 nanoseconds Average page-fault service time = 8 milliseconds EAT = (1 p) x 200 + p (8 milliseconds) = (1 p) x 200 + p x 8,000,000 nanosec. = 200 + p x 7,999,800 ns Linear with page fault rate If one access out of 1,000 causes a page fault, then EAT = 8.2 microseconds. This is a slowdown by a factor of 40!! If want performance degradation < 10 percent, p =? 220 > 200 + 7,999,800 x p 20 > 7,999,800 x p p <.0000025 < one page fault in every 400,000 memory accesses 9

Issues: Allocation of physical memory to I/O and programs Memory used for holding program pages I/O buffers also consume a big chunk of memory Solutions: Fixed percentage set aside for I/O buffers Processes and the I/O subsystem compete 10

Demand paging and the limits of logical memory Without demand paging All pages of process must be in physical memory Logical memory limited to size of physical memory With demand paging All pages of process need not be in physical memory Size of logical address space is no longer constrained by physical memory Example 40 pages of physical memory 6 processes each of which is 10 pages in size Each process only needs 5 pages as of now Run 6 processes with 10 pages to spare Higher degree of multiprogramming 11

Coping with over-allocation of memory Example Physical memory = 40 pages 6 processes each of which is of size 10 pages But are using 5 pages each as of now What happens if each process needs all 10 pages? 60 physical frames needed Terminate a user process But paging should be transparent to the user Swap out a process Reduces the degree of multiprogramming Page replacement: selected pages. Policy? soon 12

What Happens if there is no Free Frame? Could be all used up by process pages or kernel, I/O buffers, etc How much to allocate to each? Page replacement find some page in memory, but not really in use, page it out Algorithm terminate? swap out? replace the page? Performance want an algorithm which will result in minimum number of page faults Same page may be brought into memory several times Continued to Page replacement etc... 16

Page Replacement Prevent over-allocation of memory by modifying page-fault service routine to include page replacement Use modify (dirty) bit to reduce overhead of page transfers only modified pages are written to disk Page replacement completes separation between logical memory and physical memory large virtual memory can be provided on a smaller physical memory 17

Basic Page Replacement 1. Find the location of the desired page on disk 2. Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame - Write victim frame to disk if dirty 3. Bring the desired page into the (newly) free frame; update the page and frame tables 4. Continue the process by restarting the instruction that caused the trap Note now potentially 2 page transfers for page fault increasing EAT 19

20 Page Replacement

Page and Frame Replacement Algorithms Frame-allocation algorithm determines How many frames to give each process Page-replacement algorithm Which frames to replace Want lowest page-fault rate Evaluate algorithm by running it on a particular string of memory references (reference string) and computing the number of page faults on that string String is just page numbers, not full addresses Repeated access to the same page does not cause a page fault Results depend on number of frames available In all our examples, we use 3 frames and the reference string of referenced page numbers is 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 21

22 Graph of Page Faults Versus The Number of Frames

FIFO page replacement algorithm: Out with the old; in with the new When a page must be replaced Replace the oldest one OS maintains list of all pages currently in memory Page at head of the list: Oldest one Page at the tail: Recent arrival During a page fault Page at the head is removed New page added to the tail 23

First-In-First-Out (FIFO) Algorithm Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 3 frames (3 pages can be in memory at a time per process) 15 page faults Sometimes a page is needed soon after replacement 7,0,1,2,0,3,0,.. 24

Belady s Anomaly Consider 1,2,3,4,1,2,5,1,2,3,4,5 Adding more frames can cause more page faults! Belady s Anomaly Belady was here at CSU. Guest in my CS530! 3 frames: 9 page faults 4 frames: 10 page faults 25

Optimal Algorithm Replace page that will not be used for longest period of time 9 page replacements is optimal for the example 4 th access: replace 7 because we will not use if got the longest time How do you know this? Can t read the future Used for measuring how well your algorithm performs 26

Least Recently Used (LRU) Algorithm Use past knowledge rather than future Replace page that has not been used in the most amount of time (4 th access page 7 is least recently used _) Associate time of last use with each page 12 faults better than FIFO but worse than OPT Generally good algorithm and frequently used But how to implement? 27