Memory management virtual memory page replacement algorithms
This presentation is the property of its rightful owner.
Sponsored Links
1 / 29

Memory Management Virtual Memory Page replacement algorithms PowerPoint PPT Presentation


  • 97 Views
  • Uploaded on
  • Presentation posted in: General

Memory Management Virtual Memory Page replacement algorithms. Chapter 4 Sec. 4.4. Structure of a page table entry. Issues with page tables. They can be very large It takes more time to access a memory location Virtual page first has to be mapped to its corresponding physical frame

Download Presentation

Memory Management Virtual Memory Page replacement algorithms

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Memory management virtual memory page replacement algorithms

Memory ManagementVirtual MemoryPage replacement algorithms

Chapter 4

Sec. 4.4


Structure of a page table entry

Structure of a page table entry


Issues with page tables

Issues with page tables

  • They can be very large

  • It takes more time to access a memory location

    • Virtual page first has to be mapped to its corresponding physical frame

  • The spectrum of solutions

    • High speed registers to implement the table

    • Put entire page table in main memory


Page swapping

Page swapping

  • What to do if the memory reference is to a page that is not in main memory?

    • This is called a page fault

    • “Swap” a page out of main memory and “swap” the needed page in its place

  • The decision about which page to swap out is made by a page replacement algorithm


When a page fault occurs

When a page fault occurs…

  • Page fault forces choice about which page should be overwritten

  • Modified page may first have to be saved to the hard drive

    • But if is unmodified, it can just be overwritten

  • Best not to choose “popular” page

    • It will probably need to be brought back in soon


Page replacement algorithms

Page replacement algorithms

  • Choosing the page that gets swapped out

    • Optimal

    • NRU

    • FIFO

    • Second Chance

    • Clock

    • LRU

    • NFU

    • Working Set

    • WSClock


Optimal page replacement algorithm

Optimal Page Replacement Algorithm

  • Replace page that will be needed at the farthest point in future

    • Optimal but unrealizable

  • Can estimate by logging page use on previous runs of a given process

    • Impractical


Optimal algorithm example using 3 page frames

Optimal algorithm exampleUsing 3 page frames

7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1

7 7 7 2 2 2 2 2 7

0 0 0 0 40 0 0

1 1 3 3 3 1 1

Total number of page faults is ___ . This algorithm (although the best) is implausible to implement since it requires future knowledge. It is used mainly for comparison studies.


Not recently used nru

Not Recently Used (NRU)

  • Each page has reference and modified bits

    • bits are set when page is referenced, modified

  • Pages are classified

    • not referenced, not modified: 0 0

    • not referenced, modified:0 1 how can it be?

    • referenced, not modified: 1 0

    • referenced, modified: 1 1

  • Removes page at random from the lowest numbered non-empty class


Memory management virtual memory page replacement algorithms

FIFO

  • Maintain a linked list of all pages

    • in order in which they came into memory

  • The page at the head of the list swapped out

  • Disadvantage?

  • Advantage?


Fifo example using 3 frames

FIFO exampleUsing 3 frames

7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1

7 7 7 2 2 2 4 4 4 0 0 0 7 7 7

0 0 0 3 3 3 2 2 2 1 1 1 0 0

1 1 1 0 0 0 3 3 3 2 2 2 1

Total of ___ faults.

Suppose we had 4 frames instead of 3, would there be fewer page faults?


Another fifo example

Another FIFO example

Consider the reference string

1, 2, 3, 4, 1, 2, 5, 1, 2, 3, 4, 5

With three frames there are faults

With four frames there are faults.

This is an example of Belady's Anomaly.


Belady s anomaly

Belady's Anomaly?!?

FIFO with 3 page frames

P's show which page references show page faults

FIFO with 4 page frames


Second chance fifo modification

Second ChanceFIFO modification

  • A FIFO linked list is maintained, as before.

    • The page at the head of the list is chosen to be swapped out unless its R bit is 0

      • In that case, it goes to the end of the list

      • And the next process on the list is examined for swapping…


Clock variation of second chance

ClockVariation of second chance


Least recently used lru

Least Recently Used (LRU)

  • Rationale is that pages used recently will be used again soon

    • replace pages that have been unused for longest time

  • If implemented with a linked list of pages

    • the list must be updated with every memory reference

  • Other techniques require hardware support

    • Counter is maintained

      • When a page is referenced, it receives the counter’s value

    • LRU matrix


Lru matrix

LRU matrix

LRU using a matrix – pages referenced in order0,1,2,3,2,1,0,3,2,3


Lru example

LRU example

7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1, 2, 0, 1, 7, 0, 1

7 7 7 2 2 4 4 4 0 1 1 1

0 0 0 0 0 0 3 3 3 0 0

1 1 3 3 2 2 2 2 2 7

Total number of page faults is _____.

This is often the best page-replacement algorithm that we can use.


Additional reference bits lru enhancement

Additional reference bits (LRU enhancement )

  • Instead of just clearing the bits every so often, we can keep extra information by having a reference byte

  • At regular intervals (100 ms, e.g.) a clock interrupt occurs

    • OS shifts the reference bit into the high order position of the reference byte, and shifts all other bits down to the right


Additional reference bits example

Additional reference bits example

  • For example, the reference byte is 01101101 and the reference bit is 1 when the timer expires.

  • The reference byte now becomes 10110110, and the reference bit is set back to 0

  • Interpreting these bytes as unsigned integers, the least recently referenced page is the one with the smallest reference byte.


Not frequently used nfu

Not frequently used (NFU)

  • Counter in each page table entry is initialized to 0

  • At each clock interrupt, the value of the reference bit is added to the counter, and then set back to 0.

  • At a page fault, the page with the smallest counter is swapped out.

  • Not very useful, but a variation of it accounts for the aging of pages.

    • This is a simulation of LRU

    • See pp. 220-221


Working set locality model

Working Set / Locality Model

  • The working-set strategy starts by looking at how many frames a process is actually using.

  • This approach defines the locality model of process execution

    • As a process executes, it moves from one locality to another.

      • A locality is a set of pages actively used together

    • A program is composed of several (possibly overlapping) localities


What is locality

What is locality?

  • For example, when a procedure is called, it defines a new locality. When the procedure is exited, the locality changes

  • If we allocate enough frames to accommodate the process’ current locality

    • it will fault for the pages in its current locality until they are all in memory.

    • it will not fault again until it changes its locality.


Working set model

Working-Set Model

  • This model uses a parameter, kto define the working-set window

  • The idea is to examine the most recent kpage references. The set of pages in the most recent kpage references is the working set

    • If a page is in active use, it will be in the working set

    • If it is no longer being used, it will drop from the working set kunits after its last reference


Example

Example

A page reference string, withk= 10

2 6 1 5 7 7 7 7 5 1 6 2 3 4 1 2 3 4 4 4 3 4 3 4 4 4

t1

t2

At time t1 the working set is {1,2,5,6,7}

At time t2 the working set is {3, 4}

The accuracy of the working set depends upon the selection of k.

if it is too small, it may not encompass the working set

if it is too large, it may overlap several localities


Implementation

Implementation

  • The OS monitors the working-set of each process and allocates to that working-set enough frames to provide it with its working-set size

    • If there are any extra frames, another process can be started.

  • If the sum of the working-sets increases, exceeding the total number of frames, a process is suspended. That process’ pages are written out and its frames reallocated.


Working set

Working Set


Wsclock

WSClock


Summary

Summary


  • Login