Page-replacement policies On some standard algorithms for the management of resident virtual memory pages.

Slides:



Advertisements
Similar presentations
9.4 Page Replacement What if there is no free frame?
Advertisements

Page Replacement Algorithms
4.4 Page replacement algorithms
Page Replacement Algorithms
Chapter 101 The LRU Policy Replaces the page that has not been referenced for the longest time in the past By the principle of locality, this would be.
Chapter 3.3 : OS Policies for Virtual Memory
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Virtual Memory 3 Fred Kuhns
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Virtual Memory II Chapter 8.
Virtual Memory: Page Replacement
Page Replacement Algorithms
By Snigdha Rao Parvatneni
Virtual Memory Why? The need of memory more than the available physical memory. Process 3 Physical Memory Process 2 Process 1 Process 4.
Chapter 8 Virtual Memory
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
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.
Lecture 34: Chapter 5 Today’s topic –Virtual Memories 1.
Day 23 Virtual Memory. Operating system’s role in VM Hardware-support Use VM or not Use paging or segmentation or both Software domain Algorithms for.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
CS 342 – Operating Systems Spring 2003 © Ibrahim Korpeoglu Bilkent University1 Memory Management – 4 Page Replacement Algorithms CS 342 – Operating Systems.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Memory Management Virtual Memory Page replacement algorithms
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
OS Spring’04 Virtual Memory: Page Replacement Operating Systems Spring 2004.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
O RERATıNG S YSTEM LESSON 10 MEMORY MANAGEMENT II 1.
Memory Management Page replacement algorithms, segmentation Tanenbaum, ch. 3 p Silberschatz, ch. 8, 9 p
Chapter 21 Virtual Memoey: Policies Chien-Chung Shen CIS, UD
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Memory: Paging.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
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.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
CPS110: Page replacement Landon Cox. Replacement  Think of physical memory as a cache  What happens on a cache miss?  Page fault  Must decide what.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
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.
Virtual Memory Questions answered in this lecture: How to run process when not enough physical memory? When should a page be moved from disk to memory?
1 Page Replacement Algorithms. 2 Virtual Memory Management Fundamental issues : A Recap Key concept: Demand paging  Load pages into memory only when.
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.
Virtual Memory Operating Systems 1 Computer Science Dept Va Tech August 2007 © McQuain Page Buffering LRU and the Clock Algorithm are generally.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Logistics Homework 5 will be out this evening, due 3:09pm 4/14
Chapter 9: Virtual Memory – Part I
Chapter 21 Virtual Memoey: Policies
Day 22 Virtual Memory.
Day 23 Virtual Memory.
Day 24 Virtual Memory.
Demand Paging Reference Reference on UNIX memory management
Lecture 10: Virtual Memory
Module 9: Virtual Memory
Demand Paging Reference Reference on UNIX memory management
Chapter 9: Virtual-Memory Management
What Happens if There is no Free Frame?
Demand Paged Virtual Memory
Morgan Kaufmann Publishers Memory Hierarchy: Virtual Memory
Operating Systems CMPSC 473
Operating Systems Concepts
Module 9: Virtual Memory
COMP755 Advanced Operating Systems
Chapter 9: Virtual Memory CSS503 Systems Programming
Virtual Memory.
Chapter 8 & 9 Main Memory and Virtual Memory
Presentation transcript:

Page-replacement policies On some standard algorithms for the management of resident virtual memory pages

Use of backing storage The Pentiums virtual memory architecture supports the swapping of memory pages between physical ram and disk storage More processes can be in the running state if some of their pages are swapped

More processes can be running DISK STORAGE PHYSICAL RAM 3 processes 6 processes

Replacing a page If a running process needs to reference a page that is not current in physical RAM, then that page must be read from the disk But then some other page current in RAM must be overwritten (i.e., replaced) Its the Operating Systems job is to decide which page will be the one to get replaced

What could go wrong? If the OS replaces a page that will soon be referenced again, then that page will have to be re-read back into memory (and some other page will need to be replaced) Disk-I/O is slow compared to RAM access A tasks progress is delayed when it needs to wait for disk-I/O operations to complete A worst-case senario is disk thrashing

Intelligent replacement The OS should try to avoid replacing any page that will very soon be needed again Belady showed (in 1966) that an optimal page-replacement policy is to discard the page that wont be needed again for the greatest amount of time But of course the OS has no way to know which pages will be needed soonest

The LRU policy Although the OS cant know the future, it can keep track of whats occurred in past OS can assume a tasks future behavior will probably resemble its past behavior So a page that has gone unreferenced for the longest amount of time is most likely to continue to go unreferenced in future This is the Least Recently Used policy

LRU is too costly Tracking the time when each page gets referenced is prohibitively expensive For example, with a 4GB physical memory there would be one million physical pages Hardware would need to support page- tracking in parallel with task execution So more practical approaches are needed

The FIFO policy A fixed-size array of pages is organized as a ring-buffer (FIRST-IN, FIRST-OUT) Whenever a new page must be brought in from the disk, it will replace the page that has been in RAM for the longest time This is simple to implement (and can work well if all pages are accessed with roughly the same frequency – but thats unusual!

The CLOCK policy An easy way to modify the FIFO policy, so as to avoid replacing frequently accessed pages that got loaded into RAM very early, is the so-called clock policy (also called known as the second chance algorithm) It uses a single bit of data for each page, called the accessed bit (which the CPU automatically sets upon a page-access), plus a revolving software pointer

The clockface pointer = unaccessed 1 = accessed

How it works When a page-replacement is needed, the page pointed to is examined –If its access-bit is 0 (unaccessed), it will get replaced, and the pointer will be advanced –If its access-bit is 1 (accessed), its access-bit will be cleared, and the pointer will advance, and this will be repeated until an unaccessed page is reached (maybe requiring a full circle) So accessed pages get a second chance!

Clock-policy enhancement? The Pentium supports an enhancement to this clock page-replacement policy Each page-table entry has two sticky bits: Page-table entry AD A = Accessed – the page has been read ( 1 = yes, 0 = no ) D = Dirty – the page has been modified ( 1 = yes, 0 = no )

Pages: clean versus dirty When a page is selected for replacement, it does not need to be written back to disk unless it has been modified (i.e., its dirty) So its more efficient if the OS replaces a clean page instead of a dirty one This leads to an improvement in the clock page-replacement policy

Keep track of (D,A) bits 1,1 0,0 0,1 0,0 0,1 1,1 0,0 = unaccessed 0,1 = accessed (clean) 1,1 = accessed (dirty)

How enhancement works When a page-replacement is needed, the page pointed to is examined: (D,A)-bits checked –If sticky-bits are 0,0 (unaccessed), page is replaced and the pointer is advanced –If sticky-bits are 0,1 (accessed, but clean), bits are not changed, but the pointer will be advanced –After a full circle, a second scan begins; if a clean page is encountered, it gets replaced; otherwise, after a second full scan (all page are dirty), the initial page gets replaced

In-class exercise Our clockalg.cpp demo simulates three page-replacement algorithms: optimal, CLOCK, and FIFO Try adding your own code to implement a simulation for the enhanced clock policy NOTE: youll need to associate a read or write attribute with every page-access