CS 134: Operating Systems

Similar documents
OPERATING SYSTEM - VIRTUAL MEMORY

Virtual Memory Paging

Operating Systems. Virtual Memory

Lecture 17: Virtual Memory II. Goals of virtual memory

Chapter 11 I/O Management and Disk Scheduling

I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1

CS162 Operating Systems and Systems Programming Lecture 15. Page Allocation and Replacement

Linux Process Scheduling Policy

Memory unit sees only the addresses, and not how they are generated (instruction counter, indexing, direct)

Chapter 12. Paging an Virtual Memory Systems

HY345 Operating Systems

Virtualization. Explain how today s virtualization movement is actually a reinvention

The Classical Architecture. Storage 1 / 36

Why Computers Are Getting Slower (and what we can do about it) Rik van Riel Sr. Software Engineer, Red Hat

361 Computer Architecture Lecture 14: Cache Memory

& Data Processing 2. Exercise 3: Memory Management. Dipl.-Ing. Bogdan Marin. Universität Duisburg-Essen

Secondary Storage. Any modern computer system will incorporate (at least) two levels of storage: magnetic disk/optical devices/tape systems

COS 318: Operating Systems. Virtual Memory and Address Translation

14.1 Rent-or-buy problem

Virtual Memory. Virtual Memory. Paging. CSE 380 Computer Operating Systems. Paging (1)

Virtual vs Physical Addresses

Computer Architecture

Chapter 11 I/O Management and Disk Scheduling

Choosing a Computer for Running SLX, P3D, and P5

Process Scheduling CS 241. February 24, Copyright University of Illinois CS 241 Staff

File Management. Chapter 12

Kernel Optimizations for KVM. Rik van Riel Senior Software Engineer, Red Hat June

Introduction Disks RAID Tertiary storage. Mass Storage. CMSC 412, University of Maryland. Guest lecturer: David Hovemeyer.

External Sorting. Why Sort? 2-Way Sort: Requires 3 Buffers. Chapter 13

Windows Server Performance Monitoring

Timing of a Disk I/O Transfer

Process Description and Control william stallings, maurizio pizzonia - sistemi operativi

CS 61C: Great Ideas in Computer Architecture Virtual Memory Cont.

COS 318: Operating Systems

Chapter 10: Virtual Memory. Lesson 08: Demand Paging and Page Swapping

Page replacement in Linux 2.4 memory management

Code Injection From the Hypervisor: Removing the need for in-guest agents. Matt Conover & Tzi-cker Chiueh Core Research Group, Symantec Research Labs

The Quest for Speed - Memory. Cache Memory. A Solution: Memory Hierarchy. Memory Hierarchy

Storage. The text highlighted in green in these slides contain external hyperlinks. 1 / 14

How To Write A Page Table

Making the Right Choice

Board Notes on Virtual Memory

Operating Systems. III. Scheduling.

Enhancing SQL Server Performance

Hypervisor: Requirement Document (Version 3)

Memory Management Outline. Background Swapping Contiguous Memory Allocation Paging Segmentation Segmented Paging

Operating Systems, 6 th ed. Test Bank Chapter 7

Memory Management 1. Memory Management. Multitasking without memory management is like having a party in a closet.

Data Storage - I: Memory Hierarchies & Disks

White Paper Perceived Performance Tuning a system for what really matters

CS 464/564 Introduction to Database Management System Instructor: Abdullah Mueen

In and Out of the PostgreSQL Shared Buffer Cache

Capacity Analysis Techniques Applied to VMware VMs (aka When is a Server not really a Server?)

File System & Device Drive. Overview of Mass Storage Structure. Moving head Disk Mechanism. HDD Pictures 11/13/2014. CS341: Operating System

find model parameters, to validate models, and to develop inputs for models. c 1994 Raj Jain 7.1

Review from last time. CS 537 Lecture 3 OS Structure. OS structure. What you should learn from this lecture

Deploying and Optimizing SQL Server for Virtual Machines

MSU Tier 3 Usage and Troubleshooting. James Koll

