Download presentation
Presentation is loading. Please wait.
Published byFarida Agusalim Modified over 6 years ago
1
Clock-Pro: An Effective Replacement in OS Kernel
Xiaodong Zhang College of William and Mary
2
How to Make LIRS Work in OS Kernels?
Most system kernels use the CLOCK algorithm, an approximation of LRU. We have made efforts to directly implement LIRS in Linux kernels, but … Our experience tells us that we must build on existing strength. 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 1 1 1 CLOCK hand 1 On a HIT Set Reference bit to 1 (no algorithm operations) 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. 1 1 1 1
4
Basic CLOCK Replacement On a sequence of two MISSes
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 1 1 On a sequence of two MISSes 1 CLOCK hand 1 On a miss access, CLOCK turns 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. 1 1 1 1
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) 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.
6
The CLOCK has been Widely Used
Major OS Major OS Textbooks Multics UNIX/AIX/Linux/BSD VAX/VMS DB2 Windows/Oracle/Solaris Tanebaum & Woodhull Silberschatz & Galvin Stallings (for undergraduate) 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.
7
Prior Work on LRU versus CLOCK
LRU related work CLOCK related work FBR (1990, SIGMETRICS) LRU-2 (1993, SIGMOD) 2Q (1994, VLDB) SEQ (1997, SIGMETRICS) LRFU (1999, OSDI) EELRU (1999, SIGMETRICS) MQ (2001, USENIX) LIRS (2002, SIGMETRICS) ARC (2003, FAST) GCLOCK (1978, ACM TDBS) 1968 2003 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. CAR (2004, FAST) CLOCK-Pro (2005, USENIX)
8
Introduce additional page access information.
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. FCLOCK introduce …
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. 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.
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. CAR is a recently proposed VM replacement algorithm. In CAR, ….
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 However, in CAR, …. So some undesirable situation can occur. E.g. … So CAR also can not consistently improve CLOCK performance.
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) Now let’s see CLOCK-Pro, which uses the same principle as that of LIRS …
13
Cold resident CLOCK-Pro Structure 1 Hot 1 1 24 Cold non-resident 2 23 Hand-hot: find a hot page to be demoted into a cold page. 3 22 1 4 21 5 hand-hot 20 Two reasons for a resident cold page: A fresh replacement: a first access. It is demoted from a hot page. All hands move in the clockwise direction. 6 1 19 hand-cold Hand-cold is used to find a page for replacement. 7 hand-test 18 8 17 Hand-test: (1) to determine if a cold page is promoted to be hot; (2) remove non-resident cold pages out of the clock. 16 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. 9 10 15 1 11 14 12 13
14
1 1 1 hand-hot hand-cold hand-test Accessing Sequence:
….27, 7, 26, 25, 4, 23 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 19 18 20 21 22 23 24 5 4 3 1 1 Resident Cold Pages hand-hot 1 hand-cold Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 16 16 14 12 11 10 8 7 6 Hot Pages Non-resident Cold Pages
15
1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 23 1 2 3
4 5 6 7 8 9 10 11 12 13 14 15 17 19 18 20 21 22 23 24 5 4 3 1 1 Hit! Set reference bit of Page 23 to 1. No other operation 1 Resident Cold Pages hand-hot 1 hand-cold Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 16 16 14 12 11 10 8 7 6 Hot Pages Non-resident Cold Pages
16
1 1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 4 1 2 3
5 6 7 8 9 10 11 12 13 14 15 17 19 18 20 21 22 23 24 5 4 3 1 1 Hit! Set reference bit of Page 4 to 1. No other operation 1 1 Resident Cold Pages hand-hot 1 hand-cold Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 16 16 14 12 11 10 8 7 6 Hot Pages Non-resident Cold Pages
17
1 1 1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 25
(1) run hand-cold--- reclaim the first met cold page with ref bit 0 (Page 5) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 19 18 20 21 22 23 24 5 4 3 1 1 Miss! 1 1 1 Resident Cold Pages hand-hot (2) Reclaim cold page 5 and remove it from resident cold page list 1 hand-cold Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 16 16 14 12 11 10 8 7 6 Hot Pages Non-resident Cold Pages
18
Non-resident colde page list is full!
Current accessing: Page 25 1 2 3 4 6 7 8 9 10 11 12 13 14 15 17 19 18 20 21 22 23 24 4 3 1 1 (3) Leave non-resident cold page 5 in the original position of clock list 1 1 1 Resident Cold Pages 5 hand-cold hand-hot (4) Add page 5 into non-resident cold page list 1 (5) run hand-test to find a position for page 5 Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 16 Non-resident colde page list is full! 16 14 12 11 10 8 7 6 Hot Pages Non-resident Cold Pages
19
1 1 1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 25 1
3 4 6 7 8 9 10 11 12 13 14 15 17 19 18 20 21 22 23 24 4 3 1 1 (5) Add page 5 to non-resident cold page list 1 1 1 Reorganize clock list Resident Cold Pages 5 hand-cold hand-hot 1 Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 14 12 11 10 8 7 6 5 Hot Pages Non-resident Cold Pages
20
1 1 1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 25 1
3 4 6 7 8 9 10 11 12 13 14 15 18 20 19 21 22 23 24 17 25 4 3 1 Now we already have one empty room for page 25 1 1 1 1 hand-hot Resident Cold Pages (6) Check page 25 in non-resident page list---it is not in it 5 hand-cold (7) Add page 25 into clock and resident cold page list Clock 1 hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 page 25 does not exit! 14 12 11 10 8 7 6 5 Hot Pages Non-resident Cold Pages
21
1 1 1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 26 1
3 4 6 7 8 9 10 11 12 13 14 15 18 20 19 21 22 23 24 17 25 4 3 1 25 Miss! 1 1 (1) run hand-cold to reach the first met cold resident page with reference bit 0 1 1 hand-hot Resident Cold Pages 5 hand-cold Clock 1 hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 14 12 11 10 8 7 6 5 Hot Pages Non-resident Cold Pages
22
1 1 1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 26 1
3 4 6 7 8 9 10 11 12 13 14 15 18 20 19 21 22 23 24 17 25 4 3 1 25 Page 4 has reference bit 1, it should upgrade to a hot page. 1 1 1 1 hand-hot Resident Cold Pages 1. Remove it from resident cold page list 5 hand-cold Clock 1 hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 14 12 11 10 8 7 6 5 Hot Pages Non-resident Cold Pages
23
1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 26 1 2 3
7 8 9 10 11 12 13 14 15 18 20 19 21 22 23 24 17 25 3 1 25 Page 4 has reference bit 1, it should upgrade to a hot page. 1 hand-cold 1 hand-hot Resident Cold Pages 1. Remove it from resident cold page list 5 2. Reset the reference bit of page 4 and add it to hot page list Clock 1 4 hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 Hot page list is full! 14 12 11 10 8 7 6 5 Hot Pages Non-resident Cold Pages
24
1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 26 1 2 3
7 8 9 10 11 12 13 14 15 18 20 19 21 22 23 24 17 25 3 1 25 run hand-hot: degrade the first met hot page with reference bit 0 to a cold resident page 1 hand-cold 1 hand-hot Resident Cold Pages 5 Clock 1 4 hand-test 2 9 13 15 17 18 19 20 21 22 23 24 1 14 12 11 10 8 7 6 5 Hot Pages Non-resident Cold Pages
25
1 1 1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 26 1
3 6 7 8 9 10 11 12 13 14 15 18 20 19 21 22 23 17 25 3 1 25 Run hand-hot: degrade first met hot page with ref bit 0 to a cold resident page 1 hand-cold 1 hand-hot Resident Cold Pages 5 Reorganize clock list 24 Clock 1 4 hand-test 2 9 13 15 17 18 19 20 21 22 23 1 14 12 11 10 8 7 6 1 5 1 Hot Pages Non-resident Cold Pages
26
1 1 1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 26 1
3 6 7 8 9 10 11 12 13 14 15 17 19 21 20 22 23 18 25 3 1 25 4 24 Page 4 is added into hot page list. 5 hand-cold Page 24 is added into cold page list. 1 Resident Cold Pages hand-hot 1 Clock 1 hand-test 2 9 13 15 17 18 19 20 21 22 23 1 14 12 11 10 8 7 6 1 5 1 Hot Pages Non-resident Cold Pages
27
1 1 1 1 1 1 hand-hot hand-cold hand-test Current accessing: Page 26 1
3 6 7 8 9 10 11 12 13 14 15 17 19 21 20 22 23 18 25 3 1 25 4 run hand-cold: Page 3 has reference bit 0, reclaim it and move hand-cold to the next position 24 5 hand-cold 1 Resident Cold Pages hand-hot 1 Clock 1 hand-test 2 9 13 15 17 18 19 20 21 22 23 1 14 12 11 10 8 7 6 1 5 1 Hot Pages Non-resident Cold Pages
28
Non-resident cold page list is full!
Current accessing: Page 26 1 2 6 7 8 9 10 11 12 13 14 15 17 19 21 20 22 23 18 25 1 25 4 3 24 Reclaim page 3 and add it into non-resident cold page list. 5 1 Resident Cold Pages 1. Leave non-resident cold page 3 in the old position in clock list. hand-cold hand-hot 1 2. run hand-test: move 14 from non-resident cold page list. Clock 1 hand-test 3 2 9 13 15 17 18 19 20 21 22 23 Non-resident cold page list is full! 1 14 12 11 10 8 7 6 1 5 1 Hot Pages Non-resident Cold Pages
29
1 1 1 1 1 1 hand-cold hand-hot hand-test Current accessing: Page 26 1
7 8 9 10 11 12 13 15 17 19 21 20 22 23 18 25 1 25 4 3 24 Add page 3 into non-resident cold page list. 5 Reorganize clock list 1 Resident Cold Pages hand-cold hand-hot 1 Clock 1 hand-test 2 9 13 15 17 18 19 20 21 22 23 1 12 11 10 8 7 6 1 5 3 1 Hot Pages Non-resident Cold Pages
30
1 1 1 1 1 1 hand-cold hand-hot hand-test Current accessing: Page 26 1
7 8 9 10 11 12 13 15 17 18 20 22 21 23 19 25 1 25 4 3 24 Add page 26 into resident cold page list and clock list 26 5 Resident Cold Pages hand-cold 1 hand-hot 1 Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 1 1 12 11 10 8 7 6 1 5 3 1 Hot Pages Non-resident Cold Pages
31
1 1 1 1 1 1 hand-cold hand-hot hand-test Current accessing: Page 7 1 2
6 7 8 9 10 11 12 13 15 17 18 20 22 21 23 19 25 1 25 4 3 24 Miss! 26 (1) run hand-cold: reclaim the first met resident cold page (page 1) 5 Resident Cold Pages hand-cold 1 hand-hot 1 Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 1 1 12 11 10 8 7 6 1 5 3 1 Hot Pages Non-resident Cold Pages
32
Non-resident cold page list is full!
Current accessing: Page 7 2 6 7 8 9 10 11 12 13 15 17 18 20 22 21 23 19 1 25 25 4 3 24 1. Leave page 1 in the old position in clock list. 26 5 Resident Cold Pages 2. run hand-test: to find a position for page 1 hand-cold 1 hand-hot 1 Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 1 Non-resident cold page list is full! 1 12 11 10 8 7 6 1 5 3 1 Hot Pages Non-resident Cold Pages
33
1 1 1 1 1 1 hand-cold hand-hot hand-test Current accessing: Page 7 2 6
8 9 10 11 13 15 17 18 20 22 21 23 19 1 25 25 4 3 24 3. Add page 1 into non-resident cold page list. 26 5 Resident Cold Pages hand-cold 1 hand-hot 1 Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 1 1 11 10 8 7 6 1 5 3 1 1 Hot Pages Non-resident Cold Pages
34
1 1 1 1 1 1 hand-cold hand-hot hand-test Current accessing: Page 7 2 6
8 9 10 11 13 15 17 18 20 22 21 23 19 1 25 25 4 3 24 Now we have one empty slot in memory 26 5 (1) check non-resident cold page list and find it---we need to upgrade it to hot page Resident Cold Pages hand-cold 1 hand-hot (2) run hand-hot: degrade the first met hot page with reference bit 0 to cold page 1 Clock hand-test 2 9 13 15 17 18 19 20 21 22 23 1 1 Hot page list is full! 11 10 8 7 6 1 5 3 1 1 Hot Pages Non-resident Cold Pages
35
1 1 1 1 1 1 hand-cold hand-hot hand-test Current accessing: Page 7 2 6
8 9 10 11 13 15 17 18 20 22 21 23 19 1 25 25 4 3 24 Page 23 has reference bit 1---reset it to 0 26 5 Resident Cold Pages hand-cold 1 hand-hot 1 Clock 7 hand-test 2 9 13 15 17 18 19 20 21 22 23 1 1 11 10 8 6 1 5 3 1 1 Hot Pages Non-resident Cold Pages
36
1 1 1 1 hand-cold hand-hot hand-test Current accessing: Page 7 2 6 8 9
10 11 13 15 17 18 20 22 21 23 19 1 25 25 4 3 24 Page 22 has reference bit 1---reset it to 0 26 5 Resident Cold Pages hand-cold hand-hot 1 Clock 7 hand-test 2 9 13 15 17 18 19 20 21 22 23 1 11 10 8 6 1 5 3 1 1 Hot Pages Non-resident Cold Pages
37
1 1 hand-cold hand-hot hand-test Current accessing: Page 7 2 6 8 9 10
11 13 15 17 18 20 22 21 23 19 1 25 25 4 3 24 Page 21 has reference bit 0---degrade it 26 5 Resident Cold Pages hand-cold hand-hot Clock 7 hand-test 2 9 13 15 17 18 19 20 21 22 23 1 11 10 8 6 5 3 1 1 Hot Pages Non-resident Cold Pages
38
1 1 hand-cold hand-hot hand-test Current accessing: Page 7 2 6 8 9 10
11 13 15 17 18 20 22 23 19 1 25 25 4 3 24 (3) Degrade page 21 to resident cold page 26 5 Reorganize clock list Resident Cold Pages hand-cold hand-hot Clock 21 7 hand-test 2 9 13 15 17 18 19 20 22 23 1 11 10 8 6 5 3 1 1 Hot Pages Non-resident Cold Pages
39
1 1 hand-cold hand-hot hand-test Current accessing: Page 7 2 6 8 9 10
11 13 15 17 18 19 20 22 23 1 25 21 25 4 3 24 (4) insert page 21 to resident cold page and clock list 26 5 Resident Cold Pages (5) insert page 7 to hot page and clock list hand-cold hand-hot Clock 7 hand-test 2 9 13 15 17 18 19 20 22 23 11 10 8 6 1 5 3 1 1 Hot Pages Non-resident Cold Pages
40
Clock-Pro Implementation in Kernels
The Linux kernel for our implementation is The VM management is well documented. (a Prentice Hall book in 04, Mel Gorman) We are able to adjust the memory size available to the system and to the user in our experiment environment. All pages are placed in a single clock list in CLOCK-PRO implementation with three hands. SPEC 2000 and memory intensive software tools are used as benchmarks to test the CLOCK-Pro. Compare the modified kernel with the original.
43
What is the Current Status of Clock-Pro?
Linux community is actively implementing it for its inclusion in the Kernel. Clock-Pro-Approximation. In Linux VM: Mhot == active list Mcold == inactive list Mtest == recently evicted pages
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.