COMP 346 WINTER 2018 MEMORY MANAGEMENT (VIRTUAL MEMORY)

Similar documents
a process may be swapped in and out of main memory such that it occupies different regions

Virtual Memory. Chapter 8

Chapter 8 Virtual Memory

Memory Management Virtual Memory

Role of OS in virtual memory management

Virtual Memory. Chapter 8

MEMORY MANAGEMENT/1 CS 409, FALL 2013

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

ECE519 Advanced Operating Systems

Chapter 8 Virtual Memory

Chapter 8 Virtual Memory

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

Process size is independent of the main memory present in the system.

Virtual Memory. control structures and hardware support

Operating Systems: Internals and Design Principles. Chapter 7 Memory Management Seventh Edition William Stallings

Operating Systems CSE 410, Spring Virtual Memory. Stephen Wagner Michigan State University

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

1. Background. 2. Demand Paging

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

Operating Systems Virtual Memory. Lecture 11 Michael O Boyle

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

10: Virtual Memory Management

Lecture 9: Virtual Memory

Virtual Memory Outline

Week 2: Tiina Niklander

Paging Policies, Load control, Page Fault Handling, Case studies January WT 2008/09

Operating System - Virtual Memory

Chapter 9: Virtual Memory

Virtual Memory Management

Page Replacement Algorithms

stack Two-dimensional logical addresses Fixed Allocation Binary Page Table

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

Operating Systems, Fall

Operating Systems Lecture 6: Memory Management II

Perform page replacement. (Fig 8.8 [Stal05])

Virtual Memory. Today.! Virtual memory! Page replacement algorithms! Modeling page replacement algorithms

MEMORY: SWAPPING. Shivaram Venkataraman CS 537, Spring 2019

CS 143A - Principles of Operating Systems

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

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

Introduction to Virtual Memory Management

Eastern Mediterranean University School of Computing and Technology CACHE MEMORY. Computer memory is organized into a hierarchy.

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

The Memory System. Components of the Memory System. Problems with the Memory System. A Solution

CS6401- Operating System UNIT-III STORAGE MANAGEMENT

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

CS 153 Design of Operating Systems Winter 2016

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

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


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

First-In-First-Out (FIFO) Algorithm

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

Chapter 8. Virtual Memory

CPE300: Digital System Architecture and Design

Memory Management. 3. What two registers can be used to provide a simple form of memory protection? Base register Limit Register

Operating Systems. Operating Systems Sina Meraji U of T

CSE 153 Design of Operating Systems

Memory and multiprogramming

Fall COMP3511 Review

Cache memory. Lecture 4. Principles, structure, mapping

Chapter 8: Virtual Memory. Operating System Concepts

Fall 2015 COMP Operating Systems. Lab #8

Virtual Memory Design and Implementation

CSE 4/521 Introduction to Operating Systems. Lecture 27 (Final Exam Review) Summer 2018

Today s class. Operating System Machine Level. Informationsteknologi. Friday, November 16, 2007 Computer Architecture I - Class 12 1

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

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

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

CHAPTER 6 Memory. CMPS375 Class Notes (Chap06) Page 1 / 20 Dr. Kuo-pao Yang

Lecture 12: Demand Paging

Principles of Operating Systems

Chapter 9: Virtual Memory

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

4.1 Paging suffers from and Segmentation suffers from. Ans

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

Memory Management Virtual Memory

Virtual Memory Demand Paging. Virtual Memory Working Set Model

Basic Page Replacement

Operating System Principles: Memory Management Swapping, Paging, and Virtual Memory CS 111. Operating Systems Peter Reiher

OPERATING SYSTEM. Chapter 9: Virtual Memory

Chapter 3 - Memory Management

Cache Memory COE 403. Computer Architecture Prof. Muhamed Mudawar. Computer Engineering Department King Fahd University of Petroleum and Minerals

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

Chapter 9: Virtual Memory

Operating Systems and Computer Networks. Memory Management. Dr.-Ing. Pascal A. Klein

