Lab 12 Page Replacement Algorithm NCHU System Network

Lab 12 Page Replacement Algorithm NCHU System & Network Lab

Introduction • Why do we need page replacement algorithm ? – When page fault occur and there are no free memory frame, we need an algorithm to choose a victim frame. • What is page fault ? – Process wants to access the page but the page isn’t placed in main memory. NCHU System & Network Lab

Page Fault 0 1 a 2 c 3 d 4 e 5 f b logical memory valid-invalid bit frame 3 v 0 i 1 8 v 2 3 i 4 i 5 6 v page table 0 3 a 6 f 8 c a b e f c d secondary memory physical memory NCHU System & Network Lab

Page Replacement Algorithm • First In, First Out (FIFO) – Simplest – Associates with each page the time when it was brought into memory. – victim page = oldest page – Just use a FIFO queue NCHU System & Network Lab

FIFO Reference string a b c d a c a a b c a c c c b b b a a a a d d d c page frames first in first out NCHU System & Network Lab

Example • A program that show FIFO replacement algorithm process • Input – A file that has a reference string. • Output – Page replacement process. – Number of page fault times. NCHU System & Network Lab

NCHU System & Network Lab

NCHU System & Network Lab

NCHU System & Network Lab

Page Replacement Algorithm • Least Recently Used (LRU) – Associates with each page the time of that page’s last use – Victim page = the page that has not been used for the longest period of time – Use counters or stack NCHU System & Network Lab

LRU (stack) Reference string a b c d a c a a b c a c d a c a a b c b b c d d c c a b a a b c a d d c a page frames least-recently used NCHU System & Network Lab

LRU (counter) Reference string 0 1 2 3 4 5 6 7 8 9 a b c d a c a a b c a 0 a 0 d 3 d 3 d 3 b 8 b 1 b 1 a 4 a 6 a 7 a 7 c 2 c 2 c 5 c 5 c 9 page frames least-recently used NCHU System & Network Lab

Lab • A program that show LRU replacement algorithm process • Input – A file that has a reference string. • Output – Page replacement process. – Number of page fault times. NCHU System & Network Lab

Reference • Advanced Programming in the UNIX Environment 2 nd Author : Richard Stevens, Stephen A. Rago, Publisher : Addison-Wesley • Beginning Linux Programming Author : Richard Stones, Neil Matthew Publisher : Wrox • Operating System Concepts 6 th edition Author : Abraham Silberschatz, Peter Baer Galvin, Greg Gagne Publisher : John Wiley & Sons, inc. NCHU System & Network Lab
- Slides: 14