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

Similar documents
Operating System Concepts

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

Page Replacement Algorithms

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

CS370 Operating Systems

CS370 Operating Systems

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

Virtual Memory Outline

Module 9: Virtual Memory

CS370 Operating Systems

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

Chapter 9: Virtual-Memory

Memory Management. Virtual Memory. By : Kaushik Vaghani. Prepared By : Kaushik Vaghani

Chapter 10: Virtual Memory. Background

Virtual Memory COMPSCI 386

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

Swapping. Operating Systems I. Swapping. Motivation. Paging Implementation. Demand Paging. Active processes use more physical memory than system has

Where are we in the course?

Module 9: Virtual Memory

Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

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

Principles of Operating Systems

Chapter 8: Virtual Memory. Operating System Concepts

Chapter 8: Virtual Memory. Operating System Concepts Essentials 2 nd Edition

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

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

Demand Paging. Valid-Invalid Bit. Steps in Handling a Page Fault. Page Fault. Transfer of a Paged Memory to Contiguous Disk Space

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

Chapter 9: Virtual Memory

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

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

OPERATING SYSTEM. Chapter 9: Virtual Memory

Chapter 9: Virtual Memory

Outline. 1 Paging. 2 Eviction policies. 3 Thrashing 1 / 28

PAGE REPLACEMENT. Operating Systems 2015 Spring by Euiseong Seo

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

Basic Page Replacement

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

Memory management, part 2: outline

Chapters 9 & 10: Memory Management and Virtual Memory

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

Last Class: Demand Paged Virtual Memory

CS307: Operating Systems

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

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

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

1. Background. 2. Demand Paging

Chapter 9: Virtual Memory

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

UNIT - IV. What is virtual memory?

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

CS420: Operating Systems

Chapter 10: Virtual Memory

Virtual Memory. ICS332 Operating Systems

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

Addresses in the source program are generally symbolic. A compiler will typically bind these symbolic addresses to re-locatable addresses.

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

Operating Systems Lecture 6: Memory Management II

Operating System Concepts 9 th Edition

Virtual Memory III. Jo, Heeseung

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

First-In-First-Out (FIFO) Algorithm

Lecture 14 Page Replacement Policies

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

Virtual Memory. 1 Administrivia. Tom Kelliher, CS 240. May. 1, Announcements. Homework, toolboxes due Friday. Assignment.

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

Chapter 6: Demand Paging

CS370 Operating Systems

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

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

Virtual Memory - II. Roadmap. Tevfik Koşar. CSE 421/521 - Operating Systems Fall Lecture - XVI. University at Buffalo.

Page replacement algorithms OS

Basic Memory Management

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

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

ECE7995 Caching and Prefetching Techniques in Computer Systems. Lecture 8: Buffer Cache in Main Memory (I)

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

Virtual Memory Management

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

Chapter 4 Memory Management

CSC Operating Systems Spring Lecture - XIV Virtual Memory - II. Tevfik Ko!ar. Louisiana State University. March 27 th, 2008.

Virtual Memory CHAPTER CHAPTER OBJECTIVES. 8.1 Background

Page Replacement Chap 21, 22. Dongkun Shin, SKKU

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

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

Role of OS in virtual memory management

B. V. Patel Institute of Business Management, Computer &Information Technology, UTU

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

Basic Memory Management. Basic Memory Management. Address Binding. Running a user program. Operating Systems 10/14/2018 CSC 256/456 1

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

Operating System - Virtual Memory

Operating Systems. Operating Systems Sina Meraji U of T

Even in those cases where the entire program is needed, it may not all be needed at the same time (such is the case with overlays, for example).

CS450/550 Operating Systems

Practice Exercises 449

Global Replacement Algorithms (1) Ken Wong Washington University. Global Replacement Algorithms (2) Replacement Example (1)

CISC 7310X. C08: Virtual Memory. Hui Chen Department of Computer & Information Science CUNY Brooklyn College. 3/22/2018 CUNY Brooklyn College

VIRTUAL MEMORY READING: CHAPTER 9

CS 153 Design of Operating Systems Winter 2016

Transcription:

Operating Systems Lecture 7 Memory management : Virtual memory Overview Virtual memory part Page replacement algorithms Frame allocation Thrashing Other considerations Memory over-allocation Efficient process creation Memory mapped files Page replacement algorithms What page to replace? Page replacement algo should give lowest page fault rate Algorithm evaluation run on a sequence of memory references compute number of page faults for that sequence Reference sequence generated using some distribution traces of actual memory references

FIFO Page replacement algorithms Optimal LRU Counting algorithms Second chance enhanced second chance Page buffering FIFO Replace oldest page in memory imlemented by FIFO queue Not very good in many situations as we soon shall se Example: frames, 5 page replacements Belady s Anomaly Increasing number of frames may increase page faults for some algorithms discovered by Belady et al. in 969 Example: Reference string:,,, 4,,, 5,,,, 4, 5 frames: 4 frames; 4 5 5 4 9 page faults 5 0 page faults 4 4 4

Optimal Algorithm Lowest page fault of all algorithms never suffers from belady s anomaly Replace page that will not be used for longest period of time Example: reference seq.:,,, 4,,, 5,,,, 4, 5 4 6 page faults 4 5 Optimal algorithm Hard to implement why? uses information not present at time of decision Used for measuring quality of other algorithms Least Recently Used (LRU) Replace page least recently used page not use for longest period of time look backwards in time (instead of forward, as optimal) Considered to be good often used does not suffer from Belady s anomaly

