NETW3005 Virtual Memory. Reading For this lecture, you should have read Chapter 9 (Sections 1-7). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory2.

Slides:



Advertisements
Similar presentations
Page Replacement Algorithms
Advertisements

Module 10: Virtual Memory
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
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 36 Virtual Memory Read.
Virtual Memory Management G. Anuradha Ref:- Galvin.
Virtual Memory Operating System Concepts chapter 9 CS 355
Page 15/4/2015 CSE 30341: Operating Systems Principles Allocation of Frames  How should the OS distribute the frames among the various processes?  Each.
Silberschatz, Galvin and Gagne  2002 Modified for CSCI 399, Royden, Operating System Concepts Operating Systems Lecture 38 Frame Allocation Read.
03/31/2004CSCI 315 Operating Systems Design1 Allocation of Frames & Thrashing (Virtual Memory)
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 ©2009 Operating System Concepts – 8 th Edition, Lecture 15: Background Information for the VMWare ESX Memory Management.
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.
1 Thursday, July 06, 2006 “Experience is something you don't get until just after you need it.” - Olivier.
Virtual Memory Background Demand Paging Performance of Demand Paging
Virtual Memory Introduction to Operating Systems: Module 9.
Segmentation and Paging Considerations
Gordon College Stephen Brinton
Memory Management Design & Implementation Segmentation Chapter 4.
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Virtual Memory.
1 Virtual Memory vs. Physical Memory So far, all of a job’s virtual address space must be in physical memory However, many parts of programs are never.
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.
Instructor: Umar KalimNUST Institute of Information Technology Operating Systems Revisiting Virtual Memory.
Computer Organization and Architecture
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition, Chapter 9: Virtual Memory.
Virtual Memory Basic Concepts Demand Paging
03/29/2004CSCI 315 Operating Systems Design1 Page Replacement Algorithms (Virtual Memory)
Rensselaer Polytechnic Institute CSC 432 – Operating Systems David Goldschmidt, Ph.D.
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.
MEMORY MANAGEMENT Presented By:- Lect. Puneet Gupta G.P.C.G. Patiala.
1 Virtual Memory Chapter 8. 2 Hardware and Control Structures Memory references are dynamically translated into physical addresses at run time –A process.
Silberschatz, Galvin and Gagne ©2009 Operating System Concepts – 8 th Edition Virtual Memory.
Operating Systems CMPSC 473 Virtual Memory Management (3) November – Lecture 20 Instructor: Bhuvan Urgaonkar.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 10: Virtual Memory Background Demand Paging Page Replacement Allocation of.
9.1 Silberschatz, Galvin and Gagne ©2003 Operating System Concepts Chapter 9: Virtual-Memory Management Background Demand Paging Page Replacement Allocation.
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.
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.
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.
Memory Management OS Fazal Rehman Shamil. swapping Swapping concept comes in terms of process scheduling. Swapping is basically implemented by Medium.
1 Chapter 10: Virtual Memory Background Demand Paging Process Creation Page Replacement Allocation of Frames Thrashing Operating System Examples (not covered.
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 Background Virtual memory – separation of user logical memory.
Chapter 9: Virtual Memory
OPERATING SYSTEM CONCEPTS AND PRACTISE
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
Chapter 9: Virtual-Memory Management
What Happens if There is no Free Frame?
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Operating Systems CMPSC 473
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Virtual Memory.
Presentation transcript:

NETW3005 Virtual Memory

Reading For this lecture, you should have read Chapter 9 (Sections 1-7). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory2

Last lecture: Memory management Context –primary, secondary storage –memory access by processes Logical and physical addresses Memory allocation & fragmentation Paging Segmentation NETW3005 (Operating Systems) Lecture 08 - Virtual Memory3

This lecture: Virtual memory Demand paging Page replacement algorithms Frame allocation Thrashing NETW3005 (Operating Systems) Lecture 08 - Virtual Memory4

Swapping: A recap In the last lecture we introduced the idea of swapping processes in and out of main memory, in synchrony with CPU scheduling. Swapping allows more processes to multitask at any given time. Runtime binding makes swapping easier. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory5

Partially loaded processes Advantages of allowing programs to execute without being fully in memory. –Dynamic loading/linking: sharing of common language library routines, ease of up- grading etc. –It should be possible to increase the number of processes being multitasked. –It will be quicker to swap processes in and out of memory during multitasking. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory6

The Virtual Memory concept The paradigm of Virtual Memory (VM) takes the idea that a process doesn’t need to be fully in memory in order to run to its logical conclusion. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory7

VM techniques Provide ways of automating the loading of processes while they execute. The programmer deals with a logical memory just as in paging scheme. The memory manager is not only in charge of mapping logical addresses to physical addresses, but also of actually loading physical addresses into main memory from the backing store. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory8

Demand paging NETW3005 (Operating Systems) Lecture 08 - Virtual Memory9 page table CPU page0 page1 page2 page3 0 1 v 1 4 v 2 3 v 3 6 v page3 page1 page2 page0 memory You can easily use a paging scheme to implement swapping. You can go further – only load a page when the CPU references it.

Implementing Demand Paging Page table entries typically contain additional information. –Valid/invalid bit: used to indicate whether the page number referred to by a process is inside its allocated number of pages. –Protection bit: e.g. read-write / read only. The valid/invalid bit is often used to specify whether a page has been loaded. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory10

An example of Demand Paging NETW3005 (Operating Systems) Lecture 08 - Virtual Memory11 logical memory A B C D C A A B C D v i v i i i page table physical memory backing store

Note There are now two reasons for the invalid bit. There is duplication of data in the system, e.g. A is represented in two places. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory12

Page Faults Accessing an invalid page in the table results in a trap to the operating system. The operating system determines the cause of the trap: –Invalid memory access? Terminate. –Page not loaded? Page fault. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory13

Dealing with a page fault Find a free frame in main memory. Schedule a disk operation to read the desired page into this frame. Modify the page table appropriately. Restart the instruction. (It’s crucial that the process is restarted in exactly the state that generated the fault). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory14

Performance of Demand Paging On average, how long does it take to access a memory location in a demand paging system? What are the relevant factors? –memory access time (t a ); –page fault time (t f ) –probability of a page fault (p) NETW3005 (Operating Systems) Lecture 08 - Virtual Memory15

Effective access time NETW3005 (Operating Systems) Lecture 08 - Virtual Memory16 (1-p) x t a + p x t f

Acceptable page fault rates Total page fault time (including hardware and software processes) is typically around 25 milliseconds. Memory access time is typically between 10 and 200 nanoseconds. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory17

Exercise What is the effective access time for a machine with a page fault probability of 1%, memory access time (t a ) of 100 nanoseconds, and a page fault (t f ) time of 25 milliseconds? NETW3005 (Operating Systems) Lecture 08 - Virtual Memory18

Answer NETW3005 (Operating Systems) Lecture 08 - Virtual Memory19 = (1-p) x t a + p x t f = (0.99 x (0.01 x 25,000,000) = 250,000 ns Compared to the access time assuming no paging (100 ns), this rate of paging slows the system down by a factor of 2500! Lesson: for efficient paging, faults need to be very rare.

Page replacement algorithms If main memory is full when a page fault is generated, one of the pages currently being held needs to be replaced. This means an extra step in the operating system’s page-servicing routine. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory20

Find a free frame of memory. If there’s a free frame in memory, use it. Otherwise: –Select a frame to swap out. –Save it to the backing store (why?) –Proceed as before. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory21

Page replacement algorithms There are various methods for deciding which page to swap out. These are usually evaluated with respect to a reference string of page requests and a memory consisting of a small number of frames (we will use three). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory22

FIFO page replacement Ok, so how does this work? NETW3005 (Operating Systems) Lecture 08 - Virtual Memory

Advantages and disadvantages Advantages –simple to understand and implement. Disadvantages –maybe the first page to be referenced is referenced often –Note also Belady’s anomaly — increasing the allocation may increase the number of page faults. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory24

Optimal Page Replacement What would this algorithm be? Replace the page that will not be used for the longest amount of time. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory

Advantages / disadvantages Advantages? –Obvious – the algorithm is optimal. Disadvantage? –Similar to SJF scheduling – you can’t predict the future reference string (just as you can’t predict future CPU burst times). NETW3005 (Operating Systems) Lecture 08 - Virtual Memory26

LRU Page Replacement What would this algorithm be? Replace the page that has not been used for the longest period of time. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory

Advantages / disadvantages Advantage –It’s optimal if you look backward in time, rather than forward. Disadvantage –It’s time-consuming to keep a record of last use for each page. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory28

What assumption are we making? That future memory references are going to be resemble past ones. Again, note similarity with SJF. However note the logical independence of CPU burst times and memory reference patterns. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory29

LRU Approximation Hardware (1) How to keep a record of the least- recently used page? –Provide a ‘time-used’ field in the page table. –Keep a queue of page numbers, and move a page to the back of the queue each time it’s referenced. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory30

LRU Approximation Hardware (2) How to keep a record of the least- recently used page? –Associate several reference bits with each page. – Associate one reference bit with each page. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory31

Frame allocation algorithms It makes sense not to allocate a very small number of frames to a process. In fact, for any given machine there is a minimum number of frames that must be allocated to a process — the maximum number of memory locations that can be accessed in a single instruction. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory32

Frame distribution algorithms Equal allocation Proportional allocation Local vs global replacement schemes NETW3005 (Operating Systems) Lecture 08 - Virtual Memory33

Thrashing A process is thrashing if it’s spending more time paging than executing. Thrashing occurs when a process has not been allocated sufficient frames. – A page fault occurs, requiring a page to be replaced. –The replaced page is itself needed shortly thereafter. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory34

Thrashing in more detail 1.There are too many processes sharing the CPU. 2.The processes all start to thrash. 3.The CPU becomes relatively idle. 4.The scheduler detects this, and increases the degree of multiprogramming. 5.Whoops... NETW3005 (Operating Systems) Lecture 08 - Virtual Memory35

The locality model of execution Keep track of which and how many frames a process is currently using. It is possible to identify particular groups of pages which are used together. A locality is defined e.g. by a subroutine that regularly refers to a particular set of variables. Localities can overlap with one another. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory36

The Working Set model We define a parameter ∆ representing the working set window – the most recent ∆ page references. The working set is the set of pages referenced within the working set window. The idea is to ensure that each process is allocated enough frames to store its current working set. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory37

When do you load pages? Pure demand paging. None of a process’ pages are loaded until referenced. Disadvantages of this scheme? –You get loads of page-faults at the start of a process’ execution. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory38

When do you load pages? Prepaging –When a process is suspended, we remember its current working set. –When it is restarted, we bring all the pages in its working set back into memory straight away. –This is only a win if a reasonable proportion of these pages are subsequently referenced. NETW3005 (Operating Systems) Lecture 08 - Virtual Memory39

Next Lecture File System Interface Chapter 10 (Sections 1-5) Chapter 11 (Sections 1-4)