CS 318 Principles of Operating Systems

Similar documents
CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

CPU Scheduling. Basic Concepts Scheduling Criteria Scheduling Algorithms. Unix Scheduler

Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - V CPU Scheduling - I. University at Buffalo.

Lecture 11: CPU Scheduling

Windows Server Capacity Management 101

Motivation. Types of Scheduling

Hadoop Fair Scheduler Design Document

Integrated Service Management

Solution Brief Monitoring and Management For Desktops and Servers

Chapter 6: CPU Scheduling. Basic Concepts. Histogram of CPU-burst Times. CPU Scheduler. Dispatcher. Alternating Sequence of CPU And I/O Bursts

Scheduling II. To do. q Proportional-share scheduling q Multilevel-feedback queue q Multiprocessor scheduling q Next Time: Memory management

A Paper on Modified Round Robin Algorithm

University of California at Berkeley College of Engineering Computer Science Division - EECS. Computer Architecture and Engineering Midterm II

Real-Time Systems. Modeling Real-Time Systems

Lecture Note #4: Task Scheduling (1) EECS 571 Principles of Real-Time Embedded Systems. Kang G. Shin EECS Department University of Michigan

Using SAP with HP Virtualization and Partitioning

Scheduling I. Today. Next Time. ! Introduction to scheduling! Classical algorithms. ! Advanced topics on scheduling

Introduction to Real-Time Systems. Note: Slides are adopted from Lui Sha and Marco Caccamo

Roadmap. Tevfik Ko!ar. CSC Operating Systems Spring Lecture - V CPU Scheduling - I. Louisiana State University.

Journal of Global Research in Computer Science

Motivating Examples of the Power of Analytical Modeling

CPU Scheduling. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Clock-Driven Scheduling

Operating System 9 UNIPROCESSOR SCHEDULING

IBM Tivoli Workload Scheduler V8.5.1 engine Capacity Planning

10/1/2013 BOINC. Volunteer Computing - Scheduling in BOINC 5 BOINC. Challenges of Volunteer Computing. BOINC Challenge: Resource availability

A GUIDE TO GETTING SURVEY RESPONSES

Addressing UNIX and NT server performance

CPU Scheduling. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

The ABCs of. CA Workload Automation

IBM xseries 430. Versatile, scalable workload management. Provides unmatched flexibility with an Intel architecture and open systems foundation

ECONOMICS 103. Dr. Emma Hutchinson, Fall 2017

ArcGIS Network Analysis Solving transportation problems

Infor LN Minimum hardware requirements. Sizing Documentation

What about streaming data?

How fast is your EC12 / z13?

Innovative Marketing Ideas That Work

Pallab Banerjee, Probal Banerjee, Shweta Sonali Dhal

Classification Data Explanied. Have you ever wondered how JAMAR accurately calculates vehicle classification data when processing a tube style ATR?

9. Verification, Validation, Testing

Optimized Virtual Resource Deployment using CloudSim

OPERATING SYSTEMS. Systems and Models. CS 3502 Spring Chapter 03

Product Brief SysTrack VMP

WORKING WITH TEST DOCUMENTATION

Optimizing resource efficiency in Microsoft Azure

Increased Informix Awareness Discover Informix microsite launched

Principles of Operating Systems

Database Searching and BLAST Dannie Durand

for Fast, Easy Document Sharing

Best Practices: Advertising and Marketing

Case Study: Emergency Scan

A SIX-STEP, NO-FLUFF GUIDE TO BOOSTING SALES

QPR ScoreCard. White Paper. QPR ScoreCard - Balanced Scorecard with Commitment. Copyright 2002 QPR Software Oyj Plc All Rights Reserved

Priority-Driven Scheduling of Periodic Tasks. Why Focus on Uniprocessor Scheduling?

Intro to O/S Scheduling. Intro to O/S Scheduling (continued)

Tutorial Segmentation and Classification

NSF {Program (NSF ) first announced on August 20, 2004} Program Officers: Frederica Darema Helen Gill Brett Fleisch

Central Management Server (CMS) for SMA

Integrating Multigenerational Automation Systems

Better Together: Combining Your CRM Software with Marketing Automation

Application-Aware Power Management. Karthick Rajamani, Heather Hanson*, Juan Rubio, Soraya Ghiasi, Freeman Rawson

Using Systems Capacity Data for Business Intelligence

Introducing the World s Best PC Fleet Power Management System

IBM ICE (Innovation Centre for Education) Welcome to: Unit 1 Overview of delivery models in Cloud Computing. Copyright IBM Corporation

