Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Page replacement algorithm
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Aging=== The aging algorithm is a descendant of the NFU algorithm, with modifications to make it aware of the time span of use. Instead of just incrementing the counters of pages referenced, putting equal emphasis on page references regardless of the time, the reference counter on a page is first shifted right (divided by 2), before adding the referenced bit to the left of that binary number. For instance, if a page has referenced bits 1,0,0,1,1,0 in the past 6 clock ticks, its referenced counter will look like this in chronological order: 10000000, 01000000, 00100000, 10010000, 11001000, 01100100. Page references closer to the present time have more impact than page references long ago. This ensures that pages referenced more recently, though less frequently referenced, will have higher priority over pages more frequently referenced in the past. Thus, when a page needs to be swapped out, the page with the lowest counter will be chosen. The following [[Python (programming language)|Python]] code simulates the aging algorithm. Counters <math>V_i</math> are initialized with {{val|0}} and updated as described above via <math>V_i \leftarrow (R_i \ll (k-1)) | (V_i \gg 1)</math>, using [[Arithmetic shift|arithmetic shift operators]]. <syntaxhighlight lang="python"> from collections.abc import Sequence def simulate_aging(Rs: Sequence, k: int) -> None: # Simulate aging print(" t | R-bits (0-{length}) | Counters for pages 0-{length}".format(length=len(Rs))) Vs = [0] * len(Rs[0]) for t, R in enumerate(Rs): Vs[:] = [R[i] << (k - 1) | V >> 1 for i, V in enumerate(Vs)] print("{:02d} | {} | [{}]".format(t, R, ", ".join(["{:0{}b}".format(V, k) for V in Vs]))) </syntaxhighlight> In the given example of R-bits for 6 pages over 5 clock ticks, the function prints the following output, which lists the R-bits for each clock tick {{mvar|t}} and the individual counter values <math>V_i</math> for each page in [[Binary number|binary]] representation.<ref>{{cite book |first1=Andrew S. |last1=Tanenbaum |first2=Herbert |last2=Bos |date=2015 |title=Modern Operating Systems |edition=4th |publisher=Pearson |location=Boston, MA, USA |page=215 |isbn=978-0-13-359162-0 |ol=25620855M}}</ref> <syntaxhighlight lang="pycon"> >>> Rs = [[1,0,1,0,1,1], [1,1,0,0,1,0], [1,1,0,1,0,1], [1,0,0,0,1,0], [0,1,1,0,0,0]] >>> k = 8 >>> simulate_aging(Rs, k) t | R-bits (0-5) | Counters for pages 0-5 00 | [1, 0, 1, 0, 1, 1] | [10000000, 00000000, 10000000, 00000000, 10000000, 10000000] 01 | [1, 1, 0, 0, 1, 0] | [11000000, 10000000, 01000000, 00000000, 11000000, 01000000] 02 | [1, 1, 0, 1, 0, 1] | [11100000, 11000000, 00100000, 10000000, 01100000, 10100000] 03 | [1, 0, 0, 0, 1, 0] | [11110000, 01100000, 00010000, 01000000, 10110000, 01010000] 04 | [0, 1, 1, 0, 0, 0] | [01111000, 10110000, 10001000, 00100000, 01011000, 00101000] </syntaxhighlight> Note that aging differs from LRU in the sense that aging can only keep track of the references in the latest {{val|16|/|32}} (depending on the bit size of the processor's integers) time intervals. Consequently, two pages may have referenced counters of 00000000, even though one page was referenced 9 intervals ago and the other 1000 intervals ago. Generally speaking, knowing the usage within the past 16 intervals is sufficient for making a good decision as to which page to swap out. Thus, aging can offer near-optimal performance for a moderate price.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)