Chapter 13: Query Processing. Basic Steps in Query Processing

Chapter 2: Computer-System Structures. Computer System Operation Storage Structure Storage Hierarchy Hardware Protection General System Architecture

Comparison of Memory Management Systems of BSD, Windows, and Linux

Systems Infrastructure for Data Science. Web Science Group Uni Freiburg WS 2014/15

Chapter 6, The Operating System Machine Level

2015 BANK OF AMERICA CHICAGO MARATHON TRAINING PLAN JUST DO IT.

Computer Architecture

Chapter 2 System Structures

Virtual Machines. COMP 3361: Operating Systems I Winter

Virtual Machines. Virtualization

External Sorting. Chapter 13. Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke 1

Midterm II SOLUTIONS December 4 th, 2006 CS162: Operating Systems and Systems Programming

Road Map. Scheduling. Types of Scheduling. Scheduling. CPU Scheduling. Job Scheduling. Dickinson College Computer Science 354 Spring 2010.

Chapter 1 Computer System Overview

Operating Systems OBJECTIVES 7.1 DEFINITION. Chapter 7. Note:

Reducing Backups with Data Deduplication

THE WINDOWS AZURE PROGRAMMING MODEL

COS 318: Operating Systems. Virtual Machine Monitors

How To Make Your Database More Efficient By Virtualizing It On A Server

MySQL: Cloud vs Bare Metal, Performance and Reliability

Quick Start Guide Getting Started with Stocks

Virtualization. P. A. Wilsey. The text highlighted in green in these slides contain external hyperlinks. 1 / 16

Survey on Job Schedulers in Hadoop Cluster

Virtual Memory. How is it possible for each process to have contiguous addresses and so many of them? A System Using Virtual Addressing

PERFORMANCE TIPS FOR BATCH JOBS

Performance Comparison of RTOS

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Chapter 3 Operating-System Structures

Memory Management CS 217. Two programs can t control all of memory simultaneously

Computer Architecture Prof. Mainak Chaudhuri Department of Computer Science and Engineering Indian Institute of Technology, Kanpur

Traditional IBM Mainframe Operating Principles

Input / Output and I/O Strategies

Avoiding Performance Bottlenecks in Hyper-V

Windows 7: Tips and Best Practices for Simplified Migration By Nelson Ruest and Danielle Ruest

Node-Based Structures Linked Lists: Implementation

Quiz for Chapter 6 Storage and Other I/O Topics 3.10

CS10110 Introduction to personal computer equipment

CAs and Turing Machines. The Basis for Universal Computation

1. Computer System Structure and Components

Lecture 1: Data Storage & Index

KVM & Memory Management Updates

Virtuoso and Database Scalability

Transcription:

CS 134: Operating Systems Memory Fun with Paging CS 134: Operating Systems Memory Fun with Paging 1 / 37

Overview Cost of Faults Overview Overview Cost of Faults Algorithms Easy Approaches Realistic Approaches Optimizing Tweaking Clock Pre-poning Work Working Sets Allocation Policies Thrashing Algorithms Easy Approaches Realistic Approaches Optimizing Tweaking Clock Pre-poning Work Working Sets Allocation Policies Thrashing 2 / 37

3 / 37 What needs to happen when a page fault occurs? What needs to happen when a page fault occurs?

What happens... User process accesses invalid memory traps to OS What happens... User process accesses invalid memory traps to OS 4 / 37

4 / 37 What happens... User process accesses invalid memory traps to OS OS: Saves process state What happens... User process accesses invalid memory traps to OS OS: Saves process state

4 / 37 What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal

4 / 37 What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame

4 / 37 What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked

4 / 37 What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked Gets interrupt from disk (I/O complete) process ready What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked Gets interrupt from disk (I/O complete) process ready

4 / 37 What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked Gets interrupt from disk (I/O complete) process ready Scheduler restarts process process running What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked Gets interrupt from disk (I/O complete) process ready Scheduler restarts process process running