Sorting. 1 Insertion Sort. CS61B Summer 2006 Instructor: Erin Korber Lectures 13,14,15: 18,19,20 July

Local and Group Bufferpools

Pull Systems: Overview, Challenges and Success Factors

Operations and Production Management GPO300

Mobile Marketing. This means you need to change your strategy for marketing to those people, or risk losing them to your competition.

Game Theory - final project

Java & Testing. Slides adapted from Craig Zilles

The BEST Desktop Soft Real-Time Scheduler

Get The Best Out Of Oracle Scheduler

EMS 100, 200: SAUTER EMS and EMS Mobile

Marketing Automation: One Step at a Time

VAT THE ULTIMATE GUIDE TO

All NEMOs proposal for the price coupling algorithm and for the continuous trading matching algorithm, also incorporating TSO and NEMO proposals for

Adaptive Power Profiling for Many-Core HPC Architectures

Case Study. Cosma International improves systems through collaboration with Solarsoft. Customer Spotlight.

Q - water 3. Q - water. Q - water. Q - water. A new equimarginal condition. Lecture 21 & 22. A single farmer. A single farmer.

How to Scale DNN from 4,000 to 200,000 Users A Budget Challenge Case Study

Karisma v3 The most significant release of Karisma in almost ten years

Best Selection for Your Business. Electronic Pricing Scale. User s Manual. (Model: TP-31)

Job Scheduling for Multi-User MapReduce Clusters

Slot Floor Monitor System

H i g h S p e e d, R e l i a b l e a n d R o b u s t P l a n t H i s t o r i a n

Selected brief answers for review questions for first exam, Fall 2006 AGEC 350 Don't forget, you may bring a 3x5" notecard to the exam.

The Efficient Allocation of Individuals to Positions

CORE BANK PROCESSING NUPOINT. Dynamic Solutions. Superior Results.

2007 ALLDATA LLC. All rights reserved. ALLDATA is a registered trademark of ALLDATA LLC. ATI is a mark of Automotive Training Institute.

DeltaV Control Module Execution

Job Scheduling Challenges of Different Size Organizations

The Smart Marketer's Guide to Google Shopping

Module 05: Pinch Design Method for HEN synthesis Lecture 27: Rules of Pinch Design Method (PDM) 2 nd Part Key words: PDM, HEN

Lessons Learned Using HORIZON Teller Capture. Russell High, Product Manager May 24, 2017

Changing the delivery experience for the better. Updating our signature service

HOW BEST-IN-CLASS DEALERS ARE MAKING MORE CUSTOMER CONNECTIONS

UNITE Conference. May 13-16, 2012 St Louis, MO. Copyright 2012 TeamQuest Corporation. All Rights Reserved.

Recall: FCFS Scheduling (Cont.) Example continued: Suppose that processes arrive in order: P 2, P 3, P 1 Now, the Gantt chart for the schedule is:

Five trends in Capacity Management

Transcription:

CS 318 Principles of Operating Systems Fall 2017 Lecture 11: Page Replacement Ryan Huang

Memory Management Final lecture on memory management: Goals of memory management - To provide a convenient abstraction for programming - To allocate scarce memory resources among competing processes to maximize performance with minimal overhead Mechanisms - Physical and virtual addressing (1) - Techniques: Partitioning, paging, segmentation (1) - Page table management, TLBs, VM tricks (2) Policies - Page replacement algorithms (3) 10/9/17 CS 318 Lecture 11 Page Replacement 2

Lecture Overview Review paging and page replacement Survey page replacement algorithms Discuss local vs. global replacement Discuss thrashing 10/9/17 CS 318 Lecture 11 Page Replacement 3

Review: Paging Recall paging from the OS perspective: - Pages are evicted to disk when memory is full - Pages loaded from disk when referenced again - References to evicted pages cause a TLB miss PTE was invalid, causes fault - OS allocates a page frame, reads page from disk - When I/O completes, the OS fills in PTE, marks it valid, and restarts faulting process Dirty vs. clean pages - Actually, only dirty pages (modified) need to be written to disk - Clean pages do not but you need to know where on disk to read them from again 10/9/17 CS 318 Lecture 11 Page Replacement 4

Review: Paging disk Use disk to simulate larger virtual than physical mem 10/9/17 CS 318 Lecture 11 Page Replacement 5

Locality All paging schemes depend on locality - Processes reference pages in localized patterns Temporal locality - Locations referenced recently likely to be referenced again Spatial locality - Locations near recently referenced locations are likely to be referenced soon Although the cost of paging is high, if it is infrequent enough it is acceptable - Processes usually exhibit both kinds of locality during their execution, making paging practical 10/9/17 CS 318 Lecture 11 Page Replacement 6