LRU - implementation Counters entry in page table has time-of-use field OS (or hardware) maintains clock or counter At access, field is updated page with smallest time value is replaced Stack page numbers kept in stack most recently used on top, LRU at bottom Problems with this? requires update for every memory access too costly LRU approximation Few hardware architectures support true LRU replacement Referenced bit often set by hardware on access separates accessed pages from unaccessed order of access not known Referenced bit can be used to approximate LRU Second chance LRU approximation algorithm Treats set of page table entries as circular buffer advances through pages in order pointer indicates which page should be replaced next Set reference bit to 0 for each pass Does not replace pages that has reference bit= pages get a second chance if they have been accessed since last visit Degenerates to FIFO if all pages accessed since last replacement Also known as the clock algorithm 4

Second chance pointer advances curcular buffer of pages reset bit at pointer replace pages with bit=0 not used since last visit Enhanced second chance I/O time consuming twice as expensive to replace a dirty page Same procedure as second chance, but consider dity pages (0,0) neither used nor dirty (best choice) (0,) not used, but dirty (:nd choice) (,0) used, but clean (:rd choice) (,) used and dirty (worst choice) Queue may have to be scanned several times Counting algorithms Keep counter memory references to each page LFU (Least frequently used) replace page with lowest count MFU (Most frequently used) pages with low count are new should not be swapped out LFU and MFU not used much expensive to implement LFU approximates LRU poorly 5

Page buffering algorithms Page buffering can be used on any algorithm OS keeps pool of free frames process can quickly be given a frame victim frames are selected in the background variant: remember which pages reside in each free frame can quickly be given back if needed OS may keep list of modified pages modified pages written to disk in background fewer dirty pages in system These techniques are often used Page replacement non-dirty pages Possible to not only load from swap space code segment (executable, dynamic library) could be loaded from executable file again just discard frame, even if not in swap faster? sometimes... why not always?» swap space is faster than file system» might be faster to save in swap Allocation of frames How many pages to allocate to a process? more processes? more page faults? Absolute minimum depends on instruction set number of frames used simultaneously by instruction example: mov (r), (r) uses frames Absolute maximum total amount of memory Major schemes fixed allocation priority allocation 6

Frame allocation Fixed allocation same number of frames to each process proportional to size of process #frames varies as processes are started and terminated Priority allocation allocate proportional to priority of process Working set model... Frequency allocation Thrashing If process has to few pages page in new pages very often low cpu utilization much i/o-wait Thrashing more time spent on paging than execution Scheduler might increase multiprogramming because cpu is idle even more severe thrashing Degree of multiprogramming has to be decreased Local allocation of frames thrashing does not spread to other processes thrashing process consumes more resources How many frames does a process really need? Thrashing 7

Working set model Try to estimate number of frames used by process currently working set enough to keep working set in memory How to compute? set of pages referenced by fixed number of page references delta too small we don t get a complete locality delta too large we get several localities Estimating working set Referenced bit combined with regular interrupts Frequency allocation Alternative to working set model Bounds on acceptable page fault frequency lower upper Lower bound reached process has to many pages Upper bound reached process has to few frames Other considerations Prepaging load pages before process starts prevents initial high page fault rate Page size selection internal fragmentation page table size I/O transfer/seek time locality smaller pages gives higher resolution TLB reach reach = page size * # entries working set of process should fit in the TLB maybe several processes in the TLB... 8

Program structure Other considerations arrays stored row-wise each row in one page, or consecutive pages if accessed column-wise one page fault per access otherwise one page fault per row different array order in different languages... Memory over-allocation Possible to increase degreee of multiprogramming over-allocate memory Process only uses a fraction of its pages swap out pages not used use free frames to load another process Increases throughput and resource utilization What if process starts to use its frames? frames has to be paged in again other frames paged out Another type of memory overallocation OS let process allocate a lot of memory OS does not actually allocate anything! process often does not use all allocated memory when process starts using memory, it allocates one page at a time Memory allocated by processes may be larger than RAM may be larger than RAM+swap space! If all processes actually uses all memory we have a problem... optionally, we commit allocated memory to swap make sure there is space in the swap this takes some time, however... 9

Efficient process creation copy on write Do not copy any frames on process creation! flag frames as read-only use the same frames as the old process identical page table, except for the flag copy-on-write copy pages when they are modified if a process writes to a frame trap to kernel kernel allocates new frame copy the old frame restart the write instruction Very efficient if using exec() just after fork() no need to copy the process, and immediately overwrite it Copy-on-Write pages table pages table p new process p write use the same frames trap to kernel on write allocate new frame Memory mapped files Operate on a file as if its content would reside directly in memory portion of file loaded into memory mapped to pages OS responsible to mirror content between disk and memory File can easily be shared between processes Some systems use memory mapping for all file I/O solaris (normal file i/o is a wrapper for memory mapped i/o) 0

Memory mapped files part of file copied to frames frames mapped in page table several processes can share the file as with shared memory End of lecture and end of memory management Virtual memory: demand paging page replacement algos process creation memory mapped files frame allocation thrashing other considerations