Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 17: Wrapping up Virtual Memory.

Slides:



Advertisements
Similar presentations
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Advertisements

Chapter 9: Virtual Memory
國立台灣大學 資訊工程學系 Chapter 9: Virtual Memory. 資工系網媒所 NEWS 實驗室 Objectives To describe the benefits of a virtual memory system To explain the concepts of demand.
Chapter 9: Virtual Memory Adapted to COP4610 by Robert van Engelen.
Page 15/4/2015 CSE 30341: Operating Systems Principles Allocation of Frames  How should the OS distribute the frames among the various processes?  Each.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory OSC: Chapter 9. Demand Paging Copy-on-Write Page Replacement.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Module 9: Virtual Memory
Advanced Operating Systems - Spring 2009 Lecture 17 – March 23, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
1 Thursday, July 06, 2006 “Experience is something you don't get until just after you need it.” - Olivier.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 9: Virtual Memory Background Demand Paging.
Virtual Memory Introduction to Operating Systems: Module 9.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write.
Segmentation and Paging Considerations
Virtual-Memory Management
Gordon College Stephen Brinton
Virtual Memory CS 3100 Virutal Memory.
Chapter 9: Virtual Memory
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 9: Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual-Memory Management.
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 10: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 10: Virtual Memory.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
Page 19/17/2015 CSE 30341: Operating Systems Principles Optimal Algorithm  Replace page that will not be used for longest period of time  Used for measuring.
Chapter 9: Virtual-Memory Management
Chapter 9: Virtual Memory. 9.2CSCI 380 – Operating Systems Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Chapter 9: Virtual-Memory Management. 9.2Operating System Principles Chapter 9: Virtual-Memory Management Background Demand Paging Copy-on-Write Page.
1 CMSC421: Principles of Operating Systems Nilanjan Banerjee Principles of Operating Systems Acknowledgments: Some of the slides are adapted from Prof.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Background Virtual memory –
Operating System Concepts 7th Edition Abraham SilBerschatz Peter Baer Galvin Greg Gagne Prerequisite: CSE212.
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 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Chapter 9: Virtual Memory Background.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Advanced Operating Systems - Spring 2009 Lecture 16 – March 18, 2009 Dan C. Marinescu Office: HEC 439 B. Office hours:
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples Operating.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Outline n Background n Demand.
Chapter 9: Virtual Memory. 9.2 Chapter 9: Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped.
Saurav Karmakar. Chapter 9: Virtual Memory  Background  Demand Paging  Copy-on-Write  Page Replacement  Allocation of Frames  Thrashing  Memory-Mapped.
10.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts with Java Chapter 10: Virtual Memory Background Demand Paging Process Creation Page.
9.1 Silberschatz, Galvin and Gagne ©2005 Operating System Principles 9.5 Allocation of Frames Each process needs minimum number of pages Example: machine.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 9: Virtual Memory.
Chapter 9: Virtual Memory
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Silberschatz, Galvin and Gagne ©2007 Operating System Concepts with Java – 7 th Edition, Nov 15, 2006 Chapter 9: Virtual Memory.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 9: Virtual Memory.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 9: Virtual Memory Background Demand Paging Process.
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts– 8 th Edition Chapter 9: Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts– 8 th Edition Virtual Memory.
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Chapter 9: Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual-Memory Management.
操作系统原理及应用 董恺 计算机科学与工程学院、软件学院 江苏省网络与信息安全重点实验室.
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 10: Virtual Memory
Presentation transcript:

Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 17: Wrapping up Virtual Memory

14.2 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Segmentation Memory-management scheme that supports user view of memory A program is a collection of segments A segment is a logical unit such as: main program procedure function method object local variables, global variables common block stack symbol table arrays

14.3 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition User’s View of a Program

14.4 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Logical View of Segmentation user spacephysical memory space

14.5 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Segmentation Architecture Logical address consists of a two tuple:, Segment table – maps two-dimensional physical addresses; each table entry has: base – contains the starting physical address where the segments reside in memory limit – specifies the length of the segment Segment-table base register (STBR) points to the segment table’s location in memory Segment-table length register (STLR) indicates number of segments used by a program; segment number s is legal if s < STLR

14.6 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Segmentation Architecture (Cont.) Protection With each entry in segment table associate:  validation bit = 0  illegal segment  read/write/execute privileges Protection bits associated with segments; code sharing occurs at segment level Since segments vary in length, memory allocation is a dynamic storage-allocation problem

14.7 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Segmentation Hardware

14.8 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Example of Segmentation

14.9 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Thrashing (Cont.)

14.10 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Demand Paging and Thrashing Why does demand paging work? Locality model Process migrates from one locality to another Localities may overlap Why does thrashing occur?  size of locality > total memory size Limit effects by using local or priority page replacement

14.11 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Locality In A Memory-Reference Pattern

14.12 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Working-Set Model   working-set window  a fixed number of page references Example: 10,000 instructions WSS i (working set of Process P i ) = total number of pages referenced in the most recent  (varies in time) if  too small will not encompass entire locality if  too large will encompass several localities if  =   will encompass entire program D =  WSS i  total demand frames Approximation of locality if D > m  Thrashing Policy if D > m, then suspend or swap out one of the processes

14.13 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Working-set model

14.14 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Keeping Track of the Working Set Approximate with interval timer + a reference bit Example:  = 10,000 Timer interrupts after every 5000 time units Keep in memory 2 bits for each page Whenever a timer interrupts copy and sets the values of all reference bits to 0 If one of the bits in memory = 1  page in working set Why is this not completely accurate? Improvement = 10 bits and interrupt every 1000 time units

14.15 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Page-Fault Frequency More direct approach than WSS Establish “acceptable” page-fault frequency rate and use local replacement policy If actual rate too low, process loses frame If actual rate too high, process gains frame