Working Set Model (more later) Disk much, much slower than memory - Goal: run at memory speed, not disk speed 80/20 rule: 20% of memory gets 80% of memory accesses - Keep the hot 20% in memory - Keep the cold 80% on disk 10/9/17 CS 318 Lecture 11 Page Replacement 7

Working Set Model (more later) Disk much, much slower than memory - Goal: run at memory speed, not disk speed 80/20 rule: 20% of memory gets 80% of memory accesses - Keep the hot 20% in memory - Keep the cold 80% on disk 10/9/17 CS 318 Lecture 11 Page Replacement 8

Page Replacement When a page fault occurs, the OS loads the faulted page from disk into a page frame of physical memory At some point, the process used all of the page frames it is allowed to use - This is likely (much) less than all of available memory When this happens, the OS must replace a page for each page faulted in - It must evict a page to free up a page frame The page replacement algorithm determines how this is done - Greatly affect performance of paging (virtual memory) - Also called page eviction policies 10/9/17 CS 318 Lecture 11 Page Replacement 9

First-In First-Out (FIFO) Evict oldest fetched page in system Example reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 3 physical pages: 9 page faults 10/9/17 CS 318 Lecture 11 Page Replacement 10

First-In First-Out (FIFO) Evict oldest fetched page in system Example reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 3 physical pages: 9 page faults 4 physical pages: 10 page faults 10/9/17 CS 318 Lecture 11 Page Replacement 11

Belady s Anomaly More physical memory doesn t always mean fewer faults 10/9/17 CS 318 Lecture 11 Page Replacement 12

Optimal Page Replacement What is optimal (if you knew the future)? 10/9/17 CS 318 Lecture 11 Page Replacement 13

Optimal Page Replacement What is optimal (if you knew the future)? - Replace page that will not be used for longest period of time Example reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 With 4 physical pages: 10/9/17 CS 318 Lecture 11 Page Replacement 14

Belady s Algorithm Known as the optimal page replacement algorithm - Rationale: the best page to evict is the one never touched again - Never is a long time, so picking the page closest to never is the next best thing - Proved by Belady Problem: Have to predict the future Why is Belady s useful then? Use it as a yardstick - Compare implementations of page replacement algorithms with the optimal to gauge room for improvement - If optimal is not much better, then algorithm is pretty good - If optimal is much better, then algorithm could use some work Random replacement is often the lower bound 10/9/17 CS 318 Lecture 11 Page Replacement 15

Least Recently Used (LRU) Approximate optimal with least recently used - Because past often predicts the future - On replacement, evict the page that has not been used for the longest time in the past (Belady s: future) Example reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 With 4 physical pages: 8 page faults 10/9/17 CS 318 Lecture 11 Page Replacement 16

Least Recently Used (LRU) Approximate optimal with least recently used - Because past often predicts the future - On replacement, evict the page that has not been used for the longest time in the past (Belady s: future) Example reference string 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 With 4 physical pages: 8 page faults Problem 1: Can be pessimal example? - Looping over memory (then want MRU eviction) Problem 2: How to implement? 10/9/17 CS 318 Lecture 11 Page Replacement 17

Straw Man LRU Implementations Stamp PTEs with timer value - E.g., CPU has cycle counter - Automatically writes value to PTE on each page access - Scan page table to find oldest counter value = LRU page - Problem: Would double memory traffic! Keep doubly-linked list of pages - On access remove page, place at tail of list - Problem: again, very expensive What to do? - Just approximate LRU, don t try to do it exactly 10/9/17 CS 318 Lecture 11 Page Replacement 18

Clock Algorithm Use accessed bit supported by most hardware - E.g., Pentium will write 1 to A bit in PTE on first access - Software managed TLBs like MIPS can do the same Do FIFO but skip accessed pages Keep pages in circular FIFO list Scan: - page s A bit = 1, set to 0 & skip - else if A = 0, evict A.k.a. second-chance replacement 10/9/17 CS 318 Lecture 11 Page Replacement 19

Clock Algorithm Use accessed bit supported by most hardware - E.g., Pentium will write 1 to A bit in PTE on first access - Software managed TLBs like MIPS can do the same Do FIFO but skip accessed pages Keep pages in circular FIFO list Scan: - page s A bit = 1, set to 0 & skip - else if A = 0, evict A.k.a. second-chance replacement 10/9/17 CS 318 Lecture 11 Page Replacement 20

