page replacement policy in the latest Linux kernel

Zheng Da zhengda1936 at gmail.com
Tue Feb 7 16:21:34 EST 2012


Hello,

I'm trying to understand the page replacement policy in the latest Linux
kernel and reimplement a similar one in the user space.
As far as I can understand from ULK and the code, there are two lists:
active list and inactive list.
Here I only consider the case of the *page cache*:
When a page is added to the page cache (by add_to_page_cache_lru), it is
also added to the inactive list and its reference bit is set (by
mark_page_accessed).
When a page is accessed again, it is added to the active list and the
reference bit is cleared (by mark_page_accessed).
When a page is accessed and it's in the active list, the reference bit is
set if it's not set (by mark_page_accessed).

When the system is out of free pages, it starts to shrink the cache.
When a page is in the active list, if the page hasn't been referenced for a
period of time (page_referenced() returns 0, and for the pages in the page
cache, it's always 0), it will be moved to the inactive list (in
shrink_active_list);
When a page is in the inactive list, if the page hasn't been referenced
(it's always true for pages in the page cache), reclaim the page (in
shrink_inactive_list);
When the system is out of free pages, it always starts to reclaim pages in
the inactive list first, unless the number of pages in the active list is
larger than that in the inactive list.

Please correct me if any part is wrong for the page cache.

Thanks,
Da
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20120207/b64e53f2/attachment.html 


More information about the Kernelnewbies mailing list