lkml.org 
[lkml]   [2011]   [Jan]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [BUGFIX][PATCH] memcg: fix memory migration of shmem swapcache
On Wed, Jan 05, 2011 at 01:00:20PM +0900, Daisuke Nishimura wrote:
> In current implimentation, mem_cgroup_end_migration() decides whether the page
> migration has succeeded or not by checking "oldpage->mapping".
>
> But if we are tring to migrate a shmem swapcache, the page->mapping of it is
> NULL from the begining, so the check would be invalid.
> As a result, mem_cgroup_end_migration() assumes the migration has succeeded
> even if it's not, so "newpage" would be freed while it's not uncharged.
>
> This patch fixes it by passing mem_cgroup_end_migration() the result of the
> page migration.

Are there other users that rely on unused->mapping being NULL after
migration?

If so, aren't they prone to misinterpreting this for shmem swapcache
as well?

If not, wouldn't it be better to remove that page->mapping = NULL from
migrate_page_copy() altogether? I think it's an ugly exception where
the outcome of PageAnon() is not meaningful for an LRU page.

To your patch:

> --- a/mm/memcontrol.c
> +++ b/mm/memcontrol.c
> @@ -2856,7 +2856,7 @@ int mem_cgroup_prepare_migration(struct page *page,
>
> /* remove redundant charge if migration failed*/
> void mem_cgroup_end_migration(struct mem_cgroup *mem,
> - struct page *oldpage, struct page *newpage)
> + struct page *oldpage, struct page *newpage, int result)
> {
> struct page *used, *unused;
> struct page_cgroup *pc;
> @@ -2865,8 +2865,7 @@ void mem_cgroup_end_migration(struct mem_cgroup *mem,
> return;
> /* blocks rmdir() */
> cgroup_exclude_rmdir(&mem->css);
> - /* at migration success, oldpage->mapping is NULL. */
> - if (oldpage->mapping) {
> + if (result) {

Since this function does not really need more than a boolean value,
wouldn't it make the code more obvious if the parameter was `bool
success'?

if (!success) {
> used = oldpage;
> unused = newpage;
> } else {

Minor nit, though. I agree with the patch in general.

Hannes


\
 
 \ /
  Last update: 2011-01-05 13:01    [W:0.116 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site