CS 149: Operating Systems March 5 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak www.cs.sjsu.edu/~mak.

Slides:



Advertisements
Similar presentations
Chapter 4 Memory Management Basic memory management Swapping
Advertisements

9.4 Page Replacement What if there is no free frame?
Module 10: Virtual Memory
Chapter 10: Virtual Memory
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
CS 149: Operating Systems February 3 Class Meeting
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)
Virtual Memory Management G. Anuradha Ref:- Galvin.
Virtual Memory Operating System Concepts chapter 9 CS 355
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory OSC: Chapter 9. Demand Paging Copy-on-Write Page Replacement.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 15: Background Information for the VMWare ESX Memory Management.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Module 9: Virtual Memory
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 9: Virtual Memory Background Demand Paging.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Gordon College Stephen Brinton
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management – 4 Page Replacement Algorithms CS 342 – Operating Systems.
CS 104 Introduction to Computer Science and Graphics Problems
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Chapter 10: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 10: Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
CSS430 Virtual Memory Textbook Ch9
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Chapter 3 Memory Management: Virtual Memory
CS 149: Operating Systems February 5 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Memory Management From Chapter 4, Modern Operating Systems, Andrew S. Tanenbaum.
Part 8: Virtual Memory. Silberschatz, Galvin and Gagne ©2005 Virtual vs. Physical Address Space Each process has its own virtual address space, which.
CS 149: Operating Systems February 26 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 149: Operating Systems March 12 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Second-Chance Algorithm Basically, it’s a FIFO algorithm When a page has been selected, we inspect its reference bit. If the value is 0, we proceed to.
CS 149: Operating Systems April 9 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 149: Operating Systems March 10 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
CS 149: Operating Systems March 3 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
CS 241 Section Week #9 (11/05/09). Topics MP6 Overview Memory Management Virtual Memory Page Tables.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
CSC 360, Instructor: Kui Wu Memory Management II: Virtual Memory.
Demand Paging Reference Reference on UNIX memory management
CS307 Operating Systems Virtual Memory Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
Virtual Memory The address used by a programmer will be called a virtual address or logical address. An address in main memory is called a physical address.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 9: Virtual-Memory Management 9.1 Background.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual-Memory Management.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 2: The Linux System Part 4.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
OPERATING SYSTEM CONCEPTS AND PRACTISE
Chapter 9: Virtual Memory – Part I
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
5: Virtual Memory Background Demand Paging
Operating Systems CMPSC 473
Module 9: Virtual Memory
Chapter 9: Virtual Memory CSS503 Systems Programming
Virtual Memory.
Presentation transcript:

