Lecture 3 part2 : Virtual Memory

Slides:



Advertisements
Similar presentations
Chapter 10: Virtual Memory
Advertisements

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
Chapter 9 Virtual Memory Bernard Chen 2007 Spring.
Virtual Memory Management G. Anuradha Ref:- Galvin.
Virtual Memory Operating System Concepts chapter 9 CS 355
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.
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 Management
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.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement.
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.
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.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
Cosc 4740 Chapter 8 Virtual Memory. Background Code needs to be in memory to execute, but entire program rarely used –Error code, unusual routines, large.
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 ©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.
Virtual Memory. Background Virtual memory is a technique that allows execution of processes that may not be completely in the physical memory. Virtual.
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.
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.
CSC 360, Instructor: Kui Wu Memory Management II: Virtual Memory.
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.
Lecture 19 Virtual Memory Demand Paging. Background Virtual memory – separation of user logical memory from physical memory. –Only part of the program.
Chapter 9: Virtual-Memory Management. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Principles Chapter 9: Virtual-Memory Management 9.1 Background.
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.
1 Contents Memory types & memory hierarchy Virtual memory (VM) Page replacement algorithms in case of VM.
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
Topic 8 (Textbook - Chapter 9) Virtual 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
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 6 Virtual Memory
Chapter 10: Virtual Memory
Contents Memory types & memory hierarchy Virtual memory (VM)
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Virtual Memory.
Chapter 8 & 9 Main Memory and Virtual Memory
Presentation transcript:

Lecture 3 part2 : Virtual Memory

Virtual Memory Background Demand Paging Copy-on-Write Page Replacement Memory-Mapped Files

Objectives To describe the benefits of a virtual memory system To explain the concepts of demand paging, page-replacement algorithms, and allocation of page frames To discuss the principle of the working-set model To examine the relationship between shared memory and memory-mapped files To explore how kernel memory is managed

Background Code needs to be in memory to execute, but entire program rarely used Entire program code not needed at same time Consider ability to execute partially-loaded program Each program takes less memory while running -> more programs run at the same time Increased CPU utilization and throughput with no increase in response time or turnaround time Less I/O needed to load or swap programs into memory -> each user program runs faster

Background (Cont.) Virtual memory – separation of user logical memory from physical memory Only part of the program needs to be in memory for execution Logical address space can therefore be much larger than physical address space Allows address spaces to be shared by several processes Allows for more efficient process creation More programs running concurrently Less I/O needed to load or swap processes

Background (Cont.) Virtual address space – logical view of how process is stored in memory Usually start at address 0, contiguous addresses until end of space Meanwhile, physical memory organized in page frames MMU must map logical to physical Virtual memory can be implemented via: Demand paging Demand segmentation : Virtual memory هي ذاكرة إضافية و مكان وجودها هو القرص الصلب و هي جزء مألوف في أغلب أنظمة التشغيل، فأغلب أجهزة الحاسب هذه الأيام تحتوي على 1GB أو 2GB وربما 4GB ذاكرة رام، ولكن للأسف فهذا القدر من الذاكرة غير كافي لتشغيل مجموعة من البرامج في وقت واحد مثل برنامج تحرير صور ومحرر كتابة ومستعرض إنترنتوبرنامج بريد إلكتروني، فإن لم يكن لديك ذاكرة ظاهرية فلن تعمل هذه البرامج وستحصل على رسالة تطلب منك إغلاق بعض التطبيقات لتحرير جزء من الذاكرة، مع وجود الذاكرة الظاهرية سيقوم الكمبيوتر بالبحث عن أجزاء غير مستعملة باستمرار من الذاكرة الرام ويقوم بنسخها على القرص الصلب وهذا يحرر قسما من الذاكرة الرام(ram) ليتم استخدامه في تشغيل التطبيقات الإضافية، هذا الأمر يحدث بشكل تلقائي لدرجة أنك لا تحس به ويجعل جهازك يحس أن لديه ذاكرة أكبر مما هي عليه.