4 / 37 What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked Gets interrupt from disk (I/O complete) process ready Scheduler restarts process process running Adjusts page table What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked Gets interrupt from disk (I/O complete) process ready Scheduler restarts process process running Adjusts page table

4 / 37 What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked Gets interrupt from disk (I/O complete) process ready Scheduler restarts process process running Adjusts page table Restores process state What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked Gets interrupt from disk (I/O complete) process ready Scheduler restarts process process running Adjusts page table Restores process state

4 / 37 What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked Gets interrupt from disk (I/O complete) process ready Scheduler restarts process process running Adjusts page table Restores process state Returns to user code What happens... User process accesses invalid memory traps to OS OS: Saves process state Checks access was actually legal Finds a free frame Reads from disk to free frame I/O wait, process blocked Gets interrupt from disk (I/O complete) process ready Scheduler restarts process process running Adjusts page table Restores process state Returns to user code

Cost of Faults (cont.) Cost of Faults (cont.) (cont.) How long? Disk is slow 5 15 ms is a conservative guess Main memory takes 5 15 ns Page fault is about 1 million times slower than a regular memory access Page faults must be rare! (Need locality!) How long? Disk is slow 5 15 ms is a conservative guess Main memory takes 5 15 ns Page fault is about 1 million times slower than a regular memory access Page faults must be rare! (Need locality!) 5 / 37

6 / 37 Cost of Faults A Back of an Envelope Calculation How often are there page faults? Cost of Faults A Back of an Envelope Calculation A Back of an Envelope Calculation How often are there page faults? An example from a desktop machine: In 14 days 378,110 page-ins Average load < 4% 12 hours actual compute time 8.75 page faults per second average 1,000,000,000 memory accesses per second (a guess) 43,200,000,000,000 memory accesses in 12 hours 1 page-in every 114,252,466 memory accesses Using 5 ns for memory, 5 ms for disk: t avg = (5, 000, 000 1 + 5 114, 252, 465)/114, 252, 466 t avg = 5.04ns An example from a desktop machine: In 14 days 378,110 page-ins Average load < 4% 12 hours actual compute time 8.75 page faults per second average 1,000,000,000 memory accesses per second (a guess) 43,200,000,000,000 memory accesses in 12 hours 1 page-in every 114,252,466 memory accesses Using 5 ns for memory, 5 ms for disk: t avg = (5, 000, 000 1 + 5 114, 252, 465)/114, 252, 466 t avg = 5.04ns Here s the problem with t avg : it s spread over 14 days, including time when the desktop s owner was asleep. It s an average! So what if just 1% of those 378K page-ins happened last Monday morning when the owner started work? All of a sudden we re spending 3781 5ms = 18.905sec waiting for the machine to respond. And the reality is that many more than 1% of the page-ins happen when the owner is most actively using the machine... Part of the problem is cold start, when a program is faulting itself in. We can improve that in several ways; for example we can pre-load the first page of instructions, perhaps the first page of each dynamic library. We can also detect sequential page accesses and prefetch future pages. Or going further, we can remember what happened last time the program ran and bring in those pages.

Cost of Faults (cont.) Cost of Faults (cont.) (cont.) Other kinds of page faults: Demand-page executables from their files, not swap device Copy-on-write memory great for fork Lazy memory allocation Other tricks... Other kinds of page faults: Demand-page executables from their files, not swap device Copy-on-write memory great for fork Lazy memory allocation Other tricks... What kind of other tricks? Well, for example, debugging and tracing; VM translation; buffer-overflow prevention. 7 / 37

8 / 37 What happens when we run out of free frames? What happens when we run out of free frames?

8 / 37 What happens when we run out of free frames? Prevent over-allocation of memory by modifying page-fault service routine to include page replacement Add modified (dirty) bit to page table. Only modified pages are written to disk. What happens when we run out of free frames? Prevent over-allocation of memory by modifying page-fault service routine to include page replacement Add modified (dirty) bit to page table. Only modified pages are written to disk.

