page replacement policy in the latest Linux kernel
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
Hi Zheng... On Wed, Feb 8, 2012 at 04:21, Zheng Da <zhengda1936@gmail.com> wrote:
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).
I am not really sure about it. According to UTLK (I know, it is dated), page goes as "inactive, not referenced" first. -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
Hello, On Tue, Feb 7, 2012 at 11:04 PM, Mulyadi Santosa <mulyadi.santosa@gmail.com>
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).
I am not really sure about it. According to UTLK (I know, it is dated), page goes as "inactive, not referenced" first.
Yes, when a page is added to a list by add_to_page_cache_lru(), it's inactive and not referenced, but the referenced bit will be set in the same read, so I put them together. Please read do_generic_file_read(). If a page doesn't exist in the page cache, it will load the page and add it to the page cache. In the same iteration of the for loop, mark_page_accessed() is called to mark it referenced. So UTLK isn't wrong. It's just a little misleading. Thanks, Da
Hi :) On Wed, Feb 8, 2012 at 13:24, Zheng Da <zhengda1936@gmail.com> wrote:
Please read do_generic_file_read(). If a page doesn't exist in the page cache, it will load the page and add it to the page cache. In the same iteration of the for loop, mark_page_accessed() is called to mark it referenced.
So UTLK isn't wrong. It's just a little misleading.
Looks like you're correct. UTLK is based on old version of linux kernel, so quite likely the current kernel release update the way it does page replacement. Like I said, it is dated :) -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
participants (2)
-
Mulyadi Santosa -
Zheng Da