Virtual Memory That is Larger Than Physical Memory

Virtual-address Space a virtual address space (VAS) or address space is the set of ranges of virtual addresses that an operating system makes available to a process.

Demand Paging Could bring entire process into memory at load time Or bring a page into memory only when it is needed Less I/O needed, no unnecessary I/O Less memory needed Faster response More users Similar to paging system with swapping (diagram on right) Page is needed  reference to it invalid reference  abort not-in-memory  bring to memory Lazy swapper – never swaps a page into memory unless page will be needed Swapper that deals with pages is a pager

Basic Concepts With swapping, pager guesses which pages will be used before swapping out again Instead, pager brings in only those pages into memory How to determine that set of pages? Need new MMU functionality to implement demand paging If pages needed are already memory resident If page needed and not memory resident Need to detect and load the page into memory from storage

Valid-Invalid Bit With each page table entry a valid–invalid bit is associated (v  in-memory – memory resident, i  not-in-memory) Initially valid–invalid bit is set to i on all entries Example of a page table snapshot: During MMU address translation, if valid–invalid bit in page table entry is i  page fault

Page Table When Some Pages Are Not in Main Memory

Page Fault If there is a reference to a page, first reference to that page will trap to operating system: page fault Operating system looks at another table to decide: Invalid reference  abort Just not in memory Find free frame Swap page into frame via scheduled disk operation Reset tables to indicate page now in memory Set validation bit = v Restart the instruction that caused the page fault

Steps in Handling a Page Fault

Performance of Demand Paging Stages in Demand Paging (worse case) Trap to the operating system Save the user registers and process state Determine that the interrupt was a page fault Check that the page reference was legal and determine the location of the page on the disk Issue a read from the disk to a free frame: Wait in a queue for this device until the read request is serviced Wait for the device seek and/or latency time Begin the transfer of the page to a free frame While waiting, allocate the CPU to some other user Receive an interrupt from the disk I/O subsystem (I/O completed) Save the registers and process state for the other user Determine that the interrupt was from the disk Correct the page table and other tables to show page is now in memory Wait for the CPU to be allocated to this process again Restore the user registers, process state, and new page table, and then resume the interrupted instruction

Copy-on-Write Copy-on-Write (COW) allows both parent and child processes to initially share the same pages in memory If either process modifies a shared page, only then is the page copied COW allows more efficient process creation as only modified pages are copied

Before Process 1 Modifies Page C

After Process 1 Modifies Page C

What Happens if There is no Free Frame? Page replacement – find some page in memory, but not really in use, page it out Same page may be brought into memory several times

Page Replacement Prevent over-allocation of memory by modifying page-fault service routine to include page replacement Use modify (dirty) bit to reduce overhead of page transfers – only modified pages are written to disk Page replacement completes separation between logical memory and physical memory – large virtual memory can be provided on a smaller physical memory

Need For Page Replacement

Basic Page Replacement Find the location of the desired page on disk Find a free frame: - If there is a free frame, use it - If there is no free frame, use a page replacement algorithm to select a victim frame Bring the desired page into the (newly) free frame; update the page and frame tables Continue the process by restarting the instruction that caused the trap

Page Replacement

First-In-First-Out (FIFO) Algorithm Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 3 frames (3 pages can be in memory at a time per process) Can vary by reference string: consider 1,2,3,4,1,2,5,1,2,3,4,5 15 page faults

Optimal Algorithm Replace page that will not be used for longest period of time 9 is optimal for the example With only nine page faults, optimal replacement is much better than a FIFO algorithm, which results in fifteen faults. Unfortunately, the optimal page-replacement algorithm is difficult to implement, because it requires future knowledge of the reference string.

Least Recently Used (LRU) Algorithm Use past knowledge rather than future Replace page that has not been used in the most amount of time Associate time of last use with each page 12 faults – better than FIFO but worse than OPT Generally good algorithm and frequently used

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