14.16 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Working Sets and Page Fault Rates

14.17 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Problem Sketch rough graphs (“back of napkin”) illustrating the relationships among the following quantities. Note any important assumptions underlying your analysis. Page fault rate as a function of page size. What page sizes are typical for current processors and operating systems? CPU utilization as a function of the degree of multiprogramming. Consider a uni-processor system. Memory fragmentation as a function of page size. Is that internal or external?

14.18 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Memory-Mapped Files Memory-mapped file I/O allows file I/O to be treated as routine memory access by mapping a disk block to a page in memory A file is initially read using demand paging A page-sized portion of the file is read from the file system into a physical page Subsequent reads/writes to/from the file are treated as ordinary memory accesses Simplifies and speeds file access by driving file I/O through memory rather than read() and write() system calls Also allows several processes to map the same file allowing the pages in memory to be shared But when does written data make it to disk? Periodically and / or at file close() time For example, when the pager scans for dirty pages

14.19 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Memory-Mapped File Technique for all I/O Some OSes uses memory mapped files for standard I/O Process can explicitly request memory mapping a file via mmap() system call Now file mapped into process address space For standard I/O ( open(), read(), write(), close() ), mmap anyway But map file into kernel address space Process still does read() and write()  Copies data to and from kernel space and user space Uses efficient memory management subsystem  Avoids needing separate subsystem COW can be used for read/write non-shared pages Memory mapped files can be used for shared memory (although again via separate system calls)

14.20 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Memory Mapped Files

14.21 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Memory-Mapped Shared Memory in Windows

14.22 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Allocating Kernel Memory Treated differently from user memory Often allocated from a free-memory pool Kernel requests memory for structures of varying sizes Some kernel memory needs to be contiguous  I.e., for device I/O

14.23 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Buddy System Allocates memory from fixed-size segment consisting of physically-contiguous pages Memory allocated using power-of-2 allocator Satisfies requests in units sized as power of 2 Request rounded up to next highest power of 2 When smaller allocation needed than is available, current chunk split into two buddies of next-lower power of 2  Continue until appropriate sized chunk available For example, assume 256KB chunk available, kernel requests 21KB Split into A L and A r of 128KB each  One further divided into B L and B R of 64KB – One further into C L and C R of 32KB each – one used to satisfy request Advantage – quickly coalesce unused chunks into larger chunk Disadvantage - fragmentation

14.24 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Buddy System Allocator

14.25 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Slab Allocator Alternate strategy Slab is one or more physically contiguous pages Cache consists of one or more slabs Single cache for each unique kernel data structure Each cache filled with objects – instantiations of the data structure When cache created, filled with objects marked as free When structures stored, objects marked as used If slab is full of used objects, next object allocated from empty slab If no empty slabs, new slab allocated Benefits include no fragmentation, fast memory request satisfaction

14.26 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Slab Allocation

14.27 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Other Considerations -- Prepaging To reduce the large number of page faults that occurs at process startup Prepage all or some of the pages a process will need, before they are referenced Risk of wasted I/O and memory Assume s pages are prepaged and α of the pages is used Is cost of s * α save pages faults > or < than the cost of prepaging s * (1- α) unnecessary pages? α near zero  prepaging loses

14.28 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Other Issues – Page Size Sometimes OS designers have a choice Especially if running on custom-built CPU Page size selection must take into consideration: Fragmentation Page table size Resolution I/O overhead Number of page faults Locality TLB size and effectiveness Always power of 2, usually in the range 2 12 (4,096 bytes) to 2 22 (4,194,304 bytes) On average, growing over time

14.29 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Other Issues – TLB Reach TLB Reach - The amount of memory accessible from the TLB TLB Reach = (TLB Size) X (Page Size) Ideally, the working set of each process is stored in the TLB Otherwise higher cost for resolving page-> frame translation To increase TLB Reach: Increase the Page Size: increase in fragmentation Provide Multiple Page Sizes

14.30 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Other Issues – Program Structure Program structure l Int[128,128] data; Each row is stored in one page Program 1 for (j = 0; j <128; j++) for (i = 0; i < 128; i++) data[i,j] = 0; How many page faults? Program 2 for (i = 0; i < 128; i++) for (j = 0; j < 128; j++) data[i,j] = 0; How many page faults?

14.31 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Other Issues – I/O interlock I/O Interlock – Pages must sometimes be locked into memory: e.g., pages that are used for copying a file from a device must be locked from being selected for eviction by a page replacement algorithm Solutions: I/O to system memory (extra copying to user memory) Lock pages in memory (“pin” them) (lock bit)  Risky if OS bugs never unlock a page

14.32 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition OS Examples: Windows XP Uses demand paging with clustering. Clustering brings in pages surrounding the faulting page Processes are assigned working set minimum and working set maximum (50 and 345 pages most common) Working set minimum is the minimum number of pages the process is guaranteed to have in memory A process may be assigned as many pages up to its working set maximum When the amount of free memory in the system falls below a threshold, automatic working set trimming restores the amount of free memory by removing pages from processes that have pages in excess of their working set minimum Decision on which pages to trip is CPU type dependent

14.33 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition OS Examples: Solaris Maintains a list of free pages to assign faulting processes Lotsfree – threshold parameter (amount of free memory) to begin paging Desfree – threshold parameter to increasing paging Minfree – threshold parameter to being swapping Paging is performed by pageout process Pageout scans pages using modified clock algorithm Scanrate is the rate at which pages are scanned. This ranges from slowscan to fastscan Pageout is called more frequently depending upon the amount of free memory available Priority paging gives priority to process code pages

14.34 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Second-Chance (clock) Page-Replacement Algorithm

14.35 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Solaris 2 Page Scanner