Re: [PATCH] take pageout refcount into account forremove_exclusive_swap_page

From: Lee Schermerhorn
Date: Thu May 15 2008 - 13:56:07 EST


On Thu, 2008-05-15 at 11:15 +0900, Daisuke Nishimura wrote:
> On 2008/05/14 4:02 +0900, Lee Schermerhorn wrote:
> > On Tue, 2008-05-13 at 14:09 -0400, Rik van Riel wrote:
> >> On Tue, 13 May 2008 13:43:55 -0400
> >> Lee Schermerhorn <Lee.Schermerhorn@xxxxxx> wrote:
> >>
> >>> Or, more generally, 2 + N, for an anon page that is mapped [must be
> >>> read-only, right?] by N processes. This can happen after, e.g., fork().
> >>> Looks like this patch handles the condition just fine, but you might
> >>> want to reflect this in the comment.
> >> No, this patch only removes a page from the swap cache that is mapped
> >> by one process. The function page_mapped() returns either 1 or 0, not
> >> the same as page_mapcount().
> >
> > Duh! I was reading "page_mapcount()", 'cause that's what I've been
> > considering using for this purpose.
> >
> >>
> >> I am not sure if trying to handle swap cache pages that are mapped by
> >> multiple processes could get us into other corner cases and think that
> >> we should probably try to stick to the safe thing for now.
>
> I think it would be better to add a comment of
> remove_exclusive_swap_page_ref() that it doesn't handle
> swap caches that are mapped by multiple processes for safty.
>
> >
> > OK. I can test the more general case down the road.
> >
> >> Besides, shouldn't anonymous shared pages be COW and relatively rare?
> >
> > Well, all anon pages are shared right after fork(), right? They only
> > become private once they've been written to. I don't have a feel for
> > the relative numbers of shared anon vs COWed anon--either in general or
> > in the swap cache.
> >
> >>> Now, I think I can use this to try to remove anon pages from the swap
> >>> cache when they're mlocked.
> >
> > ïI suppose I can just go ahead and use this version with my stress load
> > and count the times when I could have freed the swap cache entry, but
> > didn't because it's mapped in multiple address spaces. Later ... :)
> >
>
> Lee, Rik's version looks good to me except mlocked case, but
> do you have any plan to handle these cases?

Well, it's really just an optimization--freeing swap cache entry, if
possible, when mlocking a page. I'll patch Rik's version to use
page_mapcount() and test heavily before proposing to do this. I suppose
we can also discuss whether we want a separate version that frees swap
mapped by multiple tasks for the mlock case, and keep Rik's version for
vmscan. However, I think that if it's safe in the mlock case, it should
be safe for vmscan. We'll see.

Lee

>
>
> >>>> + */
> >>>> +int remove_exclusive_swap_page_ref(struct page *page)
> >>>> +{
> >>>> + return remove_exclusive_swap_page_count(page, 2 + page_mapped(page));
> >>>> +}
> >>>> +
> >>>> +/*
> >>>> * Free the swap entry like above, but also try to
> >>>> * free the page cache entry if it is the last user.
> >>>> */
> >>>>
> >>>> All Rights Reversed
> >>
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> > the body of a message to majordomo@xxxxxxxxxxxxxxx
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
> > Please read the FAQ at http://www.tux.org/lkml/
> >

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/