Chapter 4: Memory Management

Slides:



Advertisements
Similar presentations
Chapter 3 Memory Management
Advertisements

Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Memory Management.
Paging: Design Issues. Readings r Silbershatz et al: ,
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Memory Management Paging &Segmentation CS311, CS350 & CS550.
Virtual Memory Management G. Anuradha Ref:- Galvin.
MODERN OPERATING SYSTEMS Third Edition ANDREW S. TANENBAUM Chapter 3 Memory Management Tanenbaum, Modern Operating Systems 3 e, (c) 2008 Prentice-Hall,
Chapter 4: Memory Management
Virtual Memory Operating System Concepts chapter 9 CS 355
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Module 9: Virtual Memory
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
1 Virtual Memory vs. Physical Memory So far, all of a job’s virtual address space must be in physical memory However, many parts of programs are never.
1 Pertemuan 16 Isu-Isu pada Sistem Paging dan Segmentasi Matakuliah: T0316/sistem Operasi Tahun: 2005 Versi/Revisi: 5.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Chapter 4: Memory Management
Computer Organization and Architecture
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Memory Management Page replacement algorithms, segmentation Tanenbaum, ch. 3 p Silberschatz, ch. 8, 9 p
Memory Management From Chapter 4, Modern Operating Systems, Andrew S. Tanenbaum.
1 Memory Management 4.1 Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement algorithms.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
Lecture 11 Page 1 CS 111 Online Working Sets Give each running process an allocation of page frames matched to its needs How do we know what its needs.
Virtual Memory The memory space of a process is normally divided into blocks that are either pages or segments. Virtual memory management takes.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
1 Memory Management Chapter Basic memory management 4.2 Swapping 4.3 Virtual memory 4.4 Page replacement algorithms 4.5 Modeling page replacement.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
1 Memory Management Adapted From Modern Operating Systems, Andrew S. Tanenbaum.
Virtual Memory. 2 Last Week Memory Management Increase degree of multiprogramming –Entire process needs to fit into memory Dynamic Linking and Loading.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Background Virtual memory – separation of user logical memory.
COS 318: Operating Systems Virtual Memory Paging.
CS 333 Introduction to Operating Systems Class 14 – Page Replacement
Virtual Memory What if program is bigger than available memory?
Virtual Memory Chapter 8.
MODERN OPERATING SYSTEMS Third Edition ANDREW S
OPERATING SYSTEM CONCEPTS AND PRACTISE
Memory Management Paging (continued) Segmentation
Session 3 Memory Management
Memory Caches & TLB Virtual Memory
Chapter 9: Virtual Memory – Part I
Chapter 9: Virtual Memory
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
Page Replacement.
Memory Management Paging (continued) Segmentation
What Happens if There is no Free Frame?
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
CSE 451: Operating Systems Autumn 2005 Memory Management
Contents Memory types & memory hierarchy Virtual memory (VM)
CSE451 Virtual Memory Paging Autumn 2002
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Virtual Memory: Working Sets
Lecture 9: Caching and Demand-Paged Virtual Memory
Memory Management Paging (continued) Segmentation
Module 9: Virtual Memory
Virtual Memory.
Chapter 8 & 9 Main Memory and Virtual Memory
Presentation transcript:

Chapter 4: Memory Management Part 2: Paging Algorithms and Implementation Issues

Page replacement algorithms: summary Comment OPT (Optimal) Not implementable, but useful as a benchmark NRU (Not Recently Used) Crude FIFO (First-In, First Out) Might throw out useful pages Second chance Big improvement over FIFO Clock Better implementation of second chance LRU (Least Recently Used) Excellent, but hard to implement exactly NFU (Not Frequently Used) Poor approximation to LRU Aging Good approximation to LRU, efficient to implement Working Set Somewhat expensive to implement WSClock Implementable version of Working Set CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

Working set Demand paging: bring a page into memory when it’s requested by the process How many pages are needed? Could be all of them, but not likely Instead, processes reference a small set of pages at any given time—locality of reference Set of pages can be different for different processes or even different times in the running of a single process Set of pages used by a process in a given interval of time is called the working set If entire working set is in memory, no page faults! If insufficient space for working set, thrashing may occur Goal: keep most of working set in memory to minimize the number of page faults suffered by a process CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

