This Presentation that tries to formalise paging algorithm. Intention follows a philosophy that, If an idea is understood precisely then it is much easier to innovate and prove mathematically.
2. Page and Page frames
• N is a set of page indices
– N = {1, 2, 3, …, n}.
– Each consisting of c contiguous
memory space.
• M is a set of page frame indices
– M = {1, 2, 3, …, m}.
– Each consisting of c contiguous
address space.
• 1 ≤ m ≤ n.
• At each moment of time t there is a page
map
ft : N → M ∪ { 0 } s.t.
2Formalising Paging
3. Address Translation
• When a processor generates an
address α, the hardware
computes memory location
address :
– Where x is determined from :
• If ft(x)= 0, the hardware
generates a page fault interrupt
that signals an appropriate task to
secure the missing page from
auxiliary memory.
3Formalising Paging
4. Reference String
• A program’s paging behaviour for a given input is described in machine independent
terms by its (page) reference string, which is a sequence:
• The discrete time parameter t= 1,2,3,… represents instants in “process” or “execution”
time.
• rt = i means that page “i” is referenced at tth reference.
• We use the notation NT for the set of all reference string of length T.
N+ will denote set of all finite-length strings over N, not including the empty string.
• Corresponding to the references r1r2r3…rt… is a sequence of instants in real time
a1a2a3…at… s.t. at is the instant at which rt is made.
• P(ω) : Probability mass function over NT, s.t. denotes the probability of ω’s occurance.
4Formalising Paging
8. Speed Ratio
• ΔA : Average time to transfer a page between
auxiliary memory and main memory.
• Δm : Average time to access a word when page is
in main memory.
• Speed ratio :
• Intuitively, it’s the number of time increase in
access because of auxiliary memory with respect
to main memory.
Auxiliary
Memory
8Formalising Paging
CPU
ΔAΔm
9. Space Time Product
• Real time elapsing between t and t+1 in
process time is approximately
• Fault rate F(ω) : number of page faults
encountered while processing the reference
string ω.
• Space time:
9Formalising Paging
10. Paging Algorithm
• Paging algorithm A is a mechanism for processing
reference string
• This generates a sequence of memory states
• Each memory state St is the set of pages from N
which reside in M at time t and they satisfy:
• Where |S| denotes the number of elements in S.
10Formalising Paging
11. Paging Algorithm ( cont )
• St and St-1 are related by
– {xt} : set of fetched pages.
– {yt} : set of replaced pages.
• Q : set of records called control states with initial
state be q0.
• A configuration of an algorithm is any pair
(S, q) | |S| ≤ m and q ∈ Q.
11Formalising Paging
12. Paging Algorithm ( cont )
• Transition function of algorithm A, gA is defined
as:
• Where
– (S, q) is current configuration and
– (S’, q’) is next configuration.
• precisely, S0S1S2…St… is contained in
configuration sequence
generated by :
12Formalising Paging
14. Paging Algorithm ( Exemplified )
• A paging algorithm A is a demand paging
algorithm if for a given m > 0 the transition
function gA implies that
• The choice y of page to be replaced is
prerogative of algorithm A.
14Formalising Paging
15. Forward Distance
• Forward distance: Distance to the first reference
to x after time t.
15Formalising Paging
16. Backward Distance
• Backward distance: The distance to the most recent
reference to x before time t.
16Formalising Paging
17. Reuse Distance
• Reuse distance: Distance between two occurances
of x after time t.
17Formalising Paging
18. Replacement Algorithm
• Replacement algorithm is denoted as R(S,q,x)
– S : current state of memory
– q: current configuration
– x: rt+1 the next reference.
• Suppose |S| = m and x ∉ S then.
18Formalising Paging
19. Cost Function
• The cost generated by paging algorithm A,
operating on reference string ω=r1r2…rt in
memory of size m, is denoted C(A, m, ω)
• h(k) : cost of a single auxiliary memory
transaction involving group of k pages.
• Expected cost :
• We define A to be optimal with respect to p(ω)
if it minimizes C(A, m)
19Formalising Paging
20. Optimal Replacement policy
• Page faults are unavoidable.
• Best choice of replacement algorithm A: replace
page with longest expected forward distance.
• By doing so, A maximizes the expected time
between page faults due to returning pages and
therefore cost.
20Formalising Paging
21. Belady’s OPT Algorithm ( B0 )
• Replace page with largest forward distance.
• Theoretical approach, cannot be implemented.
21Formalising Paging
ω r1 r2 r3 r4 r5
i 1 2 3 1 2
S2 S3
X 2 3
Y - 2
1 3
2 2
m
R(S2 , q2 , 3 ) = 2
t
22. Least Recently Used ( LRU )
• The page in S that is replaced is the one with
largest backward distance.
22Formalising Paging
ω r1 r2 r3 r4 r5
i 1 2 3 2 1
S2 S3
X 2 3
Y - 1
1 3
2 2
m
R(S2 , q2 , 3 ) = 1
FORMALLY
t
23. Least Frequently Used ( LFU )
• Replace page with least use.
ft(x) denote the number of references to x in r1…rt
23Formalising Paging
ω r1 r2 r3 r4 r5
i 1 2 2 3 1
m
R(S2 , q2 , 3 ) = 1
S2 S3
X - 3
Y - 1
1 3
22 22
FORMALLY
t
25. Predicament
• Does not care locality of a programme.
• Some approximation algorithms are well suited
for some applications, but not for all.
• It fails to distinguish between individual pages,
making the program spatially uniform.
• Does not account for the dependence of present
behaviour on the past.
Formalising Paging 25
27. references
THEORETICAL REFERENCES:
• Belady, L.A. A study of replacement algorithms for virtual storage computers. IBM Systems J. 5, 2 (1966), 78–101.
• Peter J. Denning . Thrashing: its causes and prevention. AFIPS '68 (Fall, part I) Proceedings of the December 9-11, 1968, fall joint
computer conference, part I. Pages 915-922.
• P. J. Denning. Dynamic Storage Allocation Systems. IEEE Transactions on Computers Volume 18 Issue 9, September 1969
Page 866-866.
• Peter J. Denning . Principles of computer system organization. ACM SIGCSE Bulletin Volume 1 Issue 3, October 1969
Pages 27-30.
• Coffman, E. G. Jr., and Denning, P. J. Operating Systems Theory, Prentice-Hall, Englewood Cliffs, New Jersey, 1973.
• A.V. Aho, P.J. Denning, and J.D. Ullman, “Principles of Optimal Page Replacement,” J. ACM, vol. 18, no. 1, 1971, pp. 80-93.
ALGORITHMS REFERENCES:
• E.J. O’Neil, P.E. O’Neil, and G. Weikum, “An Optimality Proof of the LRU-K Page Replacement Algorithm,” J. ACM, vol. 46, no. 1,
1999, pp. 92-112.
• T. Johnson and D. Shasha, “2Q: A Low OverheadHigh-Performance Buffer Management Replacement Algorithm,” Proc. VLDB
Conf., Morgan Kaufmann, 1994, pp. 297-306.
• S. Jiang and X. Zhang, “LIRS: An Efficient Low Inter- Reference Recency Set Replacement Policy to Improve Buffer Cache
Performance,” Proc. ACM Sigmetrics Conf., ACM Press, 2002; http://parapet.ee.princeton.edu/ sigm2002/papers/p31-jiang.pdf.
• Y. Zhou and J.F. Philbin, “The Multi-Queue Replacement Algorithm for Second-Level Buffer Caches,” Proc. Usenix Ann. Tech. Conf.
(Usenix 2001), Usenix, 2001, pp. 91-104.
• N. Megiddo and D.S. Modha, “ARC: A Self-Tuning, Low Overhead Replacement Cache,” Proc. Usenix Conf. File and
StorageTechnologies (FAST 2003), Usenix, 2003, pp. 115-130.
• S. Bansal, and D. Modha, CAR: Clock with Adaptive Replacement, FAST-’04 Proceedings of the 3rd USENIX Conference on File and
Storage Technologies, pp. 187-200, 2004.
27Formalising Paging