Clock-Pro is an approximation of the LIRS page replacement algorithm that is built on the existing CLOCK infrastructure in operating system kernels. It categorizes pages as either cold or hot based on their reuse distances, and uses three clock hands to manage the different page types. The allocation of memory between hot and cold pages is adjusted adaptively. Clock-Pro aims to address some limitations of previous CLOCK-based algorithms by more closely modeling LIRS behavior.
2. How to Make LIRS Work in OS Kernels?
q Most system kernels use the CLOCK algorithm, an
approximation of LRU.
q We have made efforts to directly implement LIRS in
Linux kernels, but …
q Our experience tells us that we must build on
existing strength.
q CLOCK is the base for LIRS.
3. Basic CLOCK Replacement
All the resident pages are placed around a circular list, like a clock;
Each page is associated with a reference bit, indicating if the page has been
accessed.
1 0 0
0
1 0
0 1
0
1 CLOCK hand 0
0 1
On a HIT 0 0
Set Reference bit to 1
(no algorithm operations) 1 0
1 0
0 0
0 1 1
0
4. Basic CLOCK Replacement
Starts from the currently pointed page, and evicts the page if it is”`0”;
Move the clock hand until reach a “0” page;
Give “1” page a second chance, and reset its “1” to “0”
1 0 0
0
1 0
0 0
1
On a sequence of 1 CLOCK hand 0
two MISSes
0 0
0 1
1 0
1 0
0 0
0 1 1
0
5. The CLOCK with a Long History
“In the Multics system a paging algorithm has been developed that
has the implementation ease and low overhead of the FIFO strategy
and is an approximation to the LRU strategy”
“A paging Expreiment with the Multics System” MIT Project MAC
Report MAC-M-384, May 1968, Fernando J. Corbato (1990 Turing Award Laureate)
6. The CLOCK has been Widely Used
Major OS Major OS Textbooks
Multics Tanebaum & Woodhull
UNIX/AIX/Linux/BSD Silberschatz & Galvin
VAX/VMS Stallings (for undergraduate)
DB2
Windows/Oracle/Solaris
7. Prior Work on LRU versus CLOCK
LRU related work CLOCK related work
FBR (1990, SIGMETRICS)
GCLOCK (1978, ACM TDBS)
LRU-2 (1993, SIGMOD)
2Q (1994, VLDB)
SEQ (1997, SIGMETRICS)
LRFU (1999, OSDI)
EELRU (1999, SIGMETRICS)
MQ (2001, USENIX)
1968 2003
LIRS (2002, SIGMETRICS) CAR (2004, FAST)
ARC (2003, FAST) CLOCK-Pro (2005, USENIX)
8. GCLOCK Replacement
Introduce additional page access information.
A counter is associated with each page rather than a
single bit;
The counter is incremented on a page hit;
The clock hand periodically moves, and decrements
the counter of each block;
The page with its counter of 0 is replaced.
9. Age-Based CLOCK in Linux and FreeBSD
An age is associated with each page in addition to a
reference bit;
When the clock hand sweeps through pages, it
increases its age if the page’s bit is 1, otherwise it
decreases its age.
The page with its age of 0 is replaced.
10. CAR: CLOCK with Adaptive Replacement
Two clocks T1 and T2, one is for cold pages touched only once recently (Recency),
another is for hot pages touched at least twice (“Frequency”);
Queues B1 and B2 are for pages recently replaced from T1 and T2;
The memory allocations for T1 or T2 depend on the ratio of references
to B2 and B1.
11. Limits of CAR
A page that is regularly accessed with its reuse distance a little bit
larger memory size has no hits in T1 or T2. (inherited LRU problem).
A page in T2 can stay in memory without any accesses because
frequency does not reflect ``reuse distance”.
No system implementations yet
12. Basic Ideas of CLOCK-Pro
It is an approximation of LIRS based on the CLOCK infrastructure.
Pages categorized into two groups: cold pages and hot pages
based on their reuse distances (or IRR).
There are three hands: Hand-hot for hot pages,
Hand-cold for cold pages, and Hand-test for running a reuse
distance test for a block;
The allocation of memory pages between hot pages (Mhot) and
cold pages (Mcold ) are adaptively adjusted. (M = Mhot + Mcold)
All hot pages are resident (=Lir blocks), some cold pages are also
resident (= Hir Blocks); keep track of recently replaced pages
(=non-resident Hir blocks)
13. 0 1 Cold resident CLOCK-Pro Structure
0 1 Hot
1 24
Cold non-resident 2 23
Hand-hot: find a hot 0
3 0 0
page to be demoted 0 22
into a cold 0
page. 1
4
0
0 21
5 0 hand-hot
0 20
Two reasons for a resident cold page: All hands move
6 1 19
• A fresh replacement: a first access. hand-cold in the clockwise
• It is demoted from a hotused to find
Hand-cold is page. direction. hand-test
7
a page for replacement. 0 18
8 0 17
Hand-test: (1) to determine if a
0
cold page is promoted to be hot; (2)
9 16
remove non-resident cold pages out 0
of the clock. 10 15
1 0
11 14
12 13
Then LRU is approximated by the CLOCK replacement in VM. In CLOCK, All the resident pages are placed around the a circular list, like a clock. There is a clock hand turning in the clockwise direction to search victim pages. Each page is associated with a reference bit, indicating if the page has been accessed. On a hit access, the bit is set automatically by hardware, there are no algorithm operations.
On a miss access, CLOCK t urns the clock hand, evict the first “0” page; CLOCK inserts the missed page at the head, initialize its reference bit to 0. If the ref-bit of page pointed by the hand is “1”, CLOCK gives it a second chance without replacing it, And reset its “1” to “0” and continue to look for a page with its bit of “0” CLOCK simulates LRU replacement very well, and its hit ratios are very close to LRU.
The CLOCK replacement has a long history. It dates back to 1968, F. Corbato describes the CLOCK in his report on Multics system: … Corbato later won Turing Award in 1990.
CLOCK or its variants have been widely used in major OS and described in textbooks. It still plays a dominant role in today’s systems, even with its performance concerns with certain access patterns.
Now let’s see the prior research work on LRU and CLOCK. Because the importance of replacement algorithms and the well-known LRU performance problems, there are a large number of new algorithms proposed for better performance, but almost all of them target at LRU. See the long list over the decades. However, the list for CLOCK is much shorter. See, from 1968 to 1998, it is a really a long time for a person! Only GCLOCK and several CLOCK variants are proposed during the long time. The very stringent low cost requirement poses a big challenge on inventing new VM replacement. Recently there is a VM replacement algorithm called CAR proposed by the researchers at IBM. And we proposed the CLOCK-Pr n pljn.o.
FCLOCK introduce …
Linux and FreeBSD use age-based CLOCK replacements. … However, GCLOCK and age-based CLCOK cannot provide consistent performance improvements. Their performance can be either better or worse than CLOCK. Another problem is that they will consume too many CPU cycles and adjust to changes in the access patterns slowly.
CAR is a recently proposed VM replacement algorithm. In CAR, ….
However, in CAR, …. So some undesirable situation can occur. E.g. … So CAR also can not consistently improve CLOCK performance.
Now let’s see CLOCK-Pro, which uses the same principle as that of LIRS …
I would like to use the figure to illustrate CLOCK-Pro. There are several kinds of pages on the clock. …. I associate a test period to a cold page to test its reuse distance.