page replacement

1.Optimal Algorithm 最佳置换算法

2.The NRU (Not Recently Used) Page Replacement Algorithm 最近末使用

3.The First-In, First-Out (FIFO) Page Replacement Algorithm 先进先出置换算法

4.Least Recently Used (LRU) 最近最少使用

5.The Second Chance Page Replacement Algorithm 二次机会置换算法

6.The Clock Page Replacement Algorithm 时钟页面置换算法

 The optimal algorithm replaces the page referenced last among the current
pages. Unfortunately, there is no way to determine which page will be last, so in
practice this algorithm cannot be used. It is useful as a benchmark against which
other algorithms can be measured, however.


The NRU algorithm divides pages into four classes depending on the state of
the R and M bits. A random page from the lowest numbered class is chosen. This
algorithm is easy to implement, but it is very crude. Better ones exist.


FIFO keeps track of the order pages were loaded into memory by keeping
them in a linked list. Removing the oldest page then becomes trivial, but that
page might still be in use, so FIFO is a bad choice.


Second chance is a modification to FIFO that checks if a page is in use before
removing it. If it is, the page is spared. This modification greatly improves the
performance. Clock is simply a different implementation of second chance. It
has the same performance properties, but takes a little less time to execute the
algorithm.


LRU is an excellent algorithm, but it cannot be implemented without special
hardware. If this hardware is not available, it cannot be used. NFU is a crude
attempt to approximate LRU. It is not very good. However, aging is a much
better approximation to LRU and can be implemented efficiently. It is a good
choice.


The last two algorithms use the working set. The working set algorithm is
reasonable performance, but it is somewhat expensive to implement. WSClock is
a variant that not only gives good performance but is also efficient to implement.
All in all, the two best algorithms are aging and WSClock. They are based on
LRU and the working set, respectively. Both give good paging performance and
can be implemented efficiently. A few other algorithms exist, but these two are
probably the most important in practice.

 

1.Optimal Algorithm 最佳置换算法

  • ``replace the page that will not be used for the longest time''

 

  • lowest page-fault rate of all algorithms

 

  • requires advanced knowledge of page reference string

 

  • useful for comparison studies

The best possible page replacement algorithm is easy to describe but impossible
to implement. It goes like this. At the moment that a page fault occurs, some
set of pages is in memory. One of these pages will be referenced on the very next
instruction (the page containing that instruction). Other pages may not be referenced
until 10, 100, or perhaps 1000 instructions later. Each page can be labeled
with the number of instructions that will be executed before that page is first
referenced.
The optimal page algorithm simply says that the page with the highest label
should be removed. If one page will not be used for 8 million instructions and
another page will not be used for 6 million instructions, removing the former
pushes the page fault that will fetch it back as far into the future as possible.
Computers, like people, try to put off unpleasant events for as long as they can.
The only problem with this algorithm is that it is unrealizable.

 

2.The NRU (Not Recently Used) Page Replacement Algorithm 最近末使用

In order to allow the operating system to collect useful statistics about which
pages are being used and which ones are not, most computers with virtual memory
have two status bits associated with each page. R is set whenever the page is
referenced (read or written). M is set when the page is written to (i.e., modified).
The bits are contained in each page table entry, as shown in Fig. 4-0. It is important
to realize that these bits must be updated on every memory reference, so it is
essential that they be set by the hardware. Once a bit has been set to 1, it stays 1
until the operating system resets it to 0 in software.

Class 0: not referenced, not modified.
Class 1: not referenced, modified.
Class 2: referenced, not modified.
Class 3: referenced, modified.

The NRU (Not Recently Used) algorithm removes a page at random from the
lowest numbered nonempty class. Implicit in this algorithm is that it is better to
remove a modified page that has not been referenced in at least one clock tick
(typically 20 msec) than a clean page that is in heavy use. The main attraction of
NRU is that it is easy to understand, moderately efficient to implement, and gives
a performance that, while certainly not optimal, may be adequate.

 

 

3.The First-In, First-Out (FIFO) Page Replacement Algorithm 先进先出置换算法

replace the oldest page

The operating system maintains a list of all pages currently in memory, with the page at the head of the list the oldest one and the page at the tail the most recent arrival. On a page
fault, the page at the head is removed and the new page added to the tail of the list. When applied to stores, FIFO might remove mustache wax, but it might also remove flour, salt, or butter. When applied to computers the same problem arises. For this reason, FIFO in its pure form is rarely used.

<1> 先进先出调度算法

  先进先出调度算法根据页面进入内存的时间先后选择淘汰页面,先进入内存的页面先淘汰,后进入内存的后淘汰。本算法实现时需要将页面按进入内存的时间先后组成一个队列,每次调度队首页面予以淘汰。

 

4.Least Recently Used (LRU) 最近最少使用

  • ``replace the page that has not been used for the longest time''

 

  • requires a logical clock time for each page (LRU_TIME)

 

  • or a stack of recent page references (LRU_STACK)

 

  • or a list of all references (LRU_REF)

 

  • same as OPT but on reverse of page reference string

 

  • optimal algorithm looking backward in time

A good approximation to the optimal algorithm is based on the observation
that pages that have been heavily used in the last few instructions will probably be
heavily used again in the next few. Conversely, pages that have not been used for
ages will probably remain unused for a long time. This idea suggests a realizable
algorithm: when a page fault occurs, throw out the page that has been unused for
the longest time. This strategy is called LRU (Least Recently Used) paging.

Although LRU is theoretically realizable, it is not cheap. To fully implement
LRU, it is necessary to maintain a linked list of all pages in memory, with the
most recently used page at the front and the least recently used page at the rear.
The difficulty is that the list must be updated on every memory reference. Finding
a page in the list, deleting it, and then moving it to the front is a very time consuming
operation, even in hardware (assuming that such hardware could be built).

 

5.The Second Chance Page Replacement Algorithm 二次机会置换算法

A simple modification to FIFO that avoids the problem of throwing out a
heavily used page is to inspect the R bit of the oldest page. If it is 0, the page is
both old and unused, so it is replaced immediately. If the R bit is 1, the bit is

cleared, the page is put onto the end of the list of pages, and its load time is
updated as though it had just arrived in memory. Then the search continues.

 

6.The Clock Page Replacement Algorithm 时钟页面置换算法

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值