Memory: Paging System

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

Chapter 11: File System Implementation. Objectives

Recall from Tuesday. Our solution to fragmentation is to split up a process s address space into smaller chunks. Physical Memory OS.

Memory: Page Table Structure. CSSE 332 Operating Systems Rose-Hulman Institute of Technology

Reminder: Mechanics of address translation. Paged virtual memory. Reminder: Page Table Entries (PTEs) Demand paging. Page faults

Lecture 2: Memory Systems

Last Class: Demand Paged Virtual Memory

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

CSE 421/521 - Operating Systems Fall Lecture - XXV. Final Review. University at Buffalo

Operating System Concepts

CHAPTER 6 Memory. CMPS375 Class Notes Page 1/ 16 by Kuo-pao Yang

VIRTUAL MEMORY READING: CHAPTER 9

CS370 Operating Systems

Transcription:

COMP 346 WINTER 2018 1 MEMORY MANAGEMENT (VIRTUAL MEMORY)

VIRTUAL MEMORY A process may be broken up into pieces (pages or segments) that do not need to be located contiguously in main memory. Memory references are dynamically translated into physical addresses at run time. A process may be swapped in and out of main memory such that it occupies different regions. What this means: it is not necessary for all pages/segments of a process to be in main memory during execution. Execution can proceed as long as the next instruction and the required data are in main memory. 2

ADVANTAGES OF PARTIAL LOADING More processes can be maintained in main memory. We only load some of the pieces of each process, so there is room for more processes, improving throughput. With more processes in main memory, it is more likely that a process will be in the Ready state at any given time, improving processor utilization. A process can now execute even if it is larger than the main memory size. 3

POSSIBILITY OF THRASHING To accommodate as many processes as possible, only a few pieces of each process are maintained in main memory. But main memory may be full: when the OS brings one piece in, it must swap out another piece. The OS should not swap out a piece of a process just before that piece is needed. If it does this too often this leads to thrashing: The processor spends most of its time swapping pieces rather than executing user instructions. 4

PRINCIPLE OF LOCALITY The principle of locality states that program and data references within a process tend to cluster. Hence, only a few pieces of a process will be needed over a short period of time. Use the principle of locality to make intelligent guesses about which pieces will be needed in the near future to avoid thrashing. 5

