Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Study of Page Replacement Algorithm Based On Experiment: Wang Hong

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

2012 International Conference on Mechanical Engineering and Automation

Advances in Biomedical Engineering, Vol.10

Study of Page Replacement Algorithm Based on Experiment


Wang Hong
School of computer and communication engineering, Weifang University,
Weifang, Shandong 261061
wcjsdwf@126.com
Keywords: Page replacement, Page fault, FIFO, LRU, OPT.

Abstract . The page replacement algorithm is an very important step which realize virtual memory
control. A good page replacement algorithm can reduce the fault frequency when program
executing, reduce the number of I/O, and then increase the systems efficiency effectively. In this
paper, we studied the principle of various of page replacement algorithm, designed an program
which simulated the procession and result of page replacement algorithm, in this program, we
assume a few condition, record the experiment results. According to these data, we compared and
analyzed the page fault and page fault frequency of different algorithm, and compare their
performance.
1.

Introduction

A programs execution process different fault rates as the amount of memory allocation varies. For
stack algorithms, as the memory size is decreased using any particular algorithm, the fault rate will
increase. Therefore, we will discuss the various of the policy of page replacement in follow, study
the frequency of page fault, and then decided which algorithm we will use in different system..
2.

Page Replacement Algorithm

2.1 The fist-in-fist-out (FIFO)


The fist-in-fist-out (FIFO) replacement algorithm repleases the page that has been in memory
longest.It treats the page frames allocated to a process as a circular buffer, and pages arc removed in
round-robin style. All that is required is a pointer that circles through the page frames of the
process. This is therefore one of the simplest page replacement policies to implement. The logic
behind this choice, other than its simplicity, is that one is replacing the page that has been in
memory the longest: A page fetched into memory a long time ago may have now fallen out of use.
This reasoning often be wrong, because there will often be regions of program or data that are
heavily used throughout the life of a program. Those pages will be repeatedly paged m and out by
the FIFO algorithm.
2.2 Least Recently Used(LRU)
The least-recently-used (LRU) algorithm is designed to take advantage of "normal" program
behavior. Programs are written to contain loops, which cause the main line of the code to execute
repeatedly, with special-case code rarely being executed. This means that in the code part of the
address space, the control unit will repeatedly access the set of pages containing these loops. This
set of pages that contains the code is called the code locality of the process. If the loop or loops that
are executed are stored in a small number of pages, then the program has a small code locality. In
many programs, there is a similar data locality or stack locality whereby the process tends to
978-1-61275-028-6/10/$25.00 2012 IERI

330

ICMEA 2012

repeatedly read from and write to a subset of the data when it executes the program. For example, a
program that is solving a system of equations will tend to repeatedly reference the part of the
address space that contains the coefficient matrix for the system of equations. While almost all
programs have relatively small code localities, several classes of programs have no particularly
useful data locality. (For example, a transaction processing system usually has "poor data locality,"
meaning that there is no relationship between sequential data transactions.)
The LRU replacement algorithm is explicitly designed to take advantage of locality by assuming
that if a page has been referenced recently, it is likely to be referenced again soon. The backward
distance of page r at time t, BKWDt(r), is the distance (in the reference stream) from r to the last
occurrence of the page in the preceding part of the reference stream. The backward distance is
always greater than 0 and is infinite if the page has not been referenced previously. LRU selects a
page, yt for replancement with the maximum backward distance:
yt = max xst-l(m)=BKWDt(x).
The assumption is that because of locality, the backward distance is a good estimator of the
forward distance of any page. If more than one page has maximal backward distance, LRU may
choose an arbitrary page with maximal backward distance for replacement.
2.3 Optimal algorithm(OPT)
The optimal policy selects for replacement that page for which the time to the next reference is the
longest. It can be shown that this policy results in the fewest number of page faults. At the other
extreme from random replacement is the replacement policy having "perfect knowledge" of the
page reference stream; thus it always chose an optimal page to be removed from the memory. Let
the forward distance of a page r at time t, FWDt(r), be the distance from the current point in the
reference stream to the next place in the stream where the same page is referenced again. The
forward distance is always greater than 0 and is infinite if the page is never referenced again. In the
optimal algorithm, the replaced page, yt, is one that has maximal forward distance:
yt = max xst-l(m)=FWDt(x)
Since more than one page is loaded at time t. there may be more than one page that never appears
again in the reference stream--that is, there may be more than one loaded page with maximal
forward distance. In this case, Belady's optimal algorithm chooses an arbitrary loaded page with
maximal forward distance. The optimal algorithm can be implemented only if the full page
reference stream is known in advance. Since it is rate for the system to have such knowledge, the
algorithm is not generally realizable. Instead, its theoretical behavior is used to compare the
performance of realizable algorithms with the optimal performance.