8 / 37 What happens when we run out of free frames? Prevent over-allocation of memory by modifying page-fault service routine to include page replacement Add modified (dirty) bit to page table. Only modified pages are written to disk. This brings us to Virtual Memory we can provide a larger logical address space than we have physical memory What happens when we run out of free frames? Prevent over-allocation of memory by modifying page-fault service routine to include page replacement Add modified (dirty) bit to page table. Only modified pages are written to disk. This brings us to Virtual Memory we can provide a larger logical address space than we have physical memory

Algorithms Page-Replacement Algorithms Algorithms Page-Replacement Algorithms Page-Replacement Algorithms Deciding which page to kick out is tricky How to compare algorithms? Run them on a stream of page numbers corresponding to execution of a (hypothetical?) program (We want to achieve the lowest page-fault rate, i.e., minimum t avg) Deciding which page to kick out is tricky How to compare algorithms? Run them on a stream of page numbers corresponding to execution of a (hypothetical?) program (We want to achieve the lowest page-fault rate, i.e., minimum t avg ) 9 / 37

Algorithms Algorithms For example, suppose memory accesses by the system are 00002e00 00002e04 00002e08 00002e0c 00002f00 00002f04 00003216 00003800 00002f08 00001eb0 00001eb4 00001eb8 00005380 00002f0c 00002f10 00002f14 00002f18 00002f1c 00002f20 00002f24 00004d84 00004d88 00004d8c 00005380 00003800 00003216 00002f28 00005380 00002f2c 00002f30 Algorithms Algorithms Algorithms For example, suppose memory accesses by the system are 00002e00 00002e04 00002e08 00002e0c 00002f00 00002f04 00003216 00003800 00002f08 00001eb0 00001eb4 00001eb8 00005380 00002f0c 00002f10 00002f14 00002f18 00002f1c 00002f20 00002f24 00004d84 00004d88 00004d8c 00005380 00003800 00003216 00002f28 00005380 00002f2c 00002f30 10 / 37

Algorithms Algorithms For example, suppose memory accesses by the system are 00002e00 00002e04 00002e08 00002e0c 00002f00 00002f04 00003216 00003800 00002f08 00001eb0 00001eb4 00001eb8 00005380 00002f0c 00002f10 00002f14 00002f18 00002f1c 00002f20 00002f24 00004d84 00004d88 00004d8c 00005380 00003800 00003216 00002f28 00005380 00002f2c 00002f30 Algorithms Algorithms Algorithms For example, suppose memory accesses by the system are 00002e00 00002e04 00002e08 00002e0c 00002f00 00002f04 00003216 00003800 00002f08 00001eb0 00001eb4 00001eb8 00005380 00002f0c 00002f10 00002f14 00002f18 00002f1c 00002f20 00002f24 00004d84 00004d88 00004d8c 00005380 00003800 00003216 00002f28 00005380 00002f2c 00002f30 The stream of page numbers for the above execution is 2, 3, 2, 1, 5, 2, 4, 5, 3, 2, 5, 2 The stream of page numbers for the above execution is 2, 3, 2, 1, 5, 2, 4, 5, 3, 2, 5, 2 10 / 37

Algorithms Page-Replacement Policies Algorithms Page-Replacement Policies Page-Replacement Policies When you need to free up a frame, how do you choose? Class Exercise What are some easy strategies? When you need to free up a frame, how do you choose? Class Exercise What are some easy strategies? 11 / 37

Easy Approaches 12 / 37 Random (RAND) Throw out a random page. Easy Approaches Random (RAND) Random (RAND) Throw out a random page. NRU (Not Recently Used) is the VAX VMS algorithm: periodically clear referenced bits, and evict a random not-referenced page; see book for details.

12 / 37 Random (RAND) Easy Approaches Throw out a random page. RAND is Easy to implement Prone to throwing out a page that s being used The page will get paged back in Hope it is lucky and won t get zapped again next time Easy Approaches Random (RAND) Random (RAND) Throw out a random page. RAND is Easy to implement Prone to throwing out a page that s being used The page will get paged back in Hope it is lucky and won t get zapped again next time NRU (Not Recently Used) is the VAX VMS algorithm: periodically clear referenced bits, and evict a random not-referenced page; see book for details. (NRU is a variant on RAND) (NRU is a variant on RAND)

