Re: [RFC 5/5] truncate: Remove unnecessary page release

From: KAMEZAWA Hiroyuki
Date: Sun Dec 19 2010 - 23:41:26 EST


On Mon, 20 Dec 2010 11:58:50 +0900
Minchan Kim <minchan.kim@xxxxxxxxx> wrote:

> On Mon, Dec 20, 2010 at 11:27 AM, KAMEZAWA Hiroyuki
> <kamezawa.hiroyu@xxxxxxxxxxxxxx> wrote:
> > On Mon, 20 Dec 2010 11:21:52 +0900 (JST)
> > KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxxxxxxx> wrote:
> >
> >> > This patch series changes remove_from_page_cache's page ref counting
> >> > rule. page cache ref count is decreased in remove_from_page_cache.
> >> > So we don't need call again in caller context.
> >> >
> >> > Cc: Nick Piggin <npiggin@xxxxxxx>
> >> > Cc: Al Viro <viro@xxxxxxxxxxxxxxxxxx>
> >> > Cc: linux-mm@xxxxxxxxx
> >> > Signed-off-by: Minchan Kim <minchan.kim@xxxxxxxxx>
> >> > ---
> >> > Âmm/truncate.c | Â Â1 -
> >> > Â1 files changed, 0 insertions(+), 1 deletions(-)
> >> >
> >> > diff --git a/mm/truncate.c b/mm/truncate.c
> >> > index 9ee5673..8decb93 100644
> >> > --- a/mm/truncate.c
> >> > +++ b/mm/truncate.c
> >> > @@ -114,7 +114,6 @@ truncate_complete_page(struct address_space *mapping, struct page *page)
> >> > Â Â Â* calls cleancache_put_page (and note page->mapping is now NULL)
> >> > Â Â Â*/
> >> > Â Â cleancache_flush_page(mapping, page);
> >> > - Â page_cache_release(page); Â Â Â /* pagecache ref */
> >> > Â Â return 0;
> >>
> >> Do we _always_ have stable page reference here? IOW, I can assume
> >> cleancache_flush_page() doesn't cause NULL deref?
> >>
> > Hmm, my review was bad.
> >
> > I think cleancache_flush_page() here should eat (mapping, index) as argument
> > rather than "page".
> >
> > BTW, ÂI can't understand
> > ==
> > void __cleancache_flush_page(struct address_space *mapping, struct page *page)
> > {
> > Â Â Â Â/* careful... page->mapping is NULL sometimes when this is called */
> > Â Â Â Âint pool_id = mapping->host->i_sb->cleancache_poolid;
> > Â Â Â Âstruct cleancache_filekey key = { .u.key = { 0 } };
> > ==
> >
> > Why above is safe...
> > I think (mapping,index) should be passed instead of page.
>
> I don't think current code isn't safe.
>
> void __cleancache_flush_page(struct address_space *mapping, struct page *page)
> {
> /* careful... page->mapping is NULL sometimes when this is called */
> int pool_id = mapping->host->i_sb->cleancache_poolid;
> struct cleancache_filekey key = { .u.key = { 0 } };
>
> if (pool_id >= 0) {
> VM_BUG_ON(!PageLocked(page));
>
> it does check PageLocked. So caller should hold a page reference to
> prevent freeing ramined PG_locked
> If the caller doesn't hold a ref of page, I think it's BUG of caller.
>
> In our case, caller calls truncate_complete_page have to make sure it, I think.
>

Ah, my point is that this function trust page->index even if page->mapping is
reset to NULL. And I'm not sure that there are any race that an other thread
add a replacement page for (mapping, index) while a thread call this function.

Thanks,
-Kame



--
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/