Memory Allocation. Copyright : University of Illinois CS 241 Staff 1

Similar documents
Memory - Paging. Copyright : University of Illinois CS 241 Staff 1

Lecture 14 Page Replacement Policies

Page Replacement. 3/9/07 CSE 30341: Operating Systems Principles

!! What is virtual memory and when is it useful? !! What is demand paging? !! When should pages in memory be replaced?

instruction is 6 bytes, might span 2 pages 2 pages to handle from 2 pages to handle to Two major allocation schemes

Optimal Algorithm. Replace page that will not be used for longest period of time Used for measuring how well your algorithm performs

Module 9: Virtual Memory

Background. Virtual Memory (2/2) Demand Paging Example. First-In-First-Out (FIFO) Algorithm. Page Replacement Algorithms. Performance of Demand Paging

Module 9: Virtual Memory

Principles of Operating Systems

First-In-First-Out (FIFO) Algorithm

Chapter 9: Virtual-Memory

Today. Adding Memory Does adding memory always reduce the number of page faults? FIFO: Adding Memory with LRU. Last Class: Demand Paged Virtual Memory

Lecture 17. Edited from slides for Operating System Concepts by Silberschatz, Galvin, Gagne

Chapter 8: Virtual Memory. Operating System Concepts

e-pg Pathshala Subject: Computer Science Paper: Operating Systems Module 29: Allocation of Frames, Thrashing Module No: CS/OS/29 Quadrant 1 e-text

! What is virtual memory and when is it useful? ! What is demand paging? ! What pages should be. ! What is the working set model?

Virtual Memory COMPSCI 386

Page Replacement Algorithms

Last Class: Demand Paged Virtual Memory

Basic Page Replacement

Background. Demand Paging. valid-invalid bit. Tevfik Koşar. CSC Operating Systems Spring 2007

Chapter 10: Virtual Memory. Background

Chapter 9: Virtual Memory

CS370 Operating Systems

Chapter 10: Virtual Memory. Background. Demand Paging. Valid-Invalid Bit. Virtual Memory That is Larger Than Physical Memory

CS307: Operating Systems

Virtual Memory. Reading: Silberschatz chapter 10 Reading: Stallings. chapter 8 EEL 358

Operating System Concepts

1. Background. 2. Demand Paging

Where are we in the course?

Chapter 9: Virtual Memory

ECE 7650 Scalable and Secure Internet Services and Architecture ---- A Systems Perspective. Part I: Operating system overview: Memory Management

CS 333 Introduction to Operating Systems. Class 14 Page Replacement. Jonathan Walpole Computer Science Portland State University

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

CS 333 Introduction to Operating Systems. Class 14 Page Replacement. Jonathan Walpole Computer Science Portland State University

MEMORY MANAGEMENT/1 CS 409, FALL 2013

Chapter 9: Virtual Memory

1. Creates the illusion of an address space much larger than the physical memory

CS370 Operating Systems

Paging algorithms. CS 241 February 10, Copyright : University of Illinois CS 241 Staff 1

CS420: Operating Systems

Chapter 8 Virtual Memory

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Chapter 9: Virtual-Memory Management. Operating System Concepts 8 th Edition,

Operating Systems Lecture 6: Memory Management II

Chapter 9: Virtual Memory. Chapter 9: Virtual Memory. Objectives. Background. Virtual-address address Space

Virtual Memory. Virtual Memory. Demand Paging. valid-invalid bit. Virtual Memory Larger than Physical Memory

Chapter 9: Virtual Memory

OPERATING SYSTEM. Chapter 9: Virtual Memory

Virtual Memory Outline

Virtual Memory. CSCI 315 Operating Systems Design Department of Computer Science

Chapter 9: Virtual Memory

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

Modeling Page Replacement: Stack Algorithms. Design Issues for Paging Systems

ECE7995 (3) Basis of Caching and Prefetching --- Locality

Chapter 9: Virtual Memory. Operating System Concepts 9th Edition

Virtual or Logical. Logical Addr. MMU (Memory Mgt. Unit) Physical. Addr. 1. (50 ns access)

Pipelined processors and Hazards

Chapter 10: Virtual Memory

Virtual Memory - Overview. Programmers View. Virtual Physical. Virtual Physical. Program has its own virtual memory space.

Preview. Memory Management

10: Virtual Memory Management

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory. Demand Paging

Virtual Memory Management

Virtual Memory: Page Replacement. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Chapter 9: Virtual Memory

CS510 Operating System Foundations. Jonathan Walpole

Chapter 8. Virtual Memory

CS 143A - Principles of Operating Systems

Memory management. Requirements. Relocation: program loading. Terms. Relocation. Protection. Sharing. Logical organization. Physical organization

CS450/550 Operating Systems

Virtual Memory. Overview: Virtual Memory. Virtual address space of a process. Virtual Memory

Operating System Concepts 9 th Edition

All Paging Schemes Depend on Locality. VM Page Replacement. Paging. Demand Paging

Chapter 9: Virtual Memory. Operating System Concepts 9 th Edition

