Mark_Accessed(b) {
if b.state==(UNACTIVE && UNREFERENCE)
b.state = REFERENCE
else if b.state == (UNACTIVE && REFERENCE) {
b.state = (ACTIVE && UNREFERENCE)
Add X to tail of active_list
} else if b.state == (ACTIVE && UNREFERENCE)
b.state = (ACTIVE && REFERENCE)
}
Reclaim() {
if active_list not empty and scan_num<MAX_SCAN1
{
X = head of active_list
if (X.state & REFERENCE) == 0
Add X to tail of inactive_list
else {
X.state &= ~REFERENCE
Move X to tail of active_list
}
scan_num++
}
scan_num = 0
if inactive_list not emptry and scan_num <
MAX_SCAN2 {
X = head of inactive_list
if (X.state & REFERENCE) == 0
return X
else {
X.state = ACTIVE | UNREFERENCE
Move X to tail of active_list
}
scan_num++
}
return NULL
}
Access(b){
if b is not in cache {
if slot X free
put b into X
else {
X=Reclaim()
put b into X
}
Add X to tail of inactive_list
}
Mark_Accessed(X)
}
5 文件Cache相关API及其实现
Linux 内核中与文件Cache操作相关的API有很多,按其使用方式可以分成两类:一类是以拷贝方式操作的相关接口,如read/write/sendfile等,其中sendfile在2.6系列的内核中已经不再支持;另一类是以地址映射方式操作的相关接口,如 mmap等。