Easy Approaches First-in First-out Policy (FIFO) Throw out the oldest page. Try the following stream of page numbers with 3 frames and with 4 frames: Easy Approaches First-in First-out Policy (FIFO) Do this on the board with the class. First-in First-out Policy (FIFO) Throw out the oldest page. Try the following stream of page numbers with 3 frames and with 4 frames: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5 13 / 37

13 / 37 Easy Approaches First-in First-out Policy (FIFO) Throw out the oldest page. Easy Approaches First-in First-out Policy (FIFO) First-in First-out Policy (FIFO) Throw out the oldest page. FIFO is Easy to implement Prone to throwing out a page that s being used The page will get paged back in It will then be young again, and will not be thrown out again for a long time Prone to Belady s Anomaly increasing the number of frames can sometimes increase the number of page faults FIFO is Easy to implement Prone to throwing out a page that s being used The page will get paged back in It will then be young again, and will not be thrown out again for a long time Prone to Belady s Anomaly increasing the number of frames can sometimes increase the number of page faults

Easy Approaches 14 / 37 Optimal Page-Replacement Policy (OPT) Easy Approaches Optimal Page-Replacement Policy (OPT) Optimal Page-Replacement Policy (OPT) Replace the page that won t be accessed for the longest time Replace the page that won t be accessed for the longest time

Easy Approaches Optimal Page-Replacement Policy (OPT) Easy Approaches Optimal Page-Replacement Policy (OPT) Optimal Page-Replacement Policy (OPT) Replace the page that won t be accessed for the longest time OPT is Provably optimal Impossible to implement Useful as a benchmark Replace the page that won t be accessed for the longest time OPT is Provably optimal Impossible to implement Useful as a benchmark 14 / 37

Realistic Approaches Least Recently Used (LRU) Choose to replace the page that hasn t been accessed for the longest time. Realistic Approaches Least Recently Used (LRU) Least Recently Used (LRU) Choose to replace the page that hasn t been accessed for the longest time. Class Exercise Why is LRU hard to implement? Class Exercise Why is LRU hard to implement? 15 / 37

Realistic Approaches Least Recently Used (LRU) Choose to replace the page that hasn t been accessed for the longest time. Realistic Approaches Least Recently Used (LRU) Least Recently Used (LRU) Choose to replace the page that hasn t been accessed for the longest time. LRU is Hard to implement Fairly close to OPT in performance Class Exercise What s the worst case for LRU? Can it happen in real programs? LRU is Hard to implement Fairly close to OPT in performance Class Exercise What s the worst case for LRU? Can it happen in real programs? 15 / 37

Realistic Approaches Clock (aka Second Chance) Hardware maintains a referenced bit in the page table Set by hardware when page is accessed Realistic Approaches Clock (aka Second Chance) Clock (aka Second Chance) Hardware maintains a referenced bit in the page table Set by hardware when page is accessed Only cleared by the OS Use FIFO page replacement, but: If a page has its referenced bit set, clear it and move on to the next page Clock is Easy to implement An approximation of LRU Only cleared by the OS Use FIFO page replacement, but: If a page has its referenced bit set, clear it and move on to the next page Clock is Easy to implement An approximation of LRU 16 / 37

Realistic Approaches 17 / 37 Clock (cont.) Realistic Approaches Clock (cont.) Clock (cont.) (before allocation) Here, the magenta frames are ones that have been referenced. When there is a fault on virtual page 26 (poor choice of example, since it s hard to see 28/26 difference on the diagram), we clear the referenced bits on physical pages 2 and 3, then place virtual 26 into physical 4, setting its referenced bit, and advance the pointer to physical 5. (before allocation)

Realistic Approaches 18 / 37 Clock (cont.) Realistic Approaches Clock (cont.) Clock (cont.) (after allocation) If there is another fault immediately, we ll put the new page in physical page 5, replacing virtual page 44. (after allocation)

