Virtual Memory - PowerPoint PPT Presentation

1 / 28
About This Presentation
Title:

Virtual Memory

Description:

Use 'dirty' bit to keep track if a page was modified. Servicing the PageFault ... Reference bit set, but is not dirty (1,0) (Recently used, but clean) ... – PowerPoint PPT presentation

Number of Views:76
Avg rating:3.0/5.0
Slides: 29
Provided by: scie222
Category:
Tags: dirty | memory | virtual

less

Transcript and Presenter's Notes

Title: Virtual Memory


1
(No Transcript)
2
Virtual Memory
  • A technique that allows the execution of
    processes that may not be completely in memory.
  • Virtual Memory is the separation of user memory
    from physical memory.

3
Goals
  • Eliminate physical memory size as a constraint on
    a program
  • Since each program would uses less physical
    memory, more programs can be run at the same time
  • Less I/O is needed to swap the program into
    memory, it will run faster

4
Benefits of VM
  • Physical memory no longer constrains the size of
    a process (2 GB)
  • Each process uses less memory, so more processes
    may run at the same time
  • Less I/O is needed to swap processes, so each
    process runs faster

5
Demand Paging
  • Similar to whole process swapping
  • Swap pages (pieces of the process) instead of the
    entire process
  • Only swap a page in when it is needed (lazy
    swapping)
  • Called paging rather than swapping

6
Tracking Pages
  • Requires hardware support
  • Valid/Invalid bit
  • If valid is set, address is legal and in memory
  • If invalid, either address is illegal or valid
    but paged out

7
Handling a PageFault
  • Check Process Control Block
  • Valid or invalid address?
  • If invalid, terminate process
  • If valid but not in memory
  • Find a free frame (empty memory)
  • Schedule a disk read into the empty frame
  • When read in, modify the pagetable
  • Restart the instruction that was interrupted with
    the page fault

8
Buzzword Compliance
  • Pure Demand Paging
  • Start executing a process with no pages in
    memory. It will fault on each page it needs.
  • Locality of Reference
  • When executing, the process tends to use code and
    variables that are close to each other

9
Page Replacement
  • When a process needs a frame and no free frames
    are available, the OS can
  • Kill a process (and free its frames)
  • Suspend a process (and free its frames)
  • Find an unused frame and free it by writing its
    contents out to disk

10
Servicing the PageFault
  • Find the needed page on disk
  • Find a free frame
  • If there is a free frame, use it
  • Else, find a victim using some algorithm
  • Write the victim to disk (update tables)
  • Read in the needed page into the newly freed page
  • Restart the user process

11
Servicing the PageFault
  • Note that 2 disk operations are needed
  • Writing out the victim
  • Reading in the needed page
  • If it was not modified, do not write out
  • Use dirty bit to keep track if a page was
    modified

12
Page Replacement Algorithms
  • First-In-First-Out (FIFO)
  • Simple to implement
  • Replace oldest frame first
  • Can use linked list to avoid needing timers
  • Performance varies
  • Suffers from Beladys anomaly
  • (faults increase as the number of allocated
    frames increases)

13
Page Replacement Algorithms
  • Optimal (OPT or MIN)
  • Guaranteed lowest page fault rate
  • Replace the frame that will not be used for the
    longest time
  • Requires knowledge of the future
  • Cannot be implemented
  • Used a yardstick to compare with other
    algorithms

14
Page Replacement Algorithms
  • Least recently used (LRU)
  • Approximation of OPT
  • Replace the frame that was not be used for the
    longest time
  • Assumes past trends are valid for the future
  • Can be implemented, but requires lots of hardware
    assistance
  • Counters
  • Stack

15
Page Replacement Algorithms
  • LRU approximations
  • Require reference bit
  • Set bit each time the page is used
  • Additional-Reference-Bits Algorithm
  • Keep track of last 8 references (one byte per
    page)
  • Right shift one bit before at each time slice
  • The 8 bits can be read as an integer
  • Free the page with the lowest integer value
  • (11000110 is higher than 01111011)

16
Page Replacement Algorithms
  • LRU approximations
  • Second-Chance (Clock) Algorithm
  • Keep track of last reference (one bit per page)
  • Pages are kept in a circular queue
  • When a frame is needed, check a frame
  • If its reference bit is not set, use this frame
  • If its reference bit is set, change it to zero
    and move to the next frame in the queue
  • At worst (all reference bits are set), it will go
    completely around the queue setting all bits to 0
    and choose the frame where it started

17
Page Replacement Algorithms
  • LRU approximations
  • Enhanced-Second-Chance Algorithm
  • Similar to Second-Chance Algorithm
  • Keep track of last reference and the modify
    (dirty) bit
  • Choose frames in the following order
  • Both reference bit and dirty bit are clear (0,0)
  • (Best page to replace)
  • Reference bit not set, but is dirty (0,1)
  • (Not as good, requires write out)
  • Reference bit set, but is not dirty (1,0)
  • (Recently used, but clean)
  • Reference bit set, but is dirty (1,1)
  • (Recently used and would require write out)

18
Other Algorithms
  • Counting
  • Least Frequently Used (LFU)
  • Most Frequently Used (MFU)
  • Page Buffering Algorithm

19
Allocating Frames
  • Cannot allocate more frames than exist in
    physical memory
  • Can allocate too few for a process which causes
    increased fault rates (and slows execution)

20
Allocation Algorithms
  • Equal Allocation
  • Each n process gets 1/n of frames
  • Some process may not need 1/n frames and they go
    unused
  • Proportional Allocation
  • Each process gets a set of frames in relation to
    its virtual size
  • For both, as more processes run, each process
    gets fewer frames

21
Global versus Local Allocation
  • Global Allocation
  • Take a frame from any process
  • Can increase overall fault rate
  • A process cannot control its own fault rate
  • Local Allocation
  • Take a frame only from the same process
  • Each process controls its own fault rate
  • May keep unused frames unnecessarily
  • Global provides higher system throughput

22
Thrashing
  • When a process does not have enough frames to
    avoid continuously faulting, the process spends
    more time paging than executing
  • This is called thrashing

23
Causes of Thrashing
  • Too many processes
  • Each process takes frames from other processes,
    yet none can execute

24
Working Set
  • Based on the assumption of locality
  • It is a moving window of some number, Delta, of
    pages used
  • Requires fixed interval timer interrupt
  • Can use FIFO (linked list) to track
  • Need to find right size

25
Buzzword Compliance
  • Inverted Page Table

26
Locality in Practice
  • Reading arrays in C versus Fortran
  • C is row major
  • Fortran is column major
  • Convert code from one to the other without
    changing nested loops will cause horrible
    performance

27
I/O Interlock
  • What is a process is writing a page out to disk
    when it is swapped? What if the page to be
    written is swapped out?
  • Need to lock the page until the disk I/O is done
    or need to copy the data to the kernel first.

28
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com