page_count() in shrink_list()?

Submitted by Anonymous
on August 12, 2005 - 11:46pm

Hi, I have a question about page_count(page *) in shrink_list() ( 2.6.11 source code ).
When kswapd began to shrink_cache(),it will first collect and get (Line 565) the pages in zone->inactive_list whose original page->_count are not zero into a temp list:page_list and pass these pages to shrink_list() to check and try to free some fit pages(Line 574)..
565 if (get_page_testone(page)) {
569 __put_page(page);
570 SetPageLRU(page);
571 list_add(&page->lru, &zone->inactive_list);
572 continue;
573 }
574 list_add(&page->lru, &page_list);
...

589 nr_freed = shrink_list(&page_list, sc);

in shrink_list(),I dont know why kernel will judge the expression
if(page_count(page)!=2) before doing something with this page.IMHO,
after a page is allocated ,its page_count() is 1 and again kernel add
1 in shrink_cache (line 565).So I think if the page is in page cache
or swap cache ,its page_count() is at least 3 and line 485 will not be
satisfied.
480 /*
481 * The non-racy check for busy page. It is critical to check
482 * PageDirty _after_ making sure that the page is freeable and
483 * not in use by anybody. (pagecache + us == 2)
484 */
485 if (page_count(page) != 2 || PageDirty(page)) {
486 spin_unlock_irq(&mapping->tree_lock);
487 goto keep_locked;
488 }
How?

refcounts

on
August 13, 2005 - 5:11am

I don't know about this code, but the first reference you get when you allocate an object has to be 'passed on' to the user it was allocated for (or has to be dropped after the object got inserted into a data structure, which incremenented the count), i.e. drop_reference(allocate()) should be an NOP. So i assume "after a page is allocated ,its page_count() is 1" and "the page is in page cache
or swap cache" means the same reference. After all, if the object is removed from the above mentioned data structure, its refcount should become zero.

RE

on
August 13, 2005 - 5:54am

Thanks a lot.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.