Local vs. global allocation policies Last access time What is the pool of pages eligible to be replaced? Pages belonging to the process needing a new page All pages in the system Local allocation: replace a page from this process May be more “fair”: penalize processes that replace many pages Can lead to poor performance: some processes need more pages than others Global allocation: replace a page from any process Page A0 14 Local allocation A1 12 A2 8 A4 A3 5 A4 A4 B0 10 B1 9 Global allocation B2 3 C0 16 C1 12 C2 8 C3 5 C4 4 CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

Page fault rate vs. allocated frames Local allocation may be more “fair” Don’t penalize other processes for high page fault rate Global allocation is better for overall system performance Take page frames from processes that don’t need them as much Reduce the overall page fault rate (even though rate for a single process may go up) CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

Control overall page fault rate Despite good designs, system may still thrash IF Most (or all) processes have high page fault rate Some processes need more memory, … No processes need less memory Problem: no way to reduce page fault rate (can’t give processes more pages, stealing from other processes) Solution : Reduce number of processes competing for memory Swap one or more to disk, divide up pages they held Recall the discussion about degree of multiprogramming CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

Discussion: How big should a page be? Smaller pages have advantages Less internal fragmentation Better fit for various data structures, code sections Less unused physical memory (some pages have 20 useful bytes and the rest isn’t needed currently) Larger pages are better because Less overhead to keep track of them Smaller page tables TLB can point to more memory (TLB size is fixed  same number of pages, but more memory per page) Faster paging algorithms (fewer table entries to look through) More efficient to transfer larger pages to and from disk CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

Discussion: Sharing pages Processes can share pages Entries in page tables point to the same physical page frame Easier to manage with code, since typically code is not modified during run time (no critical section) Virtual addresses in different processes can be… The same: easier to exchange pointers, keep data structures consistent Different: may be easier to actually implement Not a problem if there are only a few shared regions Can be very difficult if many processes share regions with each other CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

When are dirty pages written to disk? On demand (when they’re replaced) Fewest writes to disk Slower: replacement takes twice as long (must wait for disk write and disk read) Periodically (in the background) or threshold-based (eg, if 80% of the memory is full): Cleaner process Cleaner scans through page tables, writes out dirty pages that are pretty old Cleaner can also keep a list of pages that will be ready for replacement soon (not sooooo old) Page faults handled faster: no need to find space on demand May use the same structures discussed earlier (clock, etc.) CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

Implementation issues Memory allocation, page replacement occurs four times when OS involved with paging Process creation Determine program size Create page table During process execution Reset the MMU for new process Flush the TLB (or reload it from saved state) Page fault time Determine virtual address causing fault Swap target page out (if needed), needed page in Process termination time Release page table Return pages to the free pool CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

How is a page fault handled? Hardware causes a page fault General registers saved (as on every exception) OS determines which virtual page needed Actual fault address in a special register Address of faulting instruction in register Page fault was in fetching instruction, or Page fault was in fetching operands for instruction OS must figure out which… OS checks validity of address Process killed if address was illegal OS finds a frame to put new page If frame selected for replacement is dirty, write it out to disk OS requests the new page from disk Page tables updated Faulting instruction backed up so it can be restarted Faulting process scheduled Registers restored Program “continues” CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

Backing up an instruction Problem: page fault happens in the middle of instruction execution Some changes may have already happened Others may be waiting for VM to be fixed Solution: undo all of the changes made by the instruction Restart instruction from the beginning This is easier on some architectures than others Example: LW R1, 12(R2) Page fault in fetching instruction: nothing to undo Page fault in getting value at 12(R2): restart instruction Example: ADD (Rd)+,(Rs1)+,(Rs2)+ Page fault in writing to (Rd): may have to undo an awful lot… CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

Locking pages in memory Virtual memory and I/O occasionally interact Potential problem: process P1 issues call for read from device into buffer While P1 is waiting for I/O (blocked), P2 runs Imagine P2 has a page fault P1’s I/O buffer might be chosen to be paged out (oops) This can create a problem because an I/O device is going to write to the buffer on P1’s behalf Solution: allow some pages to be locked into memory Locked pages are immune from being replaced Pages only stay locked for (relatively) short periods CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4

Separating policy and mechanism Mechanism for page replacement has to be in kernel mode Modifying page tables Reading and writing page table entries Policy for deciding which pages to replace can be in user space More flexibility, can tailor PRA 3. Request page User process External pager 4. Page arrives User space 2. Page needed 5. Here is page! Kernel space Fault handler MMU handler 1. Page fault 6. Map in page CS 1550, cs.pitt.edu (originaly modified by Ethan L. Miller and Scott A. Brandt) Chapter 4