- If the paging technique reminds you of caching,
it is only because they both rely on the principle that
execution of computer program exhibits locality behavior
and exploits this behavior to achieve better resource
utilization.
As a result, in both techniques, a smaller amount of resource
is used to than the total amount needed and from time to time,
old entries must be replaced with newer one (because
the new ones are more likely to be used again in the near future.)
- The difference between the caching and the paging techniques is the
amount of time it takes to fetch an item:
- In caching, items fetched are words from memory and it takes
about 50 nsec to fetch one item.
- In paging, items fetched are pages from disk and it takes
50 - 100 msec to fetch one item.
- To make informed decision about which item to replace,
the computer can execute some subprogram (what else ?)
that consists of tens to about one hundred instructions
(rough estimate :-)) but not much more (or else it will
slow down paging and become counter-productive).
The computer will take about several milli second to run this program.
Such an informed decision routine will harm the performance
of caching rather than help, because time to run
the decision subroutine is much longer than
the time to fetch one item.
On the other hand, a few milli seconds extra is a negliglible
delay when added to 50 - 100 msec.
Therefore, we can make intelligent decision on which page to
replace but the algorithm must be as efficient as possible
(not too complicated).
- Before we study the effect of page faults on
the the behaviour of the computer system,
I need to motivate a "short hand" notation for page requests.
Consider the behavior of the following program:
-
I have listed the first few program addresses that will be requested
when the program is run.
The example program that I showed in the figure above
begins at address 0.
You can see that the first instruction fetched is at address 0
(the right column under "Program addresses requested").
Then the second instruction (at address 4), the third instruction
(at address 8) and the fourth instruction (at address 12)
are fetched and executed.
Instruction 4 (at address 12) is an instruction that uses a memory operand
at address 4908,
So the 5th memory request is for program address 4908.
Instruction 5 (at address 16) is fetched and executed,
and then instruction 6.
The 6th instruction again needs a memory operand, this time the
memory operand is located at address 5000.
- The figure also shows the page numbers requested when
the program is run.
The page number is obtained by locating the page in which the
program address resides.
(As you know, that depends on the program address and the page size.
In the example, I have assumed that the page size is 1 Kbytes).
- Notice that if the same page is requested for
a number of time, then only the first request can
cause a page fault
(the subsequent ones cannot, because after the first page
causes the page fault, the Operating System will
reading the page from disk.
As long as the CPU reads data from the same page,
there is aboslutely no reason in the world
that the CPU remove that page).
- So when studying the behaviour caused by
page faults, we can summarize the page requests
by representing multiple consecutive requests for
the same page number by just one single number.
- Suppose that the following is the summary of page numbers requested
by the CPU when the program is run:
And suppose that the above program is run in a computer system
that provides 3 frames (each 1 Kbytes)
of memory to run the program.
(The point of paging is to use less memory than the entire program
(which is 5 pages).
So there is no point in studying the behavior in a system with 5 frames
because there will never be a page fault after all pages have been
brought in.
I use 3 frames to illustrate the example is because if you look
at the program carefully, both inner loops span 3 pages....)
The program performance depends heavily how pages are replace
- More jargon:
- Page replacement policy:
the process to decide which a page in memory
will be replaced by a new (more recently referenced) page
read from disk.
The page replacement policy will affect the program performance.
- How do we tell if one page replacement policy if better (superior)
than another policy ?
- One page replacement policy is better if the same program run using that
policy will allow the program to finish quicker
than another policy.
- If everything being equal, then one page replacement policy is better if
it results in less page faults than the other policy -
because for every page fault, a (slow) disk operation
is invoked.
- There are 3 common page replacement policies for page systems:
- First In First Out (FIFO): simple, but not very good.
- Least Recently Used (LRU): the best, but takes a long time to
make a page selection decision.
- Second Changce (SC): reasonably efficient and approximates
the LRU policy