Docsity

Virtual Memory - Operating Systems - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Virtual Memory - Operating Systems - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Virtual Memory

Chapter 9

Background

  • 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
  • Virtual memory can be implemented via:
  • Demand paging
  • Demand segmentation

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
  • Lazy swapper – never swaps a page into memory

unless page will be needed

  • Swapper that deals with pages is a pager

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
  • During address translation, if valid–invalid bit in page table entry is i ⇒ page fault

v v v v i i i

….

Frame # valid-invalid bit

page table

Page Fault

  • Access to a page marked invalid causes a page-fault
    • An interrupt occurs (page fault). Control goes to the O.S.

1. Operating system looks at another table to decide:

  • Invalid reference ⇒ abort
  • Just not in memory

2. Get empty frame (e.g. from free-frame list).

3. Swap page into frame

4. Reset tables

5. Set validation bit = v

6. Restart the instruction that caused the page fault

Steps in Handling a Page Fault

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, = 200 + p x 7,999,
  • If one access out of 1,000 causes a page fault, then EAT = 8.2 microseconds. This is a slowdown by a factor of 40!!
  • Want performance degradation < 10% What p would lead to a 10% slowdown in performance?

Process Creation

• Virtual memory allows other benefits during

process creation:

- Copy-on-Write

- Memory-Mapped Files

Memory-Mapped Files

  • A memory-mapped file allows a part of the virtual address space to be associated with a file.
  • In memory-mapping of a file, a disk block is mapped to a page (or pages) 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 file access by treating file I/O through memory rather than read() write() system calls.
  • Writes to a file may not necessarily cause an immediate write to the disk.
  • Multiple processes may map the same file into their virtual memory, allowing data to be shared.

Memory Mapped Files

Need For Page Replacement

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

  1. Bring the desired page into the (newly) free frame;

update the page and frame tables

  1. Restart the process

Page Replacement Algorithms

  • 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

  • Want lowest page-fault rate
  • Evaluate algorithm by running it on a particular string of

memory references (reference string) and computing the

number of page faults on that string

Graph of Page Faults Versus The Number of

Frames