An Efficient Algorithm and a Generic Approach to Reduce Page Fault Rate and Access Time Costs Riaz Shaik and M. Momin Pasha Department of Computer Science and Engineering, K L University, Vijayawada, India
[email protected],
[email protected]
Abstract. Memory management systems are generally custom-made where the replacement algorithm deals only with the number of memory hits. So, to reduce the page fault rate, we are proposing a page replacement algorithm called Farthest Page Replacement (FPR) algorithm. More the page faults lesser the performance. However, there are many other parameters which are to be considered like access time costs in the aspects of time and energy. Access time is the time required by a processor to access data or to write data from and to memory. Higher performance can be achieved with a reduction of access time costs. So, to decrease the access time and energy consumption, we are proposing an approach for selecting the page to be replaced. Keywords: Page replacement, Fault Rate, Access Time Cost, Memory Addresses.
1
Introduction
The time a program or device takes to locate a single piece of information and make it available to the computer for processing is called access time cost. The term is applied to both random access memory (RAM) access and to hard disk and CD-ROM access. The access time for disk drives includes the time it actually takes for the read/write head to locate a sector on the disk (called the seek time). It depends on how far away the head is from the desired data. Access time is also frequently used to describe the speed of disk drives. It is composed of a few independently measurable elements that are added together to get a single value when evaluating the performance of a storage device. Access time costs are considered while measuring overall performance of a system. In the following fig.2, access time of A is more than access time of B. It is because B is located nearer than A. Access Time Costs (A) > Access Time Costs (B)
© Springer International Publishing Switzerland 2015 S.C. Satapathy et al. (eds.), Emerging ICT for Bridging the Future – Volume 1, Advances in Intelligent Systems and Computing 337, DOI: 10.1007/978-3-319-13728-5_58
513
514
R. Shaik and M.M. Pasha
Fig. 1. Lesser the Access Time Costs higher the performance
Fig. 2. Access Time Costs of different addresses
Main memory is the important and limited resources of a computer. As it is limited, it must be utilized efficiently to get better performance. Now one has to design capable approaches to handle main memory effectively. A page fault occurs when a program requests an address on a page that is not in the current set of memory resident pages. What happens when a page fault occurs is that the thread that experienced the page fault is put into a Wait state while the operating system finds the specific
An Efficient Algorithm and a Generic Approach
515
page on disk and restores it to physical memory. The OS then locates a copy of the desired page on the page file, and copies the page from disk into a free page in RAM. Once the copy has completed successfully, the OS allows the program thread to continue on. If the RAM does not have any empty frame then page replacement[1] is done. And the replacement is done based upon different approaches. With this, the overall objective is to decrease the total page fault rate[2] and thereby improve the performance.
Fig. 3. Occurrence of Page Fault
2
Related Work
In a computer operating system that uses paging for virtual memory management, page replacement algorithms decide which memory pages to be replaced when a new page request causes page fault. There are a variety of page replacement algorithms. The simplest page-replacement algorithm is a FIFO algorithm. The first-in, first-out (FIFO) page replacement algorithm is a low-overhead algorithm which replaces the first page entered into the frame. The other one is least recently used page (LRU) replacement algorithm. LRU[3] works on the idea that pages that have been most heavily used in the past few instructions are most likely to be used heavily in the next few instructions too. In this manner, there are various algorithms for page replacement. But as of now the finest among them is optimal page replacement algorithm which has the least page fault rate. In this algorithm the page that will not be used for the longest period of time will be replaced. For example, let us consider s reference string
1
1 1 2
2
5 1 2 5
8 8 2 5
3 2 5 3 3 2 2 5 5
1 3 2 5
5
3 3 1 5
3 1 5
516
R. Shaik and M.M. Pasha
Initially when the memory is empty the requests up to the frame size can be served. From then, the reference to the page 8 replaces page 1 because 1 will not be used until reference 8. Whereas page 2 will be used at 6 and page 5 at 7.The reference to page 3 replaces page 8 as page 8 is no longer used again in the string. This process continues until the last reference. But the disadvantage of the optimal page replacement policy is that it is very difficult to implement. In this paper, we are proposing a simple page replacement algorithm which can be implemented easily and also yields the same number of page faults like optimal page replacement. However, if we have a reference strings like this 9
1
7 3
8
2
4
6
0
in which no page is referred more than once, all the page replacement algorithms[6] would yield the same number of page faults[7] which results in performance degradation. Considering such cases, to improve the performance, we are proposing an approach.
3
Paper Contribution
3.1
Farthest Page Replacement Algorithm
Farthest Page replacement (FPR) algorithm is the simplest page replacement algorithm. A FPR replacement algorithm associates with address of the each page. When a page must be replaced, the farthest page is chosen. For our example reference string, our three frames are initially empty. 70120304230321201701 7
7 0
7 0 1
2 0 1
2 0 1
3 0 1
3 0 1
4 0 1
2 0 1
3 0 1
3 0 1
3 0 1
2 0 1
2 0 1
2 0 1
2 0 1
2 0 1
7 0 1
7 0 1
7 0 1
The first three references (7, 0, 1) cause page faults and are brought into these empty frames. The next reference (2) replaces page 7, because page 7 was farthest. Since 0 is the next reference and 0 is already in memory, we have no fault for this reference. The first reference to 3 results in replacement of page 2, since it is now farthest in line. Because of this replacement, the next reference, to 4, will fault. Page 3 is then replaced by page 4. This process continues and there are 9 faults altogether. For the same reference string FIFO[5] would result in 15 page faults, LRU[4] would yield 12 page faults and Optimal Page Replacement algorithm would generate 9 page faults. Thus the number of page faults generated for this string by our algorithm is the least page fault rate of all the existing algorithms.
An Efficient Algorithm and a Generic Approach
3.1.1
517
Pseudo Code
/*This pseudo-code is to find the farthest page among the pages present in the frame*/ for(j=1; j < Frame_Size; j++) If (frames[j] > FARTHEST) FARTHEST=j; /*replacing the farthest page with the new page which caused page fault*/ frames[FARTHEST]=New_Page;
3.2
An Approach to Reduce the Access Time Costs Basing on Addresses of the Pages
Although there are many page replacement algorithms to decrease the page fault rate, it is well known fact that page fault rate is completely based on references [8]. There may be cases where the best algorithm also yields the same number of page faults as the worst algorithm. At that time, fault rate is unavoidable. So, in such cases, to improve the performance, we are proposing an approach which reduces the access time cost. The main principle of our approach is Replace the page which will be nearest of the available pages. i.e. whenever a page fault occur, compare the addresses of the pages which are already present in the frame and find out the nearest among them. Select that page as victim and replace it with the new page which caused page fault. For example, let us consider the same string we have taken earlier
9
9 1
9 1 7 3 8 9 9 9 1 3 8 7 7 7
2
4 9 8 2
6 0 9 9 8 8 4 6
9 8 0
For this kind of references any algorithm would yield same number of page faults. But by following our approach performance can be improved. The main reason for selecting nearest page as victim page[9] is, if the same page is referred again, access time cost will be less and thus performance will be improved.
518
R. Shaik and M.M. Pasha
3.2.1 Application These cases will occur in all the algorithms. In LRU page replacement algorithm what if a page fault occurred and all the pages in the frame are referred same number of times. And in optimal page replacement algorithm consider a scenario where none of the pages in the frame are going to be referred again. In such cases FIFO will be implemented by default. Instead of that, if our approach is implemented we can minimize the access time and thus advance the performance. 3.2.2
Pseudo Code
for(i=0;i