From: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
To: Minchan Kim <minchan.kim@gmail.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>,
Johannes Weiner <hannes@cmpxchg.org>,
Andrew Morton <akpm@linux-foundation.org>,
Balbir Singh <balbir@linux.vnet.ibm.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
LKML <linux-kernel@vger.kernel.org>,
linux-mm <linux-mm@kvack.org>
Subject: [BUGFIX][PATCH v3] memcg: fix memory migration of shmem swapcache
Date: Thu, 6 Jan 2011 12:34:15 +0900 [thread overview]
Message-ID: <20110106123415.895d6dfc.nishimura@mxp.nes.nec.co.jp> (raw)
In-Reply-To: <AANLkTi=rp=WZa7PP4V6anU0SQ3BM-RJQwiDu1fJuoDig@mail.gmail.com>
> > diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
> > index 159a076..cc5a8fd 100644
> > --- a/include/linux/memcontrol.h
> > +++ b/include/linux/memcontrol.h
> > @@ -93,7 +93,7 @@ extern int
> > A mem_cgroup_prepare_migration(struct page *page,
> > A A A A struct page *newpage, struct mem_cgroup **ptr);
> > A extern void mem_cgroup_end_migration(struct mem_cgroup *mem,
> > - A A A struct page *oldpage, struct page *newpage);
> > + A A A struct page *oldpage, struct page *newpage, bool success);
>
> The term "success" implies present or future tense.
> The event this variable cares about in the past so "succeed" might be
> a more appropriate term.
> Sorry to be picky about the English but there is an important
> distinction here since we don't have any comment about the variable.
>
> Am I being too fussy?
Not at all. Your comments are very helpful to make the code more readable :)
===
From: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
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.
Signed-off-by: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>
Reviewed-by: Minchan Kim <minchan.kim@gmail.com>
Acked-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
---
v2->v3
- s/success/succeed
v1->v2
- pass mem_cgroup_end_migration() "bool" instead of "int".
include/linux/memcontrol.h | 5 ++---
mm/memcontrol.c | 5 ++---
mm/migrate.c | 2 +-
3 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h
index 159a076..9f52b57 100644
--- a/include/linux/memcontrol.h
+++ b/include/linux/memcontrol.h
@@ -93,7 +93,7 @@ extern int
mem_cgroup_prepare_migration(struct page *page,
struct page *newpage, struct mem_cgroup **ptr);
extern void mem_cgroup_end_migration(struct mem_cgroup *mem,
- struct page *oldpage, struct page *newpage);
+ struct page *oldpage, struct page *newpage, bool succeed);
/*
* For memory reclaim.
@@ -231,8 +231,7 @@ mem_cgroup_prepare_migration(struct page *page, struct page *newpage,
}
static inline void mem_cgroup_end_migration(struct mem_cgroup *mem,
- struct page *oldpage,
- struct page *newpage)
+ struct page *oldpage, struct page *newpage, bool succeed)
{
}
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 61678be..71a39bc 100644
--- 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, bool succeed)
{
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 (!succeed) {
used = oldpage;
unused = newpage;
} else {
diff --git a/mm/migrate.c b/mm/migrate.c
index 6ae8a66..be66b23 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -756,7 +756,7 @@ rcu_unlock:
rcu_read_unlock();
uncharge:
if (!charge)
- mem_cgroup_end_migration(mem, page, newpage);
+ mem_cgroup_end_migration(mem, page, newpage, rc == 0);
unlock:
unlock_page(page);
--
1.7.1
--
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-06 3:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-01-05 4:00 [BUGFIX][PATCH] " Daisuke Nishimura
2011-01-05 4:48 ` Minchan Kim
2011-01-05 6:47 ` Daisuke Nishimura
2011-01-05 7:18 ` Minchan Kim
2011-01-06 0:52 ` KAMEZAWA Hiroyuki
2011-01-06 2:51 ` Minchan Kim
2011-01-05 11:58 ` Johannes Weiner
2011-01-06 1:09 ` Daisuke Nishimura
2011-01-06 1:55 ` KAMEZAWA Hiroyuki
2011-01-06 2:49 ` Minchan Kim
2011-01-06 3:34 ` Daisuke Nishimura [this message]
2011-01-06 5:42 ` [BUGFIX][PATCH v3] " Balbir Singh
2011-01-06 6:29 ` [BUGFIX][PATCH v4] " Daisuke Nishimura
2011-01-08 9:26 ` Johannes Weiner
2011-01-10 9:05 ` Balbir Singh
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=20110106123415.895d6dfc.nishimura@mxp.nes.nec.co.jp \
--to=nishimura@mxp.nes.nec.co.jp \
--cc=akpm@linux-foundation.org \
--cc=balbir@linux.vnet.ibm.com \
--cc=hannes@cmpxchg.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan.kim@gmail.com \
/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