Clock Algorithm Use accessed bit supported by most hardware - E.g., Pentium will write 1 to A bit in PTE on first access - Software managed TLBs like MIPS can do the same Do FIFO but skip accessed pages Keep physical pages in circular list Scan: - page s A bit = 1, set to 0 & skip - else if A = 0, evict A.k.a. second-chance replacement 10/9/17 CS 318 Lecture 11 Page Replacement 21

Clock Algorithm (continued) Large memory may be a problem - Most pages referenced in long interval Add a second clock hand - Two hands move in lockstep - Leading hand clears A bits - Trailing hand evicts pages with 10/9/17 CS 318 Lecture 11 Page Replacement 22

Clock Algorithm (continued) Large memory may be a problem - Most pages referenced in long interval Add a second clock hand - Two hands move in lockstep - Leading hand clears A bits - Trailing hand evicts pages with 10/9/17 CS 318 Lecture 11 Page Replacement 23

Clock Algorithm (continued) Large memory may be a problem - Most pages referenced in long interval Add a second clock hand - Two hands move in lockstep - Leading hand clears A bits - Trailing hand evicts pages with 10/9/17 CS 318 Lecture 11 Page Replacement 24

Other Replacement Algorithms Random eviction - Dirt simple to implement - Not overly horrible (avoids Belady & pathological cases) LFU (least frequently used) eviction - Instead of just A bit, count # times each page accessed - Least frequently accessed must not be very useful (or maybe was just brought in and is about to be used) - Decay usage counts over time (for pages that fall out of usage) MFU (most frequently used) algorithm - Because page with the smallest count was probably just brought in and has yet to be used Neither LFU nor MFU used very commonly 10/9/17 CS 318 Lecture 11 Page Replacement 25

Fixed vs. Variable Space How to determine how much memory to give to each process? Fixed space algorithms - Each process is given a limit of pages it can use - When it reaches the limit, it replaces from its own pages - Local replacement Some processes may do well while others suffer Variable space algorithms - Process set of pages grows and shrinks dynamically - Global replacement One process can ruin it for the rest 10/9/17 CS 318 Lecture 11 Page Replacement 26

Working Set Model A working set of a process is used to model the dynamic locality of its memory usage - Defined by Peter Denning in 60s, published at the first SOSP conference Definition - WS(t,w) = {pages P such that P was referenced in the time interval (t, t-w)} - t time, w working set window (measured in page refs) A page is in the working set (WS) only if it was referenced in the last w references 10/9/17 CS 318 Lecture 11 Page Replacement 27

Working Set Size The working set size is the # of unique pages in the working set - The number of pages referenced in the interval (t, t-w) The working set size changes with program locality - During periods of poor locality, you reference more pages - Within that period of time, the working set size is larger Intuitively, want the working set to be the set of pages a process needs in memory to prevent heavy faulting - Each process has a parameter w that determines a working set with few faults - Denning: Don t run a process unless working set is in memory 10/9/17 CS 318 Lecture 11 Page Replacement 28

Example: gcc Working Set 10/9/17 CS 318 Lecture 11 Page Replacement 29

Working Set Problems Problems - How do we determine w? - How do we know when the working set changes? Too hard to answer - So, working set is not used in practice as a page replacement algorithm However, it is still used as an abstraction - The intuition is still valid - When people ask, How much memory does Firefox need?, they are in effect asking for the size of Firefox s working set 10/9/17 CS 318 Lecture 11 Page Replacement 30

Page Fault Frequency (PFF) Page Fault Frequency (PFF) is a variable space algorithm that uses a more ad-hoc approach - Monitor the fault rate for each process - 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) - If the fault rate is below a low threshold, take away memory Should fault more But not always Hard to use PFF to distinguish between changes in locality and changes in size of working set 10/9/17 CS 318 Lecture 11 Page Replacement 31

Thrashing Page replacement algorithms avoid thrashing - When OS spent most of the time in paging data back and forth from disk - Little time spent doing useful work (making progress) - 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 - Possible solutions Swapping write out all pages of a process Buy more memory 10/9/17 CS 318 Lecture 11 Page Replacement 32

Summary Page replacement algorithms - Belady s optimal replacement (minimum # of faults) - FIFO replace page loaded furthest in past - LRU replace page referenced furthest in past Approximate using PTE reference bit - LRU Clock replace page that is old enough - Working Set keep the set of pages in memory that has minimal fault rate (the working set ) - Page Fault Frequency grow/shrink page set as a function of fault rate Multiprogramming - Should a process replace its own page, or that of another? 10/9/17 CS 318 Lecture 11 Page Replacement 33

Next time Midterm review 10/9/17 CS 318 Lecture 11 Page Replacement 34