Clock-Pro: An Effective Replacement in OS Kernel
description
Transcript of Clock-Pro: An Effective Replacement in OS Kernel
Clock-Pro: An Effective Replacement in OS Kernel
Xiaodong Zhang
College of William and Mary
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.
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.
Basic CLOCK Replacement
0
CLOCK hand
0
1
0
0
0
01100
01
1
0
0
1
0
11 0 0
0
On a HITSet Reference bit to 1
(no algorithm operations)
10
Basic CLOCK Replacement
0
CLOCK hand
1
0
0
0
01100
01
1
0
0
1
0
11 0 0
0
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”
100
0
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 has been Widely Used
Multics
UNIX/AIX/Linux/BSD
VAX/VMS
DB2
Windows/Oracle/Solaris
Tanebaum & Woodhull
Silberschatz & Galvin
Stallings (for
undergraduate)
Major OS Major OS Textbooks
Prior Work on LRU versus CLOCK
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)
LRU related work CLOCK related work
1968 2003CAR (2004, FAST)
CLOCK-Pro (2005, USENIX)
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.
GCLOCK Replacement
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.
Age-Based CLOCK in Linux and FreeBSD
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.
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
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)
Basic Ideas of CLOCK-Pro
CLOCK-Pro Structure
0 01
0
0
1
0
0
00
0
01
0
0
hand-hot
hand-test
hand-cold
0
12
3
4
5
6
7
8
9
10 11
12 1314
15
16
17
18
19
20
21
22
23
240
1
1
Cold resident
Hot
Cold non-resident
0
All hands move in the clockwise direction.Hand-cold is used to find
a page for replacement.
Hand-test: (1) to determine if a cold page is promoted to be hot; (2) remove non-resident cold pages out of the clock.
Hand-hot: find a hot page to be demoted into a cold page.
Two reasons for a resident cold page: (1) A fresh replacement: a first access.(2) It is demoted from a hot page.
0
12
3
4
5
6
7
8
9
10
1112 13
14
15
17
19
18
20
21
22
2324
hand-hot
hand-test
hand-cold
16
0 01
0
0
1
0
0
0
0
0
0
0
0
0
2
9
13
15
17
18 19
20
21
22
23
24
00
00
00
0
0
00
1
1
16
14
1211
10
8
7 6
5
43
10
00
ResidentCold Pages
Non-resident Cold PagesHot Pages
Clock
Accessing Sequence: ….27, 7, 26, 25, 4, 23
Accessing Sequence: ….27, 7, 26, 25, 4, 23
0 0
12
3
4
5
6
7
8
9
10
1112 13
14
15
17
19
18
20
21
22
2324
hand-hot
hand-test
hand-cold
16
0 01
0
0
1
0
0
0
0
0
0
0
0
0
2
9
13
15
17
18 19
20
21
22
23
24
00
00
00
0
0
00
1
1
5
43
10
00
Hot Pages
Clock
Current accessing:Page 23
Current accessing:Page 23
Hit! Set reference bit of Page 23 to 1.No other operation
Hit! Set reference bit of Page 23 to 1.No other operation
16
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
1
1
0 0
12
3
4
5
6
7
8
9
10
1112 13
14
15
17
19
18
20
21
22
2324
hand-hot
hand-test
hand-cold
16
0 11
0
0
1
0
0
0
0
0
0
0
0
0
2
9
13
15
17
18 19
20
21
22
23
24
10
00
00
0
0
00
1
1
5
43
10
00
Hot Pages
Clock
Current accessing:Page 4
Current accessing:Page 4
Hit! Set reference bit of Page 4 to 1.No other operation
Hit! Set reference bit of Page 4 to 1.No other operation
16
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
11
0 0
12
3
4
5
6
7
8
9
10
1112 13
14
15
17
19
18
20
21
22
2324
hand-hot
hand-test
hand-cold
16
0 11
0
0
1
0
0
0
0
0
0
0
0
1
2
9
13
15
17
18 19
20
21
22
23
24
10
00
00
0
0
00
1
1
5
43
1
10
Hot Pages
Clock
Current accessing:Page 25
Current accessing:Page 25
16
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
0
(1) run hand-cold--- reclaim the first met cold page with ref bit 0 (Page 5)
(1) run hand-cold--- reclaim the first met cold page with ref bit 0 (Page 5)(2) Reclaim cold page 5 and remove it from resident cold page list
(2) Reclaim cold page 5 and remove it from resident cold page list
Miss!Miss!0 0
12
3
4
6
7
8
9
10
1112 13
14
15
17
19
18
20
21
22
2324
hand-hot
hand-test
16
0 11
0
0
1
0
0
0
0
0
0
0
1
2
9
13
15
17
18 19
20
21
22
23
24
10
00
00
0
0
00
1
1
43
1
10
Hot Pages
Clock
Current accessing:Page 25
Current accessing:Page 25
16
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
hand-cold
(3) Leave non-resident cold page 5 in the original position of clock list
(3) Leave non-resident cold page 5 in the original position of clock list
(5) run hand-test to find a position for page 5
(5) run hand-test to find a position for page 5
(4) Add page 5 into non-resident cold page list
(4) Add page 5 into non-resident cold page list
5
Non-resident
colde page list
is full!
0 0
12
3
4
6
7
8
9
10
1112 13
14
15
17
19
18
20
21
22
2324
hand-hot
hand-test
0 11
0
0
1
0
0
0
0
0
0
0
1
2
9
13
15
17
18 19
20
21
22
23
24
10
00
00
0
0
00
1
1
43
1
10
Hot Pages
Clock
Current accessing:Page 25
Current accessing:Page 25
(5) Add page 5 to non-resident cold page list
(5) Add page 5 to non-resident cold page list
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
hand-cold
05
5Reorganize clock list
Reorganize clock list
0 0
12
3
4
6
7
8
9
10
1112 13
14
15
18
20
19
21
22
23
24
17
hand-hot
hand-test
01
1
0
0
1
0
0
0
0
0
0
0
1
2
9
13
15
17
18 19
20
21
22
23
24
10
00
00
0
0
00
1
1
43
1
10
Hot Pages
Clock
Current accessing:Page 25
Current accessing:Page 25
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
hand-cold
05
5
Now we already have one empty room for page 25
Now we already have one empty room for page 25
(6) Check page 25 in non-resident page list---it is not in it
(6) Check page 25 in non-resident page list---it is not in it
(7) Add page 25 into clock and resident cold page list
(7) Add page 25 into clock and resident cold page list
025
025
page 25 does not
exit!
0 0
12
3
4
6
7
8
9
10
1112 13
14
15
18
20
19
21
22
23
24
17
hand-hot
hand-test
01
1
0
0
1
0
0
0
0
0
0
0
1
2
9
13
15
17
18 19
20
21
22
23
24
10
00
00
0
0
00
1
1
43
1
10
Hot Pages
Clock
Current accessing:Page 26
Current accessing:Page 26
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
hand-cold
05
5
Miss!Miss!
(1) run hand-cold to reach the first met cold resident page with reference bit 0
(1) run hand-cold to reach the first met cold resident page with reference bit 0
025
025
0 0
12
3
4
6
7
8
9
10
1112 13
14
15
18
20
19
21
22
23
24
17
hand-hot
hand-test
01
1
0
0
1
0
0
0
0
0
0
0
1
2
9
13
15
17
18 19
20
21
22
23
24
10
00
00
0
0
00
1
1
43
1
10
Hot Pages
Clock
Current accessing:Page 26
Current accessing:Page 26
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
hand-cold
05
5
025
025
1. Remove it from resident cold page list
1. Remove it from resident cold page list
Page 4 has reference bit 1, it should be upgraded to hot list.
Page 4 has reference bit 1, it should be upgraded to hot list.
0 0
12
3
6
7
8
9
10
1112 13
14
15
18
20
19
21
22
23
24
17
hand-hot
hand-test
01
1
0
0
1
0
0
0
0
0
0
0
2
9
13
15
17
18 19
20
21
22
23
24
10
00
00
0
0
00
1
1
3
1
0
Hot Pages
Clock
Current accessing:Page 26
Current accessing:Page 26
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
Page 4 has reference bit 1, it should upgrade to a hot page.
Page 4 has reference bit 1, it should upgrade to a hot page.
025
025
hand-cold
04
1. Remove it from resident cold page list
1. Remove it from resident cold page list
2. Reset the reference bit of page 4 and add it to hot page list
2. Reset the reference bit of page 4 and add it to hot page list
Hot page list is full!
0 0
12
3
6
7
8
9
10
1112 13
14
15
18
20
19
21
22
23
24
17
hand-hot
hand-test
01
1
0
0
1
0
0
0
0
0
0
0
2
9
13
15
17
18 19
20
21
22
23
24
10
00
00
0
0
00
1
1
3
1
0
Hot Pages
Clock
Current accessing:Page 26
Current accessing:Page 26
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
run hand-hot: degrade the first met hot page with reference bit 0 to a cold resident page
run hand-hot: degrade the first met hot page with reference bit 0 to a cold resident page
025
025
hand-cold
04
0 0
12
3
6
7
8
9
10
1112 13
14
15
18
20
19
21
22
23
17
hand-hot
hand-test
11
0
0
1
0
0
0
0
0
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
3
1
0
Hot Pages
Clock
Current accessing:Page 26
Current accessing:Page 26
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
Run hand-hot: degrade first met hot page with ref bit 0 to a cold resident page
Run hand-hot: degrade first met hot page with ref bit 0 to a cold resident page
025
025
hand-cold
04
024
Reorganize clock list
Reorganize clock list
0 0
12
3
6
7
8
9
10
11
1213 14
15
17
19
21
20
22
23
18
hand-hot
hand-test
1
1
0
0
1
00
0
00
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
3
1
0
Hot Pages
Clock
Current accessing:Page 26
Current accessing:Page 26
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
Page 4 is added into hot page list.
Page 4 is added into hot page list.
04
04
0240
24
Page 24 is added into cold page list.
Page 24 is added into cold page list.
0 0
12
3
6
7
8
9
10
11
1213 14
15
17
19
21
20
22
23
18
hand-test
1
1
0
0
1
00
0
00
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
3
1
0
Hot Pages
Clock
Current accessing:Page 26
Current accessing:Page 26
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
run hand-cold: Page 3 has reference bit 0, reclaim it and move hand-cold to the next position
run hand-cold: Page 3 has reference bit 0, reclaim it and move hand-cold to the next position
0 0
12
6
7
8
9
10
11
1213 14
15
17
19
21
20
22
23
18
hand-test
1
1
0
0
1
00
00
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
1
Hot Pages
Clock
Current accessing:Page 26
Current accessing:Page 26
14
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
Reclaim page 3 and add it into non-resident cold page list.
Reclaim page 3 and add it into non-resident cold page list.
04
04
0240
24
hand-hot
03
Non-resident
cold page list is full!
2. run hand-test: move 14 from non-resident cold page list.
2. run hand-test: move 14 from non-resident cold page list.
1. Leave non-resident cold page 3 in the old position in clock list.
1. Leave non-resident cold page 3 in the old position in clock list.
30 0
12
6
7
8
9
10
11
1213
15
17
19
21
20
22
23
18
hand-test
1
1
0
0
1
00
00
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
1
Hot Pages
Clock
Current accessing:Page 26
Current accessing:Page 26
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
Add page 3 into non-resident cold page list.
Add page 3 into non-resident cold page list.
04
04
0240
24
hand-hot
Reorganize clock list
Reorganize clock list
3
30 0
12
6
7
8
9
10
11
1213 15
17
18
20
22
21
23
19
hand-test
1
1
0
0
10
000
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
1
Hot Pages
Clock
Current accessing:Page 26
Current accessing:Page 26
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
3
3Add page 26 into resident cold page list and clock list
Add page 26 into resident cold page list and clock list
026
026
0 0
12
6
7
8
9
10
11
1213 15
17
18
20
22
21
23
19
hand-test
1
1
0
0
10
000
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
1
Hot Pages
Clock
Current accessing:Page 7
Current accessing:Page 7
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
3
3Miss!Miss!
026
026(1) run hand-cold:
reclaim the first met resident cold page (page 1)
(1) run hand-cold: reclaim the first met resident cold page (page 1)
0 0
2
6
7
8
9
10
11
1213 15
17
18
20
22
21
23
19
hand-test
1
1
0
0
10
000
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
Hot Pages
Clock
Current accessing:Page 7
Current accessing:Page 7
1211
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
3
3
026
026
1. Leave page 1 in the old position in clock list.
1. Leave page 1 in the old position in clock list.
1
Non-resident
cold page list is full!
2. run hand-test: to find a position for page 1
2. run hand-test: to find a position for page 1
2
6
7
8
9
10
11
13 1517
18
20
22
21
23
19
hand-test
1
1
0
0
10
000
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
Hot Pages
Clock
Current accessing:Page 7
Current accessing:Page 7
11
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
3
3
026
026
3. Add page 1 into non-resident cold page list.
3. Add page 1 into non-resident cold page list.
1
1
2
6
7
8
9
10
11
13 1517
18
20
22
21
23
19
hand-test
1
1
0
0
10
000
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
Hot Pages
Clock
Current accessing:Page 7
Current accessing:Page 7
11
10
8
7 6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
3
3
026
026
Now we have one empty slot in memory
Now we have one empty slot in memory
1
1
(1) check non-resident cold page list and find it---we need to upgrade it to hot page
(1) check non-resident cold page list and find it---we need to upgrade it to hot page
(2) run hand-hot: degrade the first met hot page with reference bit 0 to cold page
(2) run hand-hot: degrade the first met hot page with reference bit 0 to cold page
Hot page list is full!
2
6
8
9
10
11
13 1517
18
20
22
21
23
19
hand-test
1
1
0
0
10
000
0
0
2
9
13
15
17
18 19
20
21
22
231
00
00
0
0
00
1
1
Hot Pages
Clock
Current accessing:Page 7
Current accessing:Page 7
11
10
8
6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
3
3
026
026
1
1
07
0
0
Page 23 has reference bit 1---reset it to 0
Page 23 has reference bit 1---reset it to 0
2
6
8
9
10
11
13 1517
18
20
22
21
23
19
hand-test
0
1
0
0
10
000
0
0
2
9
13
15
17
18 19
20
21
22
230
00
00
0
0
00
1
1
Hot Pages
Clock
Current accessing:Page 7
Current accessing:Page 7
11
10
8
6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
3
3
026
026
1
1
07
0
0
Page 22 has reference bit 1---reset it to 0
Page 22 has reference bit 1---reset it to 0
2
6
8
9
10
11
13 1517
18
20
22
21
23
19
hand-test
0
0
0
0
10
000
0
0
2
9
13
15
17
18 19
20
21
22
230
00
00
0
0
00
0
1
Hot Pages
Clock
Current accessing:Page 7
Current accessing:Page 7
11
10
8
6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
3
3
026
026
1
1
07
Page 21 has reference bit 0---degrade it
Page 21 has reference bit 0---degrade it
2
6
8
9
10
11
13 1517
18
20
22
23
19
hand-test
0
0
0
10
000
0
0
2
9
13
15
17
18 19
20
22
230
00
0
0
0
00
0
1
Hot Pages
Clock
Current accessing:Page 7
Current accessing:Page 7
11
10
8
6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
3
3
026
026
1
1
07
(3) Degrade page 21 to resident cold page
(3) Degrade page 21 to resident cold page
Reorganize clock list
Reorganize clock list
21
0
2
6
8
9
10
11
13
1517 18
19
20
22
23
20
hand-test
0
0
01000
0
0
0
2
9
13
15
17
18 19
20
22
230
00
0
0
0
00
0
1
Hot Pages
Clock
Current accessing:Page 7
Current accessing:Page 7
11
10
8
6
ResidentCold Pages
Non-resident Cold Pages
05
5
025
025
hand-cold
04
04
0240
24
hand-hot
3
3
026
026
1
1
(4) insert page 21 to resident cold page and clock list
(4) insert page 21 to resident cold page and clock list
0 7
0 7
(5) insert page 7 to hot page and clock list
(5) insert page 7 to hot page and clock list
210
210
Clock-Pro Implementation in Kernels The Linux kernel for our implementation is 2.4.21.
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.
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