ADDRESS TRANSLATION IN A PAGING SYSTEM Translate virtual (logical) address into real (physical) address using page table Virtual address: (page#, offset) Real address: (frame#, offset) A quick review: The page# is used to index the page table and look up the corresponding frame#. The frame# is added to the offset to obtain the real address. 6

PAGING Each page table entry contains a present bit to indicate whether the page is in main memory or not. If it is in main memory: the entry contains the frame# of the corresponding page in main memory. If it is not in main memory: the entry may contain the address of that page on disk, or the page number may be used to index another table (often in the PCB) to obtain the address of that page on disk. Typically, each process has its own page table. 7

ADDRESS TRANSLATION IN A PAGING SYSTEM 8

PAGE TABLES AND VIRTUAL MEMORY Most computer systems support a very large virtual address space. 32 or 64 bits are used for logical addresses. Using 4 KB pages and 32-bit addressing, a page table may have 2 12 * 2 8 = 2 20 entries. The entire page table may take up too much main memory. Hence, page tables are often also stored in virtual memory and are subject to paging. When a process is running, part of its page table must be in main memory (including the page table entry of the currently executing page). 9

MULTILEVEL PAGE TABLES Since a page table will generally require several pages to be stored, one solution is to organize page tables into a multilevel hierarchy: When 2 levels are used (ex: 386, Pentium), the page number is split into two numbers: p1 and p2. First level: root page table (outer page table or page directory). Second level: process page table (user page table). The root page table entries point to process page table entries p1 indexes the outer page table and p2 indexes the resulting page in the process page table. The page directory is always kept in main memory, but part of the process page table may be swapped out. 10

TWO-LEVEL PAGE TABLES 11

TWO-LEVEL PAGE TABLES page of process 12

SEGMENTATION Typically, each process has its own segment table. Similarly to paging, each segment table entry contains a present bit and a modified bit. If the segment is in main memory, the entry contains the starting (base) address and the length of that segment. Other control bits may be present if protection and sharing is managed at the segment level. Logical to physical address translation is similar to paging except that the offset is added to the starting address (instead of being appended). 13

ADDRESS TRANSLATION IN A SEGMENTATION SYSTEM Physical address 14

COMBINED SEGMENTATION AND PAGING Some processors and OS page the segments. Several combinations exists. Here is a simple one: Each process has: one segment table. several page tables: one page table per segment. The virtual address consists of: a segment number: used to index the segment table whose entry gives the starting address of the page table for that segment. a page number: used to index that page table to obtain the corresponding frame number. an offset: used to locate the word within the frame. 15

ADDRESS TRANSLATION IN A COMBINED SEGMENTATION/PAGING SYSTEM 16

STATIC PAGING ALGORITHMS When a process starts, it is allocated a fixed number of frames in main memory. Paging policies define how pages are swapped in and out of frames allocated to the process. 13

BASIC PAGING POLICIES Fetch policy: determines when a page should be loaded into main memory. Replacement policy: when all frames are full, determine which page should be swapped out in favor of a new page. 13

DEMAND PAGING In demand paging, the required pages are not known ahead of time, and cannot be pre-fetched. Instead, pages are loaded on demand at run-time. As a result, replacement policies become a focus. 13

REPLACEMENT ALGORITHMS Optimal policy Selects for replacement the page for which the time to the next reference is the longest. Produces the fewest number of page faults. Impossible to implement (need to know the future), but serves as a standard to compare with the other algorithms: Least recently used (LRU) First-in, first-out (FIFO) Clock 20

LRU POLICY Replaces the page that has not been referenced for the longest time. By the principle of locality, this page is least likely to be referenced in the near future. Performs nearly as well as the optimal policy. Example: A process of 5 pages with an OS that fixes the resident set size to 3 21

FIFO POLICY Treats page frames allocated to a process as a circular buffer; pages removed in round-robin style. When the buffer is full, the page that has been in memory the longest is replaced. A page fetched into memory a long time ago may now have fallen out of use. But a frequently used page is often the oldest, so it will be repeatedly paged out by FIFO. Simple to implement: Requires only a pointer that circles through the page frames of the process. 22

COMPARISON OF FIFO WITH LRU LRU recognizes that pages 2 and 5 are referenced more frequently than others but FIFO does not. FIFO performs relatively poorly. 23

CLOCK POLICY The set of frames that are candidates for replacement (local or global scope) is considered as a circular buffer. When a page is replaced, a pointer is set to point to the next frame in buffer. A use bit for each frame is set to 1 whenever: a page is first loaded into the frame. the page is referenced. When it is time to replace a page, the first frame encountered with the use bit set to 0 is replaced. during the search for replacement, each use bit set to 1 is changed to 0. 24

CLOCK POLICY: AN EXAMPLE 25

COMPARISON OF CLOCK WITH FIFO AND LRU Asterisk indicates that the corresponding use bit is set to 1. Clock protects frequently referenced pages by setting the use bit to 1 at each reference. 26

CLOCK POLICY: COMMENTS If all frames have a use bit of 1, then the pointer will make one full circle setting all use bits to 0. It stops at the starting position because it can now replace the page in that frame. This is similar to FIFO, except frames with the use bit set to 1 are passed over. Numerical experiments tend to show that performance of the Clock algorithm is close to that of LRU. Many OS es use variations of the clock algorithm. Example: Solaris. 27

PROBLEM SOLVING 1 Show the memory representation using the LRU algorithm and calculate the page fault rate. Consider the reference string: R = {0, 1, 0,1, 0, 1, 2, 3, 4, 5, 3, 4, 5, 6, 7, 8, 9} and an allocation of 3 frames for a given process. Tutorial 2 28

SOLUTION Tutorial 2 29