Formalising Paging 1
FORMALISING PAGING
L J Gokul Vasan
Formalising Paging 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.
Formalising 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.
Formalising 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.
Formalising Paging 5
Reference String( Exemplified )t 1
rt r1
i 1
ω = {r1}
Formalising Paging 6
Reference String( Exemplified )• rt
• r1
• i• 1
ω = {r1 r2}
t 1 2
rt r1 r2
i 1 5
Formalising Paging 7
Reference String( Exemplified )
ω = {r1 r2 r3}
t 1 2 3
rt r1 r2 r3
i 1 5 2
Formalising 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.
AuxiliaryMemory
CPUΔAΔm
Formalising Paging 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:
Formalising 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.
Formalising 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.
Formalising 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 :
Formalising Paging 13
Paging Algorithm ( Pictorial )
Formalising 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.
Formalising Paging 15
Forward Distance
• Forward distance: Distance to the first reference to x after time t.
Formalising Paging 16
Backward Distance
• Backward distance: The distance to the most recent reference to x before time t.
Formalising Paging 17
Reuse Distance
• Reuse distance: Distance between two occurances of x after time t.
Formalising 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.
Formalising 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)
Formalising 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.
Formalising Paging 21
Belady’s OPT Algorithm ( B0 )• Replace page with largest forward distance.• Theoretical approach, cannot be implemented.
ω r1 r2 r3 r4 r5
i 1 2 3 1 2
S2 S3
X 2 3
Y - 21 3
2 2m
Example
R(S2 , q2 , 3 ) = 2
FORM
ALLY
t
Formalising Paging 22
Least Recently Used ( LRU )• The page in S that is replaced is the one with
largest backward distance. ω r1 r2 r3 r4 r5
i 1 2 3 2 1
S2 S3
X 2 3
Y - 11 3
2 2m
Example
R(S2 , q2 , 3 ) = 1
FORM
ALLY
t
Formalising Paging 23
Least Frequently Used ( LFU )• Replace page with least use.
ft(x) denote the number of references to x in r1…rt
ω r1 r2 r3 r4 r5
i 1 2 2 3 1
m
ExampleR(S2 , q2 , 3 ) = 1
S2 S3
X - 3
Y - 1
1 3
22 22
FORM
ALLY
t
Formalising Paging 24
Replacement Algorithms
Formalising Paging 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 26
Thank You
Formalising Paging 27
referencesTHEORETICAL 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.