Introduction
The concept of virtual memory in operating systems refers to extending the physical memory (RAM) to the hard drive so that running processes behave as if there is unlimited address space. Paging means dividing the running process into equally sized logical pieces called pages so that only requested pages at the current execution time are only loaded into psychical memory. A page fault happens when a page is requested but it is not yet in physical memory. In this case the page has to be brought from disk into RAM. If there is no enough room for the page then an existing page in memory has to be flushed out back to disk. If the page that need to be removed is unmodified then we can just overwrite it but if it is modified (called dirty) then we need to copy it back to disk. It is always better not to remove an often used page that is when page replacement algorithms come into play. Here is a summary of some well known page replacement algorithms:
Optimal Page Replacement Algorithm
- Replace the page that will be used furthest in the future
- It is hard or impossible to implement
Not Recently Used Page Replacement Algorithm (NRU)
- Classify pages into the following
- Not referenced Not dirty
- Not referenced and dirty
- Referenced Not dirty
- Referenced and dirty
- Periodically clear reference bit for all pages
- Remove a page from the lowest non empty class
- Easy to implement and performance adequate
First In First Out Page Replacement Algorithm (FIFO)
- As the name indicates first page in first out
- It is easy to implement using a linked list
- Bad, forces pages out regardless of usage
Second Chance Page Replacement Algorithm
- It is easy to implement and better version of FIFO
- If the page is not referenced then throw the page out
- If the page is referenced then clear the reference bit and move the page to the tail of the list
- Continue searching for a free page
Clock Page Replacement Algorithm
- Simpler implementation compared to second chance algorithm
- Clock hand points to the next page to replace
- If the page is not referenced then we replace it
- If the page is referenced then we advance the clock hand until a non referenced page is encountered
Least Recently Used Page Replacement Algorithm (LRU)
- Throw a page that has been unused for longest time
- In a linked list implementation put the most recently used pages at the front of the list and the least recently used pages at the rear
- Update the list on every memory reference but that is an expensive operation
- Near optimal performance in theory but rather expensive to implement in practice
Not Frequently Used Page Replacement Algorithm (NFU)
- An approximation of LRU
- At each clock interrupt scan the page table
- If a page is referenced then increment the page reference counter
- On replacement pick the page with the lowest counter value
- Does not support page aging and tend to keep pages with high counter values
Aging Page Replacement Algorithm
- Similar to NFU but page reference counter is reduced over time
- Replace the page with lowest counter value
Working Set Page Replacement Algorithm
- Bring a page into RAM when it is requested (demand paging)
- A process references a small set of pages at any given time (Locality of reference)
- The working set of a process is the set of pages used by the process in a given interval of time
- So the goal of this algorithm is to keep most of the working set in memory in order to reduce the number of page faults.
No comments:
Post a Comment