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
IOS103 OPERATING SYSTEM VIRTUAL MEMORY.
Chapter 9 Virtual Memory Bernard Chen 2007 Spring.
Virtual Memory Management G. Anuradha Ref:- Galvin.
Virtual Memory Operating System Concepts chapter 9 CS 355
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.
Virtual Memory Management
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.
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.
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.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Memory Management ◦ Operating Systems ◦ CS550. Paging and Segmentation  Non-contiguous memory allocation  Fragmentation is a serious problem with contiguous.
Virtual Memory.
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 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.
CS212: OPERATING SYSTEM Lecture 6: Virtual-Memory Management 1 Computer Science Department.
Computer Studies (AL) Memory Management Virtual Memory I.
Silberschatz, Galvin and Gagne Operating System Concepts Chapter 9: Virtual Memory.
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 Page Replacement Allocation of.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 9: Virtual Memory.
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.
Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.
CS307 Operating Systems Virtual Memory Fan Wu Department of Computer Science and Engineering Shanghai Jiao Tong University Spring 2012.
Virtual Memory Various memory management techniques have been discussed. All these strategies have the same goal: to keep many processes in memory simultaneously.
Silberschatz, Galvin and Gagne  Operating System Concepts Virtual Memory Virtual memory – separation of user logical memory from physical memory.
1 Virtual Memory. Cache memory: provides illusion of very high speed Virtual memory: provides illusion of very large size Main memory: reasonable cost,
Lecture 19 Virtual Memory Demand Paging. Background Virtual memory – separation of user logical memory from physical memory. –Only part of the program.
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 9: Virtual-Memory Management 9.1 Background.
1 Lecture 8: Virtual Memory Operating System Fall 2006.
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.
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
Virtual Memory CSSE 332 Operating Systems
Chapter 9: Virtual Memory – Part I
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Operating Systems Virtual Memory Alok Kumar Jagadev.
Module 9: Virtual Memory
Chapter 9: Virtual Memory
O.S Lecture 13 Virtual Memory.
Chapter 9: Virtual-Memory Management
Operating Systems Lecture November 2018.
What Happens if There is no Free Frame?
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 6 Virtual Memory
Contents Memory types & memory hierarchy Virtual memory (VM)
Chapter 9 Virtual Memory
Module 9: Virtual Memory
Chapter 9: Virtual Memory CSS503 Systems Programming
Chapter 9: Virtual Memory
Virtual Memory.
Chapter 8 & 9 Main Memory and Virtual Memory
CSE 542: Operating Systems
Presentation transcript:

Virtual Memory

Virtual Address Space, Physical Address Space, Swap Space Virtual memory is the separation of user logical memory from physical memory. The programmer no longer needs to worry about the amount of physical memory available. The Virtual Address Space of a process refers to the logical (or virtual) view of how a process is stored in memory. physical memory may be organized in page frames physical page frames assigned to a process may not be contiguous.

Virtual Memory, Sharing Virtual memory allows files and memory to be shared by several different processes through page sharing.

How works the Virtual Memory? Large program example Fetch Policy (Page load policy to the physical memory) When the page will be brought to the main memory ? Demand paging Prepaging

Demand Paging pages are only loaded when they are demanded during program execution pages that are never accessed are thus never loaded into physical memory. Lazy Swapper More pager than swapper Brings the pages only by demand A demand-paging system is similar to a paging system with swapping

Valid Invalid bit, hardware support With demand paging, we need some form of hardware support to distinguish between those pages that are in memory and those pages that are on the disk. page table @B 8 9 @D @H @E @G The valid-invalid bit scheme can be used for this purpose. When this bit is set to "valid," this value indicates that the associated page is both legal and in memory. If the bit is set to "invalid," the page either is not valid (that is, not in the logical address space of the process), or is valid but is currently on the disk (then the entry points to page address on the disk).

Page Fault Service the page-fault interrupt. Read in the page. 1. Page request 2. If V=0 (not valid) then Page Fault Occurs (the page is not in RAM) page table @B 8 9 @D @H @E @F We are faced with three major components of the page-fault service time: Service the page-fault interrupt. Read in the page. Restart the process.