Readings and References. Virtual Memory. Virtual Memory. Virtual Memory VPN. Reading. CSE Computer Systems December 5, 2001.

Chapter 6: Demand Paging

Memory Management Cache Base and Limit Registers base limit Binding of Instructions and Data to Memory Compile time absolute code Load time

ADRIAN PERRIG & TORSTEN HOEFLER Networks and Operating Systems ( ) Chapter 6: Demand Paging

CS 162 Operating Systems and Systems Programming Professor: Anthony D. Joseph Spring Lecture 15: Caching: Demand Paged Virtual Memory

Chapter 3: Virtual Memory ว ตถ ประสงค. Background สามารถอธ บายข อด ในการท ระบบใช ว ธ การจ ดการหน วยความจ าแบบเสม อนได

With regard to operating systems the kernel consists of the most frequently used functions in the operating system and it kept in main memory.

Memory management, part 2: outline. Operating Systems, 2017, Danny Hendler and Amnon Meisels

Chapter 8 Virtual Memory

Operating Systems. Overview Virtual memory part 2. Page replacement algorithms. Lecture 7 Memory management 3: Virtual memory

Virtual Memory III. Jo, Heeseung

CSE 120. Translation Lookaside Buffer (TLB) Implemented in Hardware. July 18, Day 5 Memory. Instructor: Neil Rhodes. Software TLB Management

Memory management, part 2: outline

Virtual Memory. ICS332 Operating Systems

CS 153 Design of Operating Systems Winter 2016

CS 4410 Operating Systems. Page Replacement (2) Summer 2016 Cornell University

CSE 153 Design of Operating Systems

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

CS399 New Beginnings. Jonathan Walpole

Chapter 3 Memory Management: Virtual Memory

Memory Management Outline. Operating Systems. Motivation. Paging Implementation. Accessing Invalid Pages. Performance of Demand Paging

Virtual Memory. Chapter 8

Memory Management. To improve CPU utilization in a multiprogramming environment we need multiple programs in main memory at the same time.

Transcription:

Memory Allocation Copyright : University of Illinois CS 241 Staff 1

Allocation of Page Frames Scenario Several physical pages allocated to processes A, B, and C. Process B page faults. Which page should be replaced? Allocating memory across processes? Does every process get the same fraction of memory? Different fractions? Should we completely swap some processes out of memory? Copyright : University of Illinois CS 241 Staff 2

Allocation of Page Frames Each process needs minimum number of pages Want to make sure that all processes that are loaded into memory can make forward progress Example: IBM 370 6 pages to handle SS MOVE instruction: instruction is 6 bytes, might span 2 pages 2 pages to handle from 2 pages to handle to Copyright : University of Illinois CS 241 Staff 3

Fixed Allocation Allocate a minimum number of frames per process Consider minimum requirements, e.g. on previous slide One page from the current executed instruction Most instructions require two operands Include an extra page for paging out and one for paging in Copyright : University of Illinois CS 241 Staff 4

Equal Allocation Allocate an equal number of frames per job Example Issues 100 frames 5 processes Each process gets 20 frames But jobs use memory unequally High priority jobs have same number of page frames and low priority jobs Degree of multiprogramming might vary Copyright : University of Illinois CS 241 Staff 5

Proportional Allocation Allocate a number of frames per job proportional to job size How do you determine job size Run command parameters? Dynamically? Priority Allocation May want to give high priority process more memory than low priority process Use a proportional allocation scheme using priorities instead of size Copyright : University of Illinois CS 241 Staff 6

Allocation of Page Frames Possible Replacement Scopes Local replacement Each process selects from only its own set of allocated frames Process slowed down even if other less used pages of memory are available Global replacement Process selects replacement frame from set of all frames One process can take a frame from another Process may not be able to control its page fault rate. Copyright : University of Illinois CS 241 Staff 7

Local Replacement: Per Process Each process has separate pool of pages Fixed number of pages (e.g., Digital VMS) Fixed fraction of physical memory (1/P) Proportional to size of allocated address space Page fault in one process only replaces pages of that process Perform replacement (e.g., LRU) over only those pages Advantage No interference across processes Disadvantage Potentially inefficient allocation of memory How to handle sharing of pages? Copyright : University of Illinois CS 241 Staff 8

Local Replacement: Per User Each user has separate pool of pages Advantage Fair across different users Disadvantage Inefficient allocation Copyright : University of Illinois CS 241 Staff 9

Global Replacement Pages from all processes lumped into single replacement pool Example: Run clock over all page frames Each process competes with other processes for frames Advantages Flexibility of allocation Minimize total number of page faults Disadvantages One memory-intensive process can hog memory, hurt all processes Copyright : University of Illinois CS 241 Staff 10

Page Fault Frequency Allocation Can we reduce Capacity misses by dynamically changing the number of pages/application? Too High: Need to give this process some more frames! Establish acceptable page-fault rate If actual rate too low, process loses frame If actual rate too high, process gains frame Too Low: Take some frames away and give to other processes! Question: What if we just don t have enough memory Copyright : University of Illinois CS 241 Staff 11