Realistic Approaches 19 / 37 Comparing the Policies Realistic Approaches Comparing the Policies Comparing the Policies Spend some time on this slide. An F under a column indicates that there was a fault. All algorithms are the same for the first four accesses, and all fault on the fifth access. Note that the first three faults aren t shown. The last F under OPT could replace either virtual 4 or virtual 3. On CLOCK, the fifth access finds all referenced bits set, so it chooses the page that was originally under the hand after scanning every other page in the system! Fortunately, this is rare in real systems with thousands or even millions of pages.

20 / 37 Optimizations Optimizing Optimizing Optimizations Optimizations Why is page replacement slow? One of the big costs is writing dirty pages. That s especially bad because it may mean seeking to the swap space to write, then somewhere else to read. Why is page replacement slow?

21 / 37 An Improved Clock Optimizing Optimizing An Improved Clock An Improved Clock (before allocation) (before allocation)

Optimizing Tweaking Clock 22 / 37 An Improved Clock Optimizing Tweaking Clock An Improved Clock An Improved Clock (after allocation) Here, we ve skipped over virtual page 28 (physical 4) because it s dirty, and instead we ve replaced physical 6. That saves us the disk write but if we keep going in this mode, eventually all pages will be dirty, not accessed. We ll come back to that point in a moment. (after allocation)

Optimizing Tweaking Clock 23 / 37 More Clock Optimizing Tweaking Clock More Clock More Clock How quickly does the hand go around? Why is that an issue? How quickly does the hand go around? It s an issue because the notion of recently used depends on how fast you go around. Adding memory has an effect; so does adding other programs. Why is that an issue?

Optimizing Tweaking Clock Two-Handed Clock Optimizing Tweaking Clock Two-Handed Clock Two-Handed Clock Have two clock hands, separated by fixed amount: Leading hand clears referenced bit Lagging hand frees unreferenced pages Recently used now depends only on distance between hands Have two clock hands, separated by fixed amount: Leading hand clears referenced bit Lagging hand frees unreferenced pages Recently used now depends only on distance between hands 24 / 37

25 / 37 Page Buffering Optimizing Pre-poning Work Optimizing Pre-poning Work Page Buffering Page Buffering Try to do some work ahead of time keep a list of free pages Find a page that doesn t appear to be being used Write it to disk if dirty Free it if clean Can be implemented with queue of ready to free pages Can reprieve page from queue if it gets referenced Even FIFO page replacement is workable with page buffering. Try to do some work ahead of time keep a list of free pages Find a page that doesn t appear to be being used Write it to disk if dirty Free it if clean Can be implemented with queue of ready to free pages Can reprieve page from queue if it gets referenced Even FIFO page replacement is workable with page buffering.

Optimizing Pre-poning Work 26 / 37 Using Queues, The Mach Approach Optimizing Pre-poning Work Using Queues, The Mach Approach Using Queues, The Mach Approach This is a practical implementation of a buffering algorithm. Only dirty pages can be reactivated, because otherwise the OS has lost track of what they really are. Attempts to keep 2/3 of pages active, 1/3 inactive, 5% in free list.

27 / 37 Enough Frames? Working Sets Working Sets Enough Frames? Enough Frames? How do you know if you have enough frames to work with...? How do you know if you have enough frames to work with...?

Working Sets Working Sets With fewer pages, page fault rate rises. If a process almost always page faults, it needs more frames If a process almost never page faults, it has spare frames Working Sets Working Sets Working Sets With fewer pages, page fault rate rises. If a process almost always page faults, it needs more frames If a process almost never page faults, it has spare frames 28 / 37

29 / 37 Working Sets Working Sets Working Sets Working Sets Working Sets How can we keep track of the working set of a process? How can we keep track of the working set of a process? Formal definition is pages referenced in last k accesses. Close approximation is pages referenced in last n ms. Note that this is pretty close to what the CLOCK algorithm does, except that other processes can interfere. Which leads to...

Working Sets Allocation Policies 30 / 37 Local vs. Global Working Sets Allocation Policies Local vs. Global Local vs. Global Whose pages do we take? Whose pages do we take?