CS 149: Operating Systems March 5 Class Meeting Department of Computer Science San Jose State University Spring 2015 Instructor: Ron Mak

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 2 Internal or External Fragmentation?  Variable-sized partitions  Entire processes occupy contiguous partitions of physical memory.  Fixed-sized page frames  Parts of processes occupy page frames distributed throughout physical memory. P3P1P2 P3P2P1P2P1 P3P3 P1P1 P2P2

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 3 Virtual Memory  Use paging to create virtual memory that is larger than physical memory. Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 4 Demand Paging  Unlike swapping, not all of a program needs to be loaded into memory at once.  Only load program pages when needed.  Pages that are never accessed are never loaded.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 5 Demand Paging, cont’d Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 6 Page Fault  A page fault occurs whenever a program tries to access a page that is not currently in memory. Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 7 Copy-on-Write  After a call to fork() Both parent and child share the same pages in memory. Recall that we said that after forking, the parent and child processes have separate memory.  As soon as one process attempts to modify a page: A copy of the page is created. The copied page is mapped into the address space of the process that wants to write to the page.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 8 Copy-on-Write, cont’d  Just after the fork() call:  After process 1 has written to page C: Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 9 Page Replacement  When a page fault occurs, the operating system must choose a “victim” page to evict from memory to make room for the page to be loaded from disk.  If the victim page has not been modified, then its copy on disk is up-to-date.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 10 Page Replacement  If the victim page has been modified, then the page must be written to disk. Overwrite the old page.  Which page should be evicted from memory? Several algorithms to decide.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 11 Page Replacement, cont’d  No room to load page B. Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 12 Page Replacement, cont’d Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 13 First-In, First-Out (FIFO)  Pages are evicted from memory in the order that they were loaded into memory. Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 14 Second Chance  Modification of FIFO.  Before evicting the oldest page, check its reference bit.  If the page is not being referenced, evict it.  If it is being referenced, put it back at the tail of the queue as if it were a new page just loaded (the second chance). Clear the reference bit. Reset its load time to the current time. Modern Operating Systems, 3 rd ed. Andrew Tanenbaum (c) 2008 Prentice-Hall, Inc All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak Second Chance, cont’d 15

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 16 Least Recently Used (LRU)  The victim page is the one that hadn’t been referenced the longest.  Need to keep track of the time when each page was last referenced. Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 17 Least Frequently Used (LFU)  Evict the page that has the lowest use count.  Problems: If a page was heavily used at the beginning of a program’s execution, it may stay in memory even if it’s never referenced again. A page that was just loaded may be the least frequently used page. Reference locality says it will be used again soon.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 18 Most Frequently Used (MFU)  Evict the page that has the highest use count.  Pages with the smallest use count probably just got loaded, and they will be used again soon.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 19 Random Pick  Randomly pick a page to evict.  This can have surprisingly good results.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 20 Working Set  The set of pages a process is currently using.  If a process’s working set can fit in memory, there will be few page faults. Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 21 Thrashing  A process’s working set cannot fit into available memory. Many page faults – one every few instructions.  Pages are constantly being loaded and evicted. Disk I/O is very slow compared to the speed of the CPU. The process spends more time paging than executing. Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 22 Page Fault Frequency (PFF)  To prevent thrashing, we need to control the page fault frequency (PFF) of a process. Too high: The process needs more page frames, or it will thrash. Too low: The process has too many page frames. Operating Systems Concepts with Java, 8 th edition Silberschatz, Galvin, and Gagne (c) 2010 John Wiley & Sons. All rights reserved

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 23 Assignment #4  The purpose of this assignment is to explore Memory allocation algorithms for swapping. Page replacement algorithms for paging.  Write a series of small simulation programs in either Java, C, or C++ (your choice). As in Assignment #2, you will generate simulated processes. You should not need to make any process management system calls.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 24 Assignment #4: Swapping  Main memory has 100 MB for swapping with variable sized partitions.  Processes have randomly and evenly distributed Sizes of 5, 11, 17, or 31 MB. Durations of 1, 2, 3, 4, or 5 seconds.  The process scheduler uses FCFS.  Write one or more programs that simulate the first fit, next fit, best fit, and worst fit memory allocation algorithms. It’s a busy time, so randomly generate enough simulated processes so that the job queue is never empty.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 25 Assignment #4: Swapping, cont’d  Run each algorithm 5 times simulating 1 minute each time to get an average of the number of processes successfully swapped into memory (but not necessarily completed) during the minute. Generate new random processes before each run.  Each time a process is swapped in or completes (and therefore is removed from memory), print a memory map of physical memory, e.g., AAAA....BBBBBBBB..CCCC where the letters are the process names (one letter per MB) and the dots are holes (one dot per MB).

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 26 Assignment #4: Swapping, cont’d  There is no memory compaction.  For each algorithm, print the average number of processes that were successfully swapped in.  Extra credit (up to 10 points) Rerun all your algorithms, but this time, after 30 (simulated) seconds, you can do one memory compaction. On average for each algorithm, how many MB were copied during compaction?

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 27 Assignment #4: Paging  You are running a process that consists of 10 pages numbered 0 through 9.  Physical memory has 4 page frames.  There are 10 page frames always available on disk.  The process makes random references to its pages. Due to locality of reference, after referencing a page i, there is a 70% probability that the next reference will be to page i, i-1, or i+1.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 28 Assignment #4: Paging, cont’d  In other words, there is a 70% probability that for a given i, Δ i will be -1, 0, or +1.  Otherwise, |Δ i | > 1.  TIP: Given page reference i, to compute the next page reference, first generate a random number r from 0 through 9. If 0 ≤ r < 7, then generate a random Δ i to be -1, 0, or +1. If 7 ≤ r ≤ 9, then randomly generate 2 ≤ Δ i ≤ 8. The next value of i is i + Δ i. The value of i wraps around from 9 to 0.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 29 Assignment #4: Paging, cont’d  Simulate the page replacement algorithms FIFO, LRU, LFU, MFU and random pick.  Run each algorithm 5 times, 100 page references each time, to compute an average hit ratio of pages already in memory.  For each reference, print the page numbers of the pages in memory and (if any) which page needed to be paged in and which page was evicted. Print the size and duration of a new entering process.  When the process starts, none of its pages are in memory.

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak Assignment #4: Paging, cont’d  Your output for each run could look like:  It may be easier to pivot this output so that time and the references go down the page and you print the page frames horizontally. Print also on each line which page was loaded and which page was evicted, if any. 30

Computer Science Dept. Spring 2015: March 5 CS 149: Operating Systems © R. Mak 31 Assignment #4, cont’d  to a zip file named after your team that Your source files. Your output. A short report describing your results.  Note clearly in your report if you did the extra credit.  Subject line: CS 149- section Assignment #4 team name Don’t forget to CC all your team members.  Due: Friday, March 20.