CS 153 Design of Operating Systems Spring 2015 Lecture 19: Page Replacement and Memory War.

Slides:



Advertisements
Similar presentations
VM Page Replacement Hank Levy.
Advertisements

Virtual Memory (II) CSCI 444/544 Operating Systems Fall 2008.
Virtual Memory: Page Replacement
§12.4 Static Paging Algorithms
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
1 CSC 539: Operating Systems Structure and Design Spring 2005 Virtual memory  background  demand paging  page replacement: FIFO, OPT, LRU  allocation.
Virtual Memory. 2 What is virtual memory? Each process has illusion of large address space –2 32 for 32-bit addressing However, physical memory is much.
Virtual Memory.
CSE451 Introduction to Operating Systems Winter 2012 Paging Mark Zbikowski Gary Kimura.
CSE 451: Operating Systems Autumn 2013 Module 12 Virtual Memory, Page Faults, Demand Paging, and Page Replacement Ed Lazowska
Copyright ©: Lawrence Angrave, Vikram Adve, Caccamo 1 Virtual Memory III.
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
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.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
1 Virtual Memory in the Real World Implementing exact LRU Approximating LRU Hardware Support Clock Algorithm Thrashing Cause Working Set.
Virtual Memory. Names, Virtual Addresses & Physical Addresses Source Program Absolute Module Name Space P i ’s Virtual Address Space P i ’s Virtual Address.
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.
CS444/CS544 Operating Systems Virtual Memory 4/06/2007 Prof. Searleman
Thrashing and Memory Management
1 Virtual Memory Management B.Ramamurthy Chapter 10.
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
Virtual Memory Basic Concepts Demand Paging
Memory Management 2 Tanenbaum Ch. 3 Silberschatz Ch. 8,9.
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
Basics of Operating Systems March 4, 2001 Adapted from Operating Systems Lecture Notes, Copyright 1997 Martin C. Rinard.
Week 7 February 17, 2004 Adrienne Noble. Important Dates Due Monday, Feb 23 Homework 7 Due Wednesday, Feb 25 Project 3 Due Friday, Feb 27 Homework 8.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Lecture Topics: 11/17 Page tables TLBs Virtual memory flat page tables
Copyright ©: Lawrence Angrave, Vikram Adve, Caccamo 1 Virtual Memory.
Demand Paged Virtual Memory Andy Wang Operating Systems COP 4610 / CGS 5765.
Lecture 11 Page 1 CS 111 Online Working Sets Give each running process an allocation of page frames matched to its needs How do we know what its needs.
Lecture 11 Page 1 CS 111 Online Virtual Memory A generalization of what demand paging allows A form of memory where the system provides a useful abstraction.
CS 3204 Operating Systems Godmar Back Lecture 21.
Paging (continued) & Caching CS-3013 A-term Paging (continued) & Caching CS-3013 Operating Systems A-term 2008 (Slides include materials from Modern.
Lecture Topics: 11/24 Sharing Pages Demand Paging (and alternative) Page Replacement –optimal algorithm –implementable algorithms.
CSE 153 Design of Operating Systems Winter 2015 Lecture 12: Page Replacement.
Operating Systems ECE344 Ding Yuan Page Replacement Lecture 9: Page Replacement.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
Virtual Memory. 2 Last Week Memory Management Increase degree of multiprogramming –Entire process needs to fit into memory Dynamic Linking and Loading.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
IT 344: Operating Systems Module 11 Virtual Memory, Page Faults, Demand Paging, and Page Replacement Chia-Chi Teng 265 CTB.
Page Replacement FIFO, LIFO, LRU, NUR, Second chance
© 2013 Gribble, Lazowska, Levy, Zahorjan
CSE 120 Principles of Operating
Chapter 9: Virtual Memory – Part I
CSE 120 Principles of Operating
Module 9: Virtual Memory
Chapter 9: Virtual-Memory Management
CSE 451: Operating Systems Autumn 2012 Module 12 Virtual Memory, Page Faults, Demand Paging, and Page Replacement Ed Lazowska
Lecture 40 Syed Mansoor Sarwar
5: Virtual Memory Background Demand Paging
Demand Paged Virtual Memory
VM Page Replacement Hank Levy.
CSE 451: Operating Systems Autumn 2003 Lecture 11 Demand Paging and Page Replacement Hank Levy Allen Center
There’s not always room for one more. Brian Bershad
CSE 451: Operating Systems Winter 2003 Lecture 11 Demand Paging and Page Replacement Hank Levy 412 Sieg Hall 1.
CSE 153 Design of Operating Systems Winter 19
Module 9: Virtual Memory
COMP755 Advanced Operating Systems
CSE 451: Operating Systems Autumn 2009 Module 11 Virtual Memory, Page Faults, Demand Paging, and Page Replacement Ed Lazowska
CSE 451: Operating Systems Autumn 2010 Module 11 Virtual Memory, Page Faults, Demand Paging, and Page Replacement Ed Lazowska
There’s not always room for one more. Brian Bershad
Demand Paging We’ve hinted that pages can be moved between memory and disk this process is called demand paging is different than swapping (entire process.
Presentation transcript:

CS 153 Design of Operating Systems Spring 2015 Lecture 19: Page Replacement and Memory War

2 Working Set Model l A working set of a process is used to model the dynamic locality of its memory usage u Defined by Peter Denning in 60s l Definition u WS(t,w) = {set of pages P, such that every page in P was referenced in the time interval (t, t-w)} u t – time, w – working set window (measured in page refs) l A page is in the working set (WS) only if it was referenced in the last w references

3 Working Set Size l The working set size is the number of pages in the working set u The number of pages referenced in the interval (t, t-w) l The working set size changes with program locality u During periods of poor locality, you reference more pages u Within that period of time, the working set size is larger l Intuitively, want the working set to be the set of pages a process needs in memory to prevent heavy faulting u Each process has a parameter w that determines a working set with few faults u Denning: Don’t run a process unless working set is in memory

Example: gcc Working Set 4

5 Working Set Problems l Problems u How do we determine w? u How do we know when the working set changes? l Too hard to answer u So, working set is not used in practice as a page replacement algorithm l However, it is still used as an abstraction u The intuition is still valid u When people ask, “How much memory does Firefox need?”, they are in effect asking for the size of Firefox’s working set

6 Page Fault Frequency (PFF) l Page Fault Frequency (PFF) is a variable space algorithm that uses a more ad-hoc approach u Monitor the fault rate for each process u If the fault rate is above a high threshold, give it more memory »So that it faults less »But not always (FIFO, Belady’s Anomaly) u If the fault rate is below a low threshold, take away memory »Should fault more »But not always l Hard to use PFF to distinguish between changes in locality and changes in size of working set

7 Thrashing l Page replacement algorithms avoid thrashing u When most of the time is spent by the OS in paging data back and forth from disk u No time spent doing useful work (making progress) u In this situation, the system is overcommitted »No idea which pages should be in memory to reduce faults »Could just be that there isn’t enough physical memory for all of the processes in the system »Ex: Running Windows95 with 4 MB of memory… u Possible solutions »Swapping – write out all pages of a process »Buy more memory

Avoiding Thrashing with Minimum Memory l W: minimum amount of memory needed 8

Memory-related Security Problems 9 Stack 0x xFFFFFFFF Code (Text Segment) Static Data (Data Segment) Heap (Dynamic Memory Alloc) Address Space SP PC Static Dynamic

Stack Buffer Overflow l Example from Wikipedia

Common Defenses 1/3 Stack canaries l Canary = random value inserted at each stack frame. It is checked at every call return l Effects: Attacks cannot easily guess the value and have to overwrite it

Memory War - Buffer Overflow 12 Stack 0x xFFFFFFFF Code (Text Segment) Static Data (Data Segment) Heap (Dynamic Memory Alloc) Address Space Page Protection bits?

Commonly deployed defenses 2/3 Non-executable stack l Stack memory pages cannot be executed with this protection mechanism --- stack was designed as read/write memory only anyways l Effects: Attacks can only change return address to code pages (that are executable): u Return-to-libc u ROP (Return-Oriented Programming)

Commonly defenses 3/3 Address Space Layout Randomization (ASLR) l Base address of stacks, heaps, and binaries/libraries/kernel- modules are randomized l Effects: Attackers do not know what address to use, even for the state-of-the art ROP attack method

15 Summary l Page replacement algorithms u Belady’s – optimal replacement (minimum # of faults) u FIFO – replace page loaded furthest in past u LRU – replace page referenced furthest in past »Approximate using PTE reference bit u LRU Clock – replace page that is “old enough” u Working Set – keep the set of pages in memory that has minimal fault rate (the “working set”) u Page Fault Frequency – grow/shrink page set as a function of fault rate l Multiprogramming u Should a process replace its own page, or that of another?

16 Next time… l File systems u Chapters 11, 12, and 13

17

18 Example: Comparison

19 Example: Belady's Anomaly

20 Working Set: Example