Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department.

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
Chapter 9 Virtual Memory Bernard Chen 2007 Spring.
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.
9.1 Silberschatz, Galvin and Gagne ©2009 Operating System Concepts with Java – 8 th Edition Chapter 9: 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  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.
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.
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.
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
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.
Chapter 9: Virtual Memory. 9.2 Silberschatz, Galvin and Gagne ©2005 Operating System Concepts – 7 th Edition, Feb 22, 2005 Background Virtual memory –
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.
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.
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.
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.
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.
Virtual Memory The address used by a programmer will be called a virtual address or logical address. An address in main memory is called a physical address.
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.
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
Virtual Memory.
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
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)
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Virtual Memory.
Chapter 8 & 9 Main Memory and Virtual Memory
Module IV Memory Organization.
Presentation transcript:

Operating Systems (CS 340 D) Princess Nora University Faculty of Computer & Information Systems Computer science Department

(Chapter-9) Virtual Memory

Chapter 9: Virtual Memory 1.Background 2.Virtual Memory Implementation 3

OBJECTIVES :  To describe the benefits of a virtual memory system  To explain the concepts of demand paging  To explain the page-replacement algorithms 4

Background 5

In chapter of memory management,  various memory-management strategies used in computer systems were discussed and all of these strategies have the same goal: to keep many processes in memory simultaneously to allow multiprogramming.  They tend to require that an entire process be in memory before it can execute. Virtual memory is a technique that allows the execution of processes that are not completely in memory. Background 6

Advantages of Virtual Memory technique: 1.Programs can be larger than physical memory. 2.It abstracts main memory into an extremely large, uniform array of storage. 3.It separate logical memory as viewed by the user from physical memory. 4.It increases CPU utilization and throughput because more programs could be run at the same time as a result of making process takes less physical memory 5. Less I/O would be needed to load user programs into memory, so each process would run faster. 6.This technique frees programmers from the concerns of memory-storage limitations. 7.It allows processes to share files easily and to implement shared memory. In addition, it provides an efficient mechanism for process creation. Background (Cont.) 7

Virtual Memory That is Larger Than Physical Memory 8 Virtual memory supports sharing

 Disadvantages of virtual memory technique:  It is not easy to implement  It may substantially decrease performance if it is used carelessly Background 9

Virtual Memory Implementation Demand Paging 10

Virtual memory can be implemented via : 1. Demand paging 2. Demand segmentation 11

1-Demand Paging Consider how an executable program might be loaded from disk into memory.  Option(1): is to load the entire program in physical memory at program execution time.  Problem  we may not initially need the entire program in memory. Ex: Suppose a program starts with a list of available options from which the user is to select. Loading the entire program into memory results in loading the executable code for all options, regardless of whether an option is ultimately selected by the user or not.  Option(2): load pages only as they are needed during program execution. This technique is known as demand paging and is commonly used in virtual memory systems. 12

1-Demand Paging  A demand-paging system is similar to a paging system with swapping But rather than swapping the entire process into memory, we use a lazy swapper.  lazy swapper never swaps a page into memory unless that page will be needed.  Since we are now viewing a process as a sequence of pages, rather than as one large contiguous address space, use of the term swapper is technically incorrect.  A swapper manipulates entire processes, whereas a pager is concerned with the individual pages of a process.  We thus use pager, rather than swapper, in connection with demand paging. 13

Transfer of a Paged Memory to Contiguous Disk Space 14

n With this scheme, we need some form of hardware support to distinguish between 1. the pages that are in memory 2. the pages that are on the disk. n The valid–invalid bit scheme can be used for this purpose.  “valid,” :  the associated page is both legal and in memory.  “invalid,”  the page either is not valid (/illegal)(that is, not in the logical address space of the process) or is valid but is currently on the disk. 1-Demand Paging (cont..) 15

Valid-Invalid Bit  With each page table entry a valid– invalid bit is associated (v  in-memory, i  not-in-memory)  Initially valid–invalid bit is set to (i) on all entries page table 1-Demand Paging(cont..) 16

Page Table When Some Pages Are Not in Main Memory 17

Page Fault what happens if the process tries to access a page that was not brought into memory?  Access to a page marked invalid causes a page fault.  The paging hardware, in translating the address through the page table, will notice that the invalid bit is set, causing a trap to the operating system. How OS handle page fault ?? 1. Operating system looks at another table to decide (is the reference is legal or not??):  Illegal reference  abort  Legal but not in memory  bring this page into RAM 2. Get empty frame 3. Swap page into frame 4. Reset tables & Set validation bit = v 5. Restart the instruction that caused the page fault 18

Steps in Handling a Page Fault 19

Performance of Demand Paging n Demand paging can significantly affect the performance of a computer system. why ? if no page faults, the effective access time is equal to the memory access time. If, a page fault occurs, we must first read the relevant page from disk and then access the desired word. n Let p be the probability of a page fault (0 ≤ p ≤ 1). >>> expect p to be close to only a few page faults. effective access time =[ (1 − p) × ma] + [p × page fault time]. 20

Demand Paging Example  Memory access time = 200 nanoseconds  Average page-fault service time = 8 milliseconds  EAT = [(1 – p) x 200] + [ p (8 milliseconds)] = [(1 – p) x 200] + [p x 8,000,000] = 200 +[ p x 7,999,800]  If one access out of 1,000 causes a page fault (p= 1/1000), then EAT = 8.2 microseconds>>This is a slowdown by a factor of 40 !! Slowdown factor = memory access time (without page fault)/ EAT 21

Page Replacement Algorithms 22

Page Replacement  If we increase our degree of multiprogramming, we are over- allocating memory.  Ex: If we run six processes, each of which is ten pages in size but actually uses only five pages, we have higher CPU utilization and throughput, with ten frames to spare.  It is possible, however, that each of these processes, for a particular data set, may suddenly try to use all ten of its pages, resulting in a need for sixty frames when only forty are available.  Further, consider that system memory is not used only for holding program pages. Buffers for I/O also consume a considerable amount of memory. This use can increase the strain on memory- placement algorithms. 23

Need For Page Replacement 24

Basic Page Replacement 1. Find the location of the desired page on disk 2. 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 3. Bring the desired page into the (newly) free frame; update the page and frame tables 4. Restart the process 25

Page Replacement 26

27 Page Replacement Algorithms 1. FIFO Page Replacement 2. Optimal Page Replacement 3. Least Recently Used (LRU) Algorithm

FIFO Page Replacement 28

n The simplest page-replacement algorithm is a first-in, first- out (FIFO) n FIFO  each page has memory load start time  or create FIFO queue to hold all pages in memory n When a page must be replaced, the oldest page is chosen. FIFO Page Replacement algorithm 29

FIFO Page Replacement 30

Optimal Page Replacement 31

Optimal Algorithm  Replace page that will not be used for longest period of time  4 frames example 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5  How do you know this?  Used for measuring how well your algorithm performs

Optimal Page Replacement 33

Least Recently Used (LRU) Page Replacement 34

Least Recently Used (LRU) Algorithm  Reference string: 1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5  Counter implementation o Every page entry has a counter; every time page is referenced through this entry, copy the clock into the counter o When a page needs to be changed, look at the counters to determine which are to change

LRU Page Replacement 36

LRU Algorithm (Cont.)  Stack implementation – keep a stack of page numbers in a double link form:  Page referenced:  move it to the top  requires 6 pointers to be changed  No search for replacement 37

Use Of A Stack to Record The Most Recent Page References 38

Thank you End of Chapter 9 39