1 Virtual Memory. Cache memory: provides illusion of very high speed Virtual memory: provides illusion of very large size Main memory: reasonable cost,

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
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 – 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.
Virtual Memory Management
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.
Virtual Memory Chapter 8.
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 Lecture 9: Virtual Memory Operating System I Spring 2007.
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.
Virtual Memory.
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 ©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.
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.
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 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.
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
Virtual Memory.
Virtual Memory Chapter 8.
Virtual Memory CSSE 332 Operating Systems
Chapter 9: Virtual Memory – Part I
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Virtual Memory Chapter 8.
Lecture 10: Virtual Memory
Module 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 9: Virtual-Memory Management
Operating Systems Lecture November 2018.
5: Virtual Memory Background Demand Paging
Chapter 9: Virtual Memory
Chapter 9: Virtual Memory
Chapter 6 Virtual Memory
Lecture 37 Syed Mansoor Sarwar
Module 9: Virtual Memory
Virtual Memory.
Presentation transcript:

1 Virtual Memory

Cache memory: provides illusion of very high speed Virtual memory: provides illusion of very large size Main memory: reasonable cost, but slow & small Memory Hierarchy Summary

Virtual Memory  Program addresses only logical addresses  Hardware maps logical addresses to physical addresses  Only part of a process is loaded into memory  process may be larger than main memory  additional processes allowed in main memory since only part of each process needs to be in physical memory  memory loaded/unloaded as the programs execute  Real Memory – The physical memory occupied by a program (frames)  Virtual memory – The larger memory space perceived by the program (pages) Virtual Memory

Virtual Memory That is Larger Than Physical Memory

Virtual Memory  Principle of Locality – A program tends to reference the same items - even if same item not used, nearby items will often be referenced  Resident Set – Those parts of the program being actively used (remaining parts of program on disk)  Thrashing – Constantly needing to get pages off secondary storage  happens if the O.S. throws out a piece of memory that is about to be used  can happen if the program scans a long array – continuously referencing pages not used recently  O.S. must watch out for this situation! Virtual Memory

 Decisions about virtual memory:  Fetch Policy – when to bring a page in?  When needed or in anticipation of need?  Placement – where to put it?  Replacement – what to unload to make room for a new page?  Resident Set Management – how many pages to keep in memory?  Fixed # of pages or variable?  Reassign pages to other processes?  Cleaning Policy – when to write a page to disk?  Load Control – degree of multiprogramming?

Paging and Virtual Memory  Large logical memory – small real memory  Demand paging allows  size of logical address space not constrained by physical memory  higher utilization of the system  Paging implementation  frame allocation  how many per process?  page replacement  how do we choose a frame to replace?

Demand Paging  Bring a page into memory only when it is needed.  Less I/O needed  Less memory needed  Faster response  More users  Page is needed  reference to it  invalid reference  abort  not-in-memory  bring to memory

Transfer of a Paged Memory to Contiguous Disk Space

Page Table of Demand Paging

Page Fault  If there is ever a reference to a page, first reference will trap to OS  page fault  OS looks at another table to decide:  Invalid reference  abort.  Just not in memory.  Get empty frame.  Swap page into frame.  Reset tables, validation bit = 1.  Restart instruction: Least Recently Used  block move  auto increment/decrement location

Steps in Handling a Page Fault

What happens if there is no free frame?  Page replacement – find some page in memory, but not really in use, swap it out.  algorithm  performance – want an algorithm which will result in minimum number of page faults.  Same page may be brought into memory several times.

Demand Paging  Paged memory combined with swapping  Processes reside in main/secondary memory  Could also be termed as lazy swapping  bring pages into memory only when accessed  What about at context switch time?  could swap out entire process  restore page state as remembered  anticipate which pages are needed

Page Replacement  Demand paging allows us to over-allocate  no free frames – must implement frame replacement  Frame replacement  select a frame (victim)  write the victim frame to disk  read in new frame  update page tables  restart process

Page Replacement  If no frames are free, two page transfers  doubles page fault service time  Reduce overhead using dirty bit  dirty bit is set whenever a page is modified  if dirty, write page, else just throw it out

Paging Implementation (continued … )  Must be able to restart a process at any time  instruction fetch  operand fetch  operand store (any memory reference)  Consider simple instruction  Add C,A,B (C = A + B)  All operands on different pages  Instruction not in memory  4 possible page faults )-: slooooow :-(

Performance of Demand Paging  Page Fault Rate 0  p  1.0  if p = 0 no page faults  if p = 1, every reference is a fault  Effective Access Time (EAT) EAT = (1 – p) x memory access + p (page fault overhead + [swap page out ] + swap page in + restart overhead)

Demand Paging Example  Memory access time = 1 microsecond  50% of the time the page that is being replaced has been modified and therefore needs to be swapped out.  Swap Page Time = 10 msec = 10,000 microsecond EAT = (1 – p) x 1 + p (15000) = p (in microsecond)

Performance Example  Paging Time …  Disk latency8 milliseconds  Disk seek15 milliseconds  Disk transfer time1 millisecond  Total paging time~25 milliseconds  Could be longer due to  device queueing time  other paging overhead

Paging Performance (continued … )  Effective access time: EAT = (1 - p)  ma + p  pft where: p is probability of page fault ma is memory access time pft is page fault time

Paging Performance (continued … )  Effective access time with 100 ns memory access and 25 ms page fault time: EAT = (1 - p)  ma + p  pft = (1 - p)  p  25,000,000 = ,999,900  p  What is the EAT if p = (1 out of 1000)?  ,990  = 25 microseconds  250 times slowdown!  How do we get less than 10% slowdown?  ,990  p  1.10  100 ns = 110 ns  Less than 1 out of 2,500,000 accesses fault

Paging Improvements  Paging needs to be as fast as possible  Disk access time is faster if:  use larger blocks  no file table lookup or other indirect lookup  binary boundaries  Most systems have a separate swap space  Copy entire file image into swap at load time  Demand page  Or …  Demand pages initially from the file system  Write pages to swap as they are needed

Fetch Policy  Demand paging means that a process starts slowly.  produces a flurry of page faults early, then settles down  Locality means a smaller number of pages per process are needed.  desired set of pages should be in memory - working set  Prepaging means bringing in pages that are likely to be used in the near future.  try to take advantage of disk characteristics  generally more efficient to load several consecutive sectors/pages than individual sectors due to seek, rotational latency  hard to correctly guess which pages will be referenced  easier to guess at program startup  may load unnecessary pages

Placement Policies  Where to put the page  trivial in a paging system – can be placed anywhere  Best-fit, First-Fit, or Next-Fit can be used with segmentation  is a concern with distributed systems

Replacement Policies  Replacement Policy  which page to replace when a new page needs to be loaded  tends to combine several things:  how many page frames are allocated  replace only a page in the current process or from all processes? (Resident Set Management)  from pages being considered, selecting one page to be replaced  Frame Locking  require a page to stay in memory  O.S. Kernel and Interrupt Handlers  real-Time processes  other key data structures  implemented by bit in data structures