Page Fault handling

Page Fault handling need to be able to restart any instruction after a page fault. The restart would require fetching the instruction again decoding it again fetching the two operands again and then adding again. However, there is not much repeated work (less than one complete instruction), and the repetition is necessary only when a page fault occurs.

Copy on Write In the extreme case, we could start executing a process with no pages in memory. On the first instruction the process immediately faults for the page. After this page is brought into memory, the process continues to execute, faulting as necessary until every page that it needs is in memory. Process creation using the fork() system call may initially bypass the need for demand paging by using a technique similar to page sharing. Copy the page only if the process writes on it This technique provides for rapid process creation and minimizes the number of new pages that must be allocated to the newly created process.

Why to do Page Replacement ? What happens if there is no free frame to allocate ? Do page replacement. Find some page in memory that is not in use now and swap it out. Now you have a free frame. Bring new page here.

How is done the Page Replacement ? Page fault service algorithm rewritten for Page Replacement Find the location of the desired page on the disk. Find a free frame: a. If there is a free frame, use it. b. If there is no free frame, use a page-replacement algorithm to select a victim frame. c. Write the victim frame to the disk; change the page and frame tables accordingly (change to invalid). Modify to f, valid Read the desired page into the newly freed frame; change the page and frame tables (change to valid). Restart the user process.

Reduce the Page Replacement time Notice that, if no frames are free, two page transfers (one out and one in) are required. This situation effectively doubles the page-fault service time and increases the effective access time accordingly. We can reduce this overhead by using a modify bit (or dirty bit). each page or frame has a modify bit associated with it in the hardware If the page has not been modified since it was read into memory we need not write the memory page to the disk: it is already there. This scheme can significantly reduce the time required to service a page fault, since it reduces I/O time by one-half if the page has not been modified.

Replacement Policies Random Replacement Memory manager must decide which page to swap out of primary memory in order to load the requested page Random Replacement F I O

Replacement Policies

Replacement Policies

Thrashing, Locality Theoretically, some programs may access several new pages of memory with each instruction execution (one page for the instruction and many for data), possibly causing multiple page faults per instruction. This situation would result in unacceptable system performance. Fortunately, analysis of running processes shows that this behavior is exceedingly unlikely. Programs tend to have locality of reference which results in reasonable performance from demand paging. A process is thrashing if it is spending more time paging than executing.

Frame Allocation to prevent Thrashing Setup page-fault “normal” upper and lower limits for “your” OS. Allocate some amount of frames for each process Monitor the page fault rate If it’s high add more frames for processes. If page fault rate is low you can decrease the number of frames per process

Prepaging In a system using the working-set model, for example, we keep with each process a list of the pages in its working set If we must suspend a process (due to an I/O wait or a lack of free frames), we remember the working set for that process. When the process is to be resumed (I/O completion or enough free frames), we automatically bring back into memory its entire working set before restarting the process.

Virtual Memory Example The process logical space has 4 pages. The following logical pages of the process 0,2 are placed in the physical memory following frames 2,5 Show the above situation on the below tables filling all columns Page Table   Frame Valid 2 v 1 i 5 3 4 Physical Memory   Frame N: Con tent Usage frequency 10 1 20 2 A 30 3 40 4 50 5 C 60 Virtual Memory   Page N: Content A 1 B 2 C 3 D The next instruction of the process performs the following operation z = x + y The logical addresses of x, y, z are in the following pages of logical space: z – 0 x – 2 y – 3

Virtual Memory Example The next instruction of the process performs the following operation z = x + y The logical addresses of x, y, z are in the following pages of logical space: z – 0 x – 2 y – 3 Show the situation of memory resources on below tables after the operation. If needed use the page replacement policy “Least Frequently Used”. After replacing set the “Usage Frequency” value to 0. Page Table   Frame Valid 2 v 1 i 5 3  0 4 Physical Memory   Frame N: Con tent Usage frequency  D 1 20 2 A 30 3 40 4 50 5 C 60 Virtual Memory   Page N: Content A 1 B 2 C 3 D