From: Miklos Szeredi <miklos@szeredi.hu>
To: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Cc: kamezawa.hiroyu@jp.fujitsu.com, miklos@szeredi.hu,
akpm@linux-foundation.org, minchan.kim@gmail.com,
linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] mm: add replace_page_cache_page() function
Date: Tue, 11 Jan 2011 10:38:16 +0100 [thread overview]
Message-ID: <E1PcagC-0007Ge-40@pomaz-ex.szeredi.hu> (raw)
In-Reply-To: <20110111125330.e416cff5.nishimura@mxp.nes.nec.co.jp> (message from Daisuke Nishimura on Tue, 11 Jan 2011 12:53:30 +0900)
On Tue, 11 Jan 2011, Daisuke Nishimura wrote:
> > What I recommend is below. (Please see the newest -mm because of a bug fix for
> > mem cgroup) Considering page management on radix-tree, it can be considerd as
> > a kind of page-migration, which replaces pages on radix-tree.
> >
> > ==
> >
> > > +int replace_page_cache_page(struct page *old, struct page *new, gfp_t gfp_mask)
> > > +{
> > > + int error;
> > > +
> > > + VM_BUG_ON(!PageLocked(old));
> > > + VM_BUG_ON(!PageLocked(new));
> > > + VM_BUG_ON(new->mapping);
> > > +
> > struct mem_cgroup *memcg;
> >
> I think it should be initialized to NULL.
>
> > error = mem_cgroup_prepare_migration(old, new, &memcg);
>
> I want some comments like:
>
> /*
> * This is not page migration, but prepare_migration and end_migration
> * does enough work for charge replacement.
> */
>
> > #
> > # This function will charge against "newpage". But this expects
> > # the caller allows GFP_KERNEL gfp_mask.
> > # After this, the newpage is in "charged" state.
> > if (error)
> > return -ENOMEM;
> >
> > > + error = radix_tree_preload(gfp_mask & ~__GFP_HIGHMEM);
> > > + if (!error) {
> > > + struct address_space *mapping = old->mapping;
> > > + pgoff_t offset = old->index;
> > > +
> > > + page_cache_get(new);
> > > + new->mapping = mapping;
> > > + new->index = offset;
> > > +
> > > + spin_lock_irq(&mapping->tree_lock);
> > > + __remove_from_page_cache(old);
> > > + error = radix_tree_insert(&mapping->page_tree, offset, new);
> > > + BUG_ON(error);
> > > + mapping->nrpages++;
> > > + __inc_zone_page_state(new, NR_FILE_PAGES);
> > > + if (PageSwapBacked(new))
> > > + __inc_zone_page_state(new, NR_SHMEM);
> > > + spin_unlock_irq(&mapping->tree_lock);
> > > + radix_tree_preload_end();
> >
> > > + mem_cgroup_replace_cache_page(old, new); <== remove this.
> >
> > mem_cgroup_end_migraton(memcg, old, new, true);
> >
> > > + page_cache_release(old);
> > > + }
> > else
> > mem_cgroup_end_migration(memcg, old, new, false);
> >
> > # Here, if the 4th argument is true, old page is uncharged.
> > # if the 4th argument is false, the new page is uncharged.
> > # Then, "charge" of the old page will be migrated onto the new page
> > # if replacement is done.
> >
> >
> >
> > > +
> > > + return error;
> > > +}
> > > +EXPORT_SYMBOL_GPL(replace_page_cache_page);
> > > +
> >
> > ==
> >
> > I think this is enough simple and this covers all memory cgroup's racy
> > problems.
> >
> I agree.
Thanks for the comments.
Yeah, using existing infrastructure is undoubtedly simpler and less
prone to bugs. So going with this for a first implementation might
do.
However, replace_page_cache_page() is meant to be very efficient,
otherwise any performance won by not copying the page contents are
lost to the cost of page replacement. My guess is,
mem_cgroup_prepare_migration()/end_migration() are to heavyweight for
this.
Thanks,
Miklos
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom policy in Canada: sign http://dissolvethecrtc.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2011-01-11 9:38 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-07 18:22 Miklos Szeredi
2011-01-11 2:29 ` KAMEZAWA Hiroyuki
2011-01-11 3:53 ` Daisuke Nishimura
2011-01-11 9:38 ` Miklos Szeredi [this message]
2011-01-11 5:41 ` Minchan Kim
-- strict thread matches above, loose matches on Subject: below --
2010-12-15 15:49 Miklos Szeredi
2010-12-15 16:49 ` Rik van Riel
2010-12-15 23:22 ` Minchan Kim
2010-12-16 11:59 ` Miklos Szeredi
2010-12-16 22:04 ` Minchan Kim
2010-12-17 1:21 ` Hugh Dickins
2010-12-17 1:40 ` Minchan Kim
2010-12-17 2:10 ` Hugh Dickins
2010-12-17 4:37 ` Minchan Kim
2010-12-17 15:53 ` Miklos Szeredi
2010-12-16 1:07 ` KAMEZAWA Hiroyuki
2010-12-16 12:05 ` Miklos Szeredi
2010-12-17 0:01 ` KAMEZAWA Hiroyuki
2010-12-17 15:51 ` Miklos Szeredi
2010-12-19 23:54 ` KAMEZAWA Hiroyuki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1PcagC-0007Ge-40@pomaz-ex.szeredi.hu \
--to=miklos@szeredi.hu \
--cc=akpm@linux-foundation.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan.kim@gmail.com \
--cc=nishimura@mxp.nes.nec.co.jp \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox