1 / 22

Virtual Memory

Virtual Memory. Virtual Memory is created to solve difficult memory management problems Data fragmentation in physical memory: Reuses blocks of memory that would otherwise be unused when programs free up data.

Download Presentation

Virtual Memory

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Virtual Memory • Virtual Memory is created to solve difficult memory management problems • Data fragmentation in physical memory: Reuses blocks of memory that would otherwise be unused when programs free up data. • Physical memory size constraints are also solved by using alternate forms of data storage to act like memory. • Implemented via Paging or Segmentation • Problem: Thrashing reduces preformance

  2. Virtual MemoryOverview • Techniques used to give an application program logical access to contiguous working memory • In reality the data is fragmented in primary and secondary memory.

  3. Virtual MemoryMemory Fragmentation • Not just using disk space to extend the physical memory. • Uses real physical memory more efficiently. • Tricks programs into thinking they are using large blocks of contiguous addresses. • Reuses fragments in memory.

  4. Virtual Memory: A History 1950s: Primary memory Magnetic Core Memory (non-volatile)‏

  5. Virtual Memory: A History 1950s: Secondary memory Drum Memory (non-volatile)‏ (BSD Unix: /dev/drum is default name for swap)‏

  6. Virtual MemoryOverlays • Before virtual memory, programs that were too big for the size of physical memory used Overlays • Overlays still popular in embedded systems that require cheap hardware • Overlays require the programmer to manage memory for each program.

  7. Virtual MemoryOverlays • Program manually divided into self-contained code blocks called Overlays • Size of Overlay limited by memory constraints (different for different systems)‏ • Programmer had to use specific programming languages or assembly language to have control over the size of the program and the size of the overlay.

  8. Virtual MemoryA history • Virtual memory was developed in approximately 1959–1962, at the University of Manchester for the Atlas Computer, completed in 1962. • In 1961, Burroughs released the B5000, the first commercial computer with virtual memory. It used segmentation rather than paging. • Virtual Memory was controversial and required many theories, models, and experiments before it was adopted. "the machine that everyone loves, and nobody buys" - Brian Randell

  9. Virtual MemoryA history • Dynamic address translation required a specialized, expensive, and hard to build hardware • Worries that new system-wide algorithms of utilizing secondary storage would be far less effective than application-specific ones. • In 1969 an IBM research team led by David Sayre showed that the virtual memory overlay system consistently worked better than the best manually controlled systems.

  10. Virtual MemoryPages • Virtual memory address space is divided into pages. • A page is a block of contiguous virtual memory addresses that are at least 4096 bytes in size. • Pages are managed by Page Tables. • Page Tables are kept in memory and translate virtual addresses into physical addresses for use by the hardware. • A Page Directory manages Page Tables. • There is one page directory per operating system.

  11. Visualization of Paging System in Windows NT (32 bit)‏ Page Directory Entry Offset (Per Process)‏ Page Table Entry Offset (Table + Frame)‏ Memory byte offset (4096 bytes in frame)‏

  12. Virtual MemoryPaging • “Swapping” is the act of swapping data from physical memory into the virtual memory portion of the hard drive. • “Paging” is the act of reading data from the hard drive (not the virtual memory portion) and writing data permanently back to the hard drive. • Some Operating Systems use “Paging” to describe both (Windows and its “pagefile” vs Unix and its “swap”)‏

  13. Virtual MemoryPage Fault • A Page Fault occurs when a program attempts to access a page that is not current in main memory. • The operating system takes over and does the following: • 1. Determines the location of the data in secondary storage. • 2. Creates an empty page frame in main memory. • 3. Loads the data into the empty page frame. • 4. Updates the Page Table to show the new data. • 5. Return control to the program, retrying the last instruction which caused the page fault.

  14. Virtual MemoryPage Fault • If main memory is full in step 2: Swap out page in memory using an algorithm (most commonly used is discarding based on Least Recently Used)‏ • A Page is “Dirty” if it has been modified since it was read from secondary storage. • If Page is “Dirty”, the OS writes the changes back to secondary storage. Else, the OS just discards the page. • When Page Fault swapping occurs, OS attempts to predict which pages will be used later and load those at the same time.

  15. Virtual MemoryPaging Strategies • Demand Paging: No pages are loaded into RAM unless specifically requested by the program. Program starts with NO pages loaded into RAM. Pages of program of the program that are not run will never be loaded.

  16. Virtual MemoryPaging Strategies • Loader Paging: Attempts to predict which parts of the program will be loaded. If possible, every page of the program will be loaded into memory at the start of execution.

  17. Virtual MemoryPaging Strategies • Anticipatory Paging: Uses the locality of reference to pre-load pages from the program that are most likely to be executed. The goal is to minimize the number of page faults.

  18. Virtual MemoryPaging Strategies • Swap Prefetch: A type of anticipatory paging which specifically pre-loads pages • Pre-loads pages from program that caused last pagefault. • Pre-loads pages that have been swapped out back into memory when a large program releases it's memory in anticipation of the user needing to use the other programs instead.

  19. Virtual MemoryPaging Strategies • Pre-cleaning: Writes “Dirty” pages back into secondary storage periodically as a syncing mechanism, before page needs to be swapped out. • Makes starting a new program much faster as pages that were “Dirty” and would have to be written back to secondary storage are now clean and are just discarded.

  20. Virtual MemoryPaging Replacement Algorithms • Theoretical Optimal Paging Algorithm • First In, First Out • Second Chance (Special case of FIFO)‏ • Clock (Similar to Second Chance)‏ • Least Recently Used • Not Frequently Used • Aging (Combines LRU with NFU)‏ • Random

  21. Virtual MemoryThrashing • Thrashing is when the Operating System spends more and more time swapping pages to and from virtual memory on the hard drive than running the program • Occurs when the sum of localities from running processes cannot all fit into main memory. When a computer is using more and more resources for a decreasing amount of work done, it is said to be thrashing.

  22. Virtual MemoryThrashing • Solutions for Thrashing: • Increase size of main memory • Reduce number of concurrent processes running • Reduce the size of concurrent processes running

More Related