Working Sets Allocation Policies Frame Allocation Policies Working Sets Allocation Policies Frame Allocation Policies Frame Allocation Policies So far, we ve examined paging without thinking about processes but what about processes? Each process needs a bare minimum number of pages (set by hardware characteristics of machine) Frames need to be shared out fairly between processes So far, we ve examined paging without thinking about processes but what about processes? Each process needs a bare minimum number of pages (set by hardware characteristics of machine) Frames need to be shared out fairly between processes 31 / 37

Working Sets Allocation Policies Local, Fixed Frame Allocation Working Sets Allocation Policies Local, Fixed Frame Allocation Local, Fixed Frame Allocation Give each of the n processes 1/n of the available frames Each process can only take frames from itself Class Exercise What do you think? Give each of the n processes 1/n of the available frames Each process can only take frames from itself Class Exercise What do you think? 32 / 37

Working Sets Allocation Policies Local, Proportional Frame Allocation Working Sets Allocation Policies Local, Proportional Frame Allocation Local, Proportional Frame Allocation Give each process frames in proportion to the amount of virtual memory they use Class Exercise What do you think? Give each process frames in proportion to the amount of virtual memory they use Class Exercise Some processes use a lot of VM, but don t access it often Some processes use a little VM, but access it often Not fair What do you think? 33 / 37

Working Sets Allocation Policies Global, Variable Allocation Working Sets Allocation Policies Global, Variable Allocation Global, Variable Allocation Just take the best (e.g., LRU) page, no matter which process it belongs to... Class Exercise Is this policy fair? If not, why not? Just take the best (e.g., LRU) page, no matter which process it belongs to... Class Exercise Is this policy fair? If not, why not? 34 / 37

Working Sets Allocation Policies Local, Variable Allocation Each program has a frame allocation Use working set measurements to adjust frame allocation from time to time. Each process can only take frames from itself. Working Sets Allocation Policies Local, Variable Allocation Local, Variable Allocation Each program has a frame allocation Use working set measurements to adjust frame allocation from time to time. Each process can only take frames from itself. Class Exercise What s wrong with this policy? Wrong assumptions: that we can measure working sets properly. That we can fit all working sets in memory. I.e., what assumptions are we making that could be wrong? Class Exercise What s wrong with this policy? I.e., what assumptions are we making that could be wrong? 35 / 37

Working Sets Allocation Policies Local, Variable Allocation Each program has a frame allocation Use working set measurements to adjust frame allocation from time to time. Each process can only take frames from itself. Working Sets Allocation Policies Local, Variable Allocation Local, Variable Allocation Each program has a frame allocation Use working set measurements to adjust frame allocation from time to time. Each process can only take frames from itself. Class Exercise What s wrong with this policy? Wrong assumptions: that we can measure working sets properly. That we can fit all working sets in memory. I.e., what assumptions are we making that could be wrong? What should we do if the working sets of all processes are more than the total number of frames available? Class Exercise What s wrong with this policy? I.e., what assumptions are we making that could be wrong? What should we do if the working sets of all processes are more than the total number of frames available? 35 / 37

Working Sets Thrashing Thrashing If we don t have enough pages, the page-fault rate is very high leads to thrashing... Low CPU utilization Lots of I/O activity Working Sets Thrashing Thrashing Thrashing If we don t have enough pages, the page-fault rate is very high leads to thrashing... Low CPU utilization Lots of I/O activity 36 / 37

Working Sets Thrashing Thrashing Working Sets Thrashing Thrashing Thrashing Under local replacement policy, only problem process is affected (usually) Can detect and swap out until can give bigger working set If can t give big enough, might want to kill... Under global replacement policy, whole machine can be brought to its knees!... But even under local policy, disk can become so busy that no other work gets done! Under local replacement policy, only problem process is affected (usually) Can detect and swap out until can give bigger working set If can t give big enough, might want to kill... Under global replacement policy, whole machine can be brought to its knees!... But even under local policy, disk can become so busy that no other work gets done! 37 / 37