331

main

Variable nitialization

Generate a series of random numbers


and initialize the environment

display FIFO out of sequence page

display FIFO page fault number

display LRU out of sequence page


and page fault number

display OPT out of sequence page


and page fault number

end

Fig.1 Process flow chart

Fig.2 A result of this program

In a few special cases (such as a program to predict the weather), large programs are used enough
to merit careful analysis of their paging behavior Although it is usually not possible to exactly
predict the page reference stream, one can sometimes predict the next page with high probability
that the prediction will be correct. For example, the conditional branch instruction at the end of a
loop almost always branches back to the beginning of the loop rather than exiting it. Such
predictions are based on static analysis of the source code or on observations of dynamic behavior
of the program. This analysis can produce enough information to incorporate replacement "hints" in
the source code, although the process is labor-intensive and only worthwhile on programs that are
long running and frequently executed. The compiler and paging systems can then be designed to
use these hints to predict the future behavior of the page reference stream.
3.

Experiment Content and Data Analysis

3.1 Experiment content


(1)Experiment step
To Simulate realization a variety of page replacement algorithms. The step as follows:
Use generating random number function, again a random series, as the page sequence which will
be loaded into memory.
Use FIFO, LRU and OPT algorithm, give the page sequence which will be out of memory.
332

List the number of page fault.


(2) Experimental environment
This experiment can bee done in Turbo C environment, also it can be done in VC serious in
Windows system,, and gcc in Linux. We do it in VC6.0.
(3) Program design
In this experiment, we assume the memory block number is four which the system allocated the
process. Assume use the first fit memory algorithm, and define the length which Generating random
numbers is 39. These two item both given by macro definition. The algorithm which needs
simulation include: FIFO, LRU and OPT algorathms.
The functions which user defined as follows:
Isinbuf():return some data X in or not in the buffer[], if it in, return its location ; if not, return -1.
oldest()return the page location which least recently used.
oldest2()return the page location which time to the next reference is the longest.
Program design process as fig.1.
Execute this program, the result as fig.2.
3.2 The result of experiment
Executing this program for ten times, then produce ten page sequence, the fault page number of
each sequence shown in tab 1.
Tab.1 The data recorded
algorithm
number
of fault

FIFO

LRU

OPT

18

17

11

22

21

14

20

21

13

18

20

13

23

22

13

23

23

16

22

22

15

215

25

14

20

22

13

10

13

12

10

order

4.

Conclusion

According to the experiment recorder, we analyzed the count data, we can made the conclusion:
The FIFO policy is very simple to implement, but performs relatively poorly. The optimally policy
is impossible to implement, because it would require the operating system to have perfect
knowledge of future events. However, it does serve as a standard against which to judge real-world
algorithms. The LRU algorithm is the nearest to the OPT algorithm..

333

References
[1] Feng HongWei, Wang Peng. Operating system teaching and experimental design research.
Laboratory research and exploration, in 2007, the 26th volume (12 issues): 251-253.
[2] Wang Hong, Hou Gang and so on, operating system Discipline (Linux)) - - exercise
explanation, sample question analysis, experimental instruction (the second edition). Beijing:
Water conservancy and Hydroelectric Power Press, August, 2008. 214-284.
[3] Yang Yanhang, Sun Bingxin. A Security Policy for Operating System, Journal of North-East
Forestry.
[4] Wang Yahui, Zhong Keding, Yuying. An Idea of Security Enhancement based on Linux
Operating System, Computer Applications and Software.
[5] Zhang Heng, Zhang Yusen, Lu Weidong, Implementation and Assessment on the Capability
Mechanism of Linux Security Enhancement System, Journal of System Simulation.
[6] Pan Yu, Han Jun, A Network Security Policy and Protection Measures Based on Linux
System , Computer and Information Technology.
[7] William Stallings, Operating Systems internals and design principles. Beijing: Electronic
Industry Press ,2006.3
[8] Gary Nutt. Operating systems:A Modern perspective . Beijing: Posts & Telecom Press ,
[9] Wu Xiaoming, Guo Yudong, Computer Security, Technology Forum

334

You might also like