![Page 1: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/1.jpg)
Memory Management: Page Replacement Policies:
Miscellaneous TopicsCS 571: Operating Systems (Spring 2020)
Lecture 8c
Yue Cheng
Some material taken/derived from: • Wisconsin CS-537 materials created by Remzi Arpaci-Dusseau.Licensed for use under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
![Page 2: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/2.jpg)
2
Page Replacement Workload Examples
Y. Cheng GMU CS571 Spring 2020
![Page 3: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/3.jpg)
Workload Examples
• A simple workload• Workload consists of a working set of 100 pages• Workload issues 10,000 access requests
• Four replacement policies• OPT: The optimal • LRU: Least-recently used• FIFO: First-in first-out• RAND: Random
3Y. Cheng GMU CS571 Spring 2020
![Page 4: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/4.jpg)
The No-Locality Workload
4
Each reference is to a random page within the set of accessed pagesY. Cheng GMU CS571 Spring 2020
![Page 5: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/5.jpg)
The 80-20 Workload
5
80-20: 80% of the refs are made to 20% of the pages (“hot” pages)Y. Cheng GMU CS571 Spring 2020
![Page 6: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/6.jpg)
The Looping-Sequential Workload
6
Loop first 50 pages starting from 0 to 49 for a total of 10,000 accessesY. Cheng GMU CS571 Spring 2020
![Page 7: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/7.jpg)
The Looping-Sequential Workload
7
Loop first 50 pages starting from 0 to 49 for a total of 10,000 accesses
49
Y. Cheng GMU CS571 Spring 2020
![Page 8: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/8.jpg)
8
Thrashing
Y. Cheng GMU CS571 Spring 2020
![Page 9: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/9.jpg)
Thrashing• High-paging activity: The system is spending more
time paging than executing
• How can this happen? • OS observes low CPU utilization and increases the degree of
multiprogramming• Global page-replacement algorithm is used, it takes away
frames belonging to other processes• But these processes need those pages, they also cause
page faults• Many processes join the waiting queue for the paging device,
CPU utilization further decreases• OS introduces new processes, further increasing the paging
activity
9Y. Cheng GMU CS571 Spring 2020
![Page 10: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/10.jpg)
CPU Utilization vs. the Degree of Multiprogramming
10Y. Cheng GMU CS571 Spring 2020
![Page 11: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/11.jpg)
How to Avoid Thrashing?
• To avoid thrashing, earlier OS did admission control to only run a subset of processes
• Some current OS takes more draconian approach• E.g., some Linux runs an out-of-memory killer to
choose a memory-intensive process and kill it
11Y. Cheng GMU CS571 Spring 2020
![Page 12: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/12.jpg)
Review: Demand Paging• Bring a page into memory only when it is needed• Less I/O needed• Less memory needed • Faster response• Support more processes/users
• Page is needed Þ use the reference to page• If not in memory Þ must bring from the disk
• Demand paging versus swapping• Fetching the page in only on demand vs. kicking out
one victim then paging in one under mem pressure
12Y. Cheng GMU CS571 Spring 2020
![Page 13: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/13.jpg)
Demand Paging and Thrashing
• Why does demand paging work?Locality model• Process migrates from one locality to another• Localities may overlap
• Why does thrashing occur?S size of locality > total memory sizeOr S working set size > total memory size
• Definition of working set size (WSS): number of unique items that are accessed
13Y. Cheng GMU CS571 Spring 2020
![Page 14: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/14.jpg)
14
Impact of Program Structures on Memory Performance
Y. Cheng GMU CS571 Spring 2020
![Page 15: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/15.jpg)
Impact of Program Structure on Memory Performance• Consider an array named data with 128*128 elements• Each row is stored in one page (of size 128 words)
15Y. Cheng GMU CS571 Spring 2020
![Page 16: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/16.jpg)
Impact of Program Structure on Memory Performance• Consider an array named data with 128*128 elements• Each row is stored in one page (of size 128 words)• Program 1
for (j = 0; j <128; j++)for (i = 0; i < 128; i++)
data[i][j] = 0;
128 x 128 = 16,384 page faults
16Y. Cheng GMU CS571 Spring 2020
![Page 17: Memory Management - tddg.github.io · Memory Management: Page Replacement Policies: Miscellaneous Topics CS 571: Operating Systems (Spring 2020) Lecture 8c Yue Cheng Some material](https://reader033.vdocument.in/reader033/viewer/2022050102/5f418a924b3f6a744b16bbe3/html5/thumbnails/17.jpg)
Impact of Program Structure on Memory Performance• Consider an array named data with 128*128 elements• Each row is stored in one page (of size 128 words)• Program 1
for (j = 0; j <128; j++)for (i = 0; i < 128; i++)
data[i][j] = 0;
128 x 128 = 16,384 page faults
• Program 2 for (i = 0; i < 128; i++)for (j = 0; j < 128; j++)data[i][j] = 0;
Only 128 page faults17Y. Cheng GMU CS571 Spring 2020