Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.

Slides:



Advertisements
Similar presentations
Module 10: Virtual Memory
Advertisements

Chapter 10: Virtual Memory
Background Virtual memory – separation of user logical memory from physical memory. Only part of the program needs to be in memory for execution. Logical.
Chapter 9: Virtual Memory
1 CSC 539: Operating Systems Structure and Design Spring 2005 Virtual memory  background  demand paging  page replacement: FIFO, OPT, LRU  allocation.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Lecture 13: Main Memory (Chapter 8)
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
Module 10: Virtual Memory Background Demand Paging Performance of Demand Paging Page Replacement Page-Replacement Algorithms Allocation of Frames Thrashing.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts Chapter 9: Virtual Memory Background Demand Paging.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Segmentation and Paging Considerations
Virtual-Memory Management
Gordon College Stephen Brinton
Virtual Memory CS 3100 Virutal Memory.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
03/26/2010CSCI 315 Operating Systems Design1 Virtual Memory Notice: The slides for this lecture have been largely based on those accompanying an earlier.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
Virtual Memory Chapter 8. Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
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.
1 Chapter 8 Virtual Memory Virtual memory is a storage allocation scheme in which secondary memory can be addressed as though it were part of main memory.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
Chapter 9: Virtual Memory. Background Demand Paging Copy-on-Write Page Replacement Allocation of Frames Thrashing Memory-Mapped Files Allocating Kernel.
CSS430 Virtual Memory Textbook Ch9
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
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.
Rensselaer Polytechnic Institute CSCI-4210 – Operating Systems David Goldschmidt, Ph.D.
Part 8: Virtual Memory. Silberschatz, Galvin and Gagne ©2005 Virtual vs. Physical Address Space Each process has its own virtual address space, which.
Operating Systems Chapter 8
CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
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.
#include pthread_mutex_t sem_mut = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t cond_mut = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
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.
NETW3005 Virtual Memory. Reading For this lecture, you should have read Chapter 9 (Sections 1-7). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory2.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
10.1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual-Memory Management.
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.
Chapter 9: Virtual Memory
OPERATING SYSTEM CONCEPTS AND PRACTISE
UNIT–IV: Memory Management
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 6 Virtual Memory
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Virtual Memory.
Chapter 8 & 9 Main Memory and Virtual Memory
Presentation transcript:

Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.

 A noncontiguous memory allocation scheme avoids the external fragmentation problem  Slice up physical memory into fixed-sized blocks called frames ▪ Sizes typically range from 2 16 and up!  Slice up logical memory into fixed-sized blocks called pages  Allocate pages into frames ▪ Note that frame size equals page size

 When a process of size n pages is ready to run, operating system finds n free frames  The OS keeps track of pages via a page table main memory process P i == in use == free

 Page tables map logical memory addresses to physical memory addresses

 Covers a logical address space of size 2 m with page size 2 n page number page offset p d (m – n)(n)

 Use page table caching at the hardware level to speed address translation  Hardware-level translation look-aside buffer (TLB)

 Segmentation is a memory-management scheme that corresponds to logical segments of a user program  A segment resides in a contiguous block of memory  Segments are numbered and referred to by a pair

 Logical segments map to physical memory

 A segment table maps a pair to a physical address  Each table entry has:  A segment base containing the starting physical address where the segment resides  A segment limit specifying the length of the segment

 Only part of a process needs to be loaded into memory for it to start its execution  Virtual memory further separates logical memory and physical memory  Logical (or virtual) address space can be larger than physical address space  Allows physical address space to be shared by several processes  Enables quicker process creation

 Unused pages are stored on disk

 Multiple processes can share common libraries or data by mapping virtual pages to shared physical pages  More efficient use of physical memory space

 When a page of memory is requested, if it’s not in physical memory, load page from disk  i.e. on demand  Less I/O required  Less physical memory  Faster user response times (usually)  More user processes

 Virtual memory policies include:  The fetch policy governs when a page should be loaded into memory  The placement policy specifies where a page is loaded into physical memory  The replacement policy determines which existing page in memory should be replaced

 Page allocation:  In a static allocation scheme, the number of frames per process is fixed  In a dynamic allocation scheme, the number of frames per process varies  In an equal allocation scheme, all processes have an equal number of frames  In a proportional allocation scheme, processes are allocated frames in proportion to size, priority, etc.

 Associate a valid/invalid bit with each page table entry  Initially set all entries to i  During address translation, if valid/invalid bit is v, page is already in memory  Otherwise, if bit is i, a page fault occurs v v v v i i i …. frame # valid/invalid bit page table

 Page faults are trapped by the OS:  When an invalid reference occurs in the page table  When a page is not yet in the page table  Page fault recovery:  Get free frame from physical memory  Swap desired page into free frame  Reset page table entry  Set validation bit to v  Restart instruction that caused the page fault

 Page faults are costly!

 The page fault rate p is in the range [0.0, 1.0]:  If p is 0.0, no page faults occur  If p is 1.0, every page request is a page fault  Typically p is very low....  The effective memory-access time is  (1 – p) x physical-memory-access + p x ( page-fault-overhead + swap-page-out + swap-page-in + restart-overhead )

 Given:  Memory access time is 200 nanoseconds  Average page-fault service time is 8 milliseconds  The effective memory access time is  (1 – p) x 200ns + p x 8ms =  200ns – 200ns p + p x 8,000,000ns =  200ns + 7,999,800 p

 If a process does not have enough pages, the page-fault rate is high, leading to thrashing  Process is busy swapping pages in and out of memory  Low CPU utilization  Operating system might think it needs to increase the degree of multiprogramming! ▪ More processes added, further degrading performance

 Remember the Principle of Locality

 Future memory references in a given process will likely be local to previous memory references  This phenomenon is called the principle of locality  A process executes in a series of phases, spending a finite amount of time performing memory references in each phase

 Example graph of page faults versus total number of allocated frames

 Operating system should allocate enough frames for the current locality of a process:  What happens when too few frames are allocated?  What happens when too many frames are allocated?

 Example of a single process:

 Dynamic page fault frequency scheme

 How do we identify the victim?

 Page replacement algorithms include:  First-in-first-out (FIFO)  Optimal (OPT)  Least recently used (LRU)  Least frequently used (LFU)  Page fault frequency scheme (introduced earlier)  Working set apply these algorithms to a page reference stream

 The above is a 3-frame memory  How many page faults occur if we use a 4-frame memory instead?

 Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5  How many page faults occur with a 3-frame memory?  How many page faults occur with a 4-frame memory?

 Belady’s Anomaly:  More frames may lead to more page faults!

 Replace pages that will not be used for the longest amount of time FIFO: OPT:

 Replace pages that have not been used for the longest amount of time

 Similar to LRU, but replace least frequently used pages  Requires usage counts  Initial page replacements are swapped out quickly because their usage counts are 1

 For each process, maintain a working set of pages referenced by the process during the most recent w page references  How do we choose w?

 Let d be the sum of the sizes of the working sets of all active processes  Let F be the total number of frames  If d < F, then the operating system can allow additional processes to enter the system  If d > F, then the operating system must suspend one or more active processes ▪ Otherwise thrashing will occur!

 Windows XP uses demand paging with clustering (which loads pages surrounding the page fault)  Processes are assigned a working set minimum and a working set maximum  The working set minimum is the minimum number of pages a process is guaranteed to have in physical memory  Likewise, a process may be assigned pages up to its working set maximum

 When the amount of free memory in the system falls below a threshold, automatic working set trimming is performed  Increases the amount of free memory  Removes pages from processes that have pages in excess of their working set minimum