From: Sha Zhengju <handai.szj@gmail.com>
To: cgroups@vger.kernel.org, linux-mm@kvack.org
Cc: mhocko@suse.cz, kamezawa.hiroyu@jp.fujitsu.com,
akpm@linux-foundation.org, hughd@google.com, gthelen@google.com,
Sha Zhengju <handai.szj@taobao.com>
Subject: [PATCH V2 1/3] memcg: rewrite the comment about race condition of page stat accounting
Date: Mon, 13 May 2013 13:04:51 +0800 [thread overview]
Message-ID: <1368421491-4897-1-git-send-email-handai.szj@taobao.com> (raw)
In-Reply-To: <1368421410-4795-1-git-send-email-handai.szj@taobao.com>
From: Sha Zhengju <handai.szj@taobao.com>
While doing memcg page stat accounting, we need to access page_cgroup
members including pc->mem_cgroup and pc->flags, so there are 3 candidates
which have potential race conditions with it: move account, charge, uncharge.
But page stat and uncharge can also take it easy because the former is done
before the page is deleted from radix-tree and the later is after the delete,
so they will be serialized by some other locks(like page lock).
So the races among them will be solved by:
stat move charge uncharge
stat X move lock no race no race
move X lock_page_cgroup lock_page_cgroup
charge X lock_page_cgroup
uncharge X
Signed-off-by: Sha Zhengju <handai.szj@taobao.com>
---
mm/memcontrol.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index fe4f123..b31513e 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2317,9 +2317,10 @@ static bool mem_cgroup_handle_oom(struct mem_cgroup *memcg, gfp_t mask,
* are no race with "charge".
*
* Considering "uncharge", we know that memcg doesn't clear pc->mem_cgroup
- * at "uncharge" intentionally. So, we always see valid pc->mem_cgroup even
- * if there are race with "uncharge". Statistics itself is properly handled
- * by flags.
+ * at "uncharge" intentionally but clear PageCgroupUsed flag for that page.
+ * Besides, the file-stat operations happen before a page is deleted from
+ * radix-tree while uncharge is after the delete. So there are no race with
+ * "uncharge" too.
*
* Considering "move", this is an only case we see a race. To make the race
* small, we check mm->moving_account and detect there are possibility of race
--
1.7.9.5
--
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/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2013-05-13 5:05 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-13 5:03 [PATCH V2 0/3] memcg: simply lock " Sha Zhengju
2013-05-13 5:04 ` Sha Zhengju [this message]
2013-05-13 5:05 ` [PATCH V2 2/3] memcg: alter mem_cgroup_{update,inc,dec}_page_stat() args to memcg pointer Sha Zhengju
2013-05-13 12:25 ` Michal Hocko
2013-05-14 9:00 ` Sha Zhengju
2013-05-14 9:10 ` Michal Hocko
2013-05-14 0:15 ` Kamezawa Hiroyuki
2013-05-14 9:03 ` Sha Zhengju
2013-05-13 5:05 ` [PATCH V2 3/3] memcg: simplify lock of memcg page stat account Sha Zhengju
2013-05-13 13:12 ` Michal Hocko
2013-05-13 13:38 ` Michal Hocko
2013-05-14 9:13 ` Sha Zhengju
2013-05-14 9:28 ` Michal Hocko
2013-05-14 8:35 ` Sha Zhengju
2013-05-14 0:41 ` [PATCH V2 0/3] memcg: simply lock of page stat accounting Kamezawa Hiroyuki
2013-05-14 7:13 ` Michal Hocko
2013-05-15 12:35 ` Konstantin Khlebnikov
2013-05-15 13:41 ` Michal Hocko
2013-05-16 4:28 ` Konstantin Khlebnikov
2013-05-16 13:28 ` Michal Hocko
2013-05-17 5:57 ` Konstantin Khlebnikov
2013-05-17 8:38 ` Michal Hocko
2013-05-17 10:29 ` Konstantin Khlebnikov
2013-05-17 12:53 ` Michal Hocko
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=1368421491-4897-1-git-send-email-handai.szj@taobao.com \
--to=handai.szj@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=gthelen@google.com \
--cc=handai.szj@taobao.com \
--cc=hughd@google.com \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=mhocko@suse.cz \
/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