Overcommitting Memory When does the Virtual Memory illusion break? Example Set of processes frequently references 33 important pages Physical memory can fit 32 pages What happens? Process A references page not in physical memory OS runs another process B OS replaces some page in memory with page for A How long can B run before it page faults? Cycle continues... Copyright : University of Illinois CS 241 Staff 12

Overcommitting Memory If a process does not have enough pages, the page-fault rate is very high Low CPU utilization. OS thinks that it needs to increase the degree of multiprogramming Another process is added to the system. System throughput plunges System is reading and writing pages instead of executing useful instructions Average memory access time = disk access time Memory appears as slow as disk, instead of disk appearing as fast as memory Copyright : University of Illinois CS 241 Staff 13

Thrashing If a process does not have enough frames, the page-fault rate is very high Low CPU utilization Thrashing A process is busy swapping pages in and out In other words, a process is spending more time paging than executing Copyright : University of Illinois CS 241 Staff 14

Thrashing Example Process has 3 frames allocated to it (use LRU) Reference string is 123412341234-4 th access onwards all cause page faults Cannot be fixed with better replacement policies Do not indicate that a page must be kept in memory Only show which pages are better than others to replace Copyright : University of Illinois CS 241 Staff 15

Thrashing Student s analogy to thrashing: Too many courses Drop a course OS solution: Admission control Determine how much memory each process needs Long-term scheduling policy Run only those processes whose memory requirements can be satisfied What if memory needs of one process are too large???? Copyright : University of Illinois CS 241 Staff 16

Why Thrashing? Computations have locality Set of pages that are actively used together As the number of page frames decreases There are not enough available page frames to contain the locality of the process Processes start faulting heavily Pages that are read in, are used and immediately paged out Copyright : University of Illinois CS 241 Staff 17

Thrashing Page fault rate goes up Processes get suspended for page out to disk The system may start new jobs Reduces number of available page frames Increases page faults System throughput plunges! Copyright : University of Illinois CS 241 Staff 18

Working Set Question How much memory does a process need to keep the most recent computation in memory with very few page faults? How can we determine this? Determine the working set of a process The principle of locality A program clusters its access to data and text temporally A recently accessed page is more likely to be accessed again Copyright : University of Illinois CS 241 Staff 19

Working Set (1968, Denning) Need Set of pages process needs to avoid thrashing Requires knowing the future Working set Pages referenced by process in last seconds of execution Approximates locality Copyright : University of Illinois CS 241 Staff 20

Working Set (1968, Denning) working-set window fixed number of page references Example: 10,000 instruction Working set of P i = pages referenced in most recent Copyright : University of Illinois CS 241 Staff 21

Working Set (1968, Denning) Using working set sizes Cache partitioning Give each app enough space for WS Page replacement Preferentially discard non-ws pages Scheduling Process not executed unless WS in memory Copyright : University of Illinois CS 241 Staff 22

Working Set Size At least allocate this many frames for this process Copyright : University of Illinois CS 241 Staff 23

Working Set Size Choosing T T too small Will not encompass entire locality T too large Will encompass several localities T = Will encompass entire program Copyright : University of Illinois CS 241 Staff 24

Working sets of real programs Working set size stable transition stable transition stable transition Typical programs have phases Copyright : University of Illinois CS 241 Staff 25

Working Set in Action to Prevent Thrashing Algorithm If number free page frames > working set of some suspended process i Activate process i and map in its working set If working set size of some process k increases and no page frame is free Suspend process k and release all its pages Tracking the working set Moving window over reference string Approximate with Interval timer + a reference bit Copyright : University of Illinois CS 241 Staff 26

Working Set Implementation Example: T = 10,000 Timer interrupts after every 5000 time units Copy and set the values of all reference bits to 0 Keep in memory 2 bits for each page Indicates if page was used within last 10,000 to 15,000 references If one of the bits in memory = 1 Page in working set Not completely accurate - cannot tell where reference occurred. Improvement - 10 bits and interrupt every 1000 time units Copyright : University of Illinois CS 241 Staff 27

Page Fault Frequency Working Set Approximation of pure working set Assumption If the working set is correct Approach Not many page faults Control thrashing by establishing acceptable page-fault rate Copyright : University of Illinois CS 241 Staff 28

Page Fault Frequency Working Set Algorithm If page fault rate increases beyond assumed knee of curve Increase number of page frames available to process If page fault rate decreases below foot of knee of curve Decrease number of page frames available to process Copyright : University of Illinois CS 241 Staff 29

Page Size Considerations Small pages Large page tables Minimizes internal fragmentation Good for locality of reference (~256) Page tables are larger Disk-seek time dominates transfer time (It takes the same time to read a large page as a small page) Large pages Significant amounts of a page may not be referenced Enables more data per seek Real systems (can be reconfigured) Windows: default 8KB Linux: default 4 KB Copyright : University of Illinois CS 241 Staff 30