From: Kamezawa Hiroyuki <kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
To: Sha Zhengju <handai.szj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org,
mhocko-AlSwsSmVLrQ@public.gmane.org,
akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org,
hughd-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org,
Sha Zhengju <handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
Subject: Re: [PATCH V2 0/3] memcg: simply lock of page stat accounting
Date: Tue, 14 May 2013 09:41:42 +0900 [thread overview]
Message-ID: <51918846.7090006@jp.fujitsu.com> (raw)
In-Reply-To: <1368421410-4795-1-git-send-email-handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
If you want to rewrite all things and make memcg cleaner, I don't stop it.
But, how about starting with this simeple one for your 1st purpose ?
doesn't work ? dirty ?
== this patch is untested. ==
From 95e405451f56933c4777e64bb02326ec0462f7a7 Mon Sep 17 00:00:00 2001
From: KAMEZAWA Hiroyuki <kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
Date: Tue, 14 May 2013 09:40:55 +0900
Subject: [PATCH] Allow nesting lock of memcg's page stat accouting.
Sha Zhengju and Michal Hocko pointed out that
mem_cgroup_begin/end_update_page_stat() should be nested lock.
https://lkml.org/lkml/2013/1/2/48
page_remove_rmap
mem_cgroup_begin_update_page_stat <<< 1
set_page_dirty
__set_page_dirty_buffers
__set_page_dirty
mem_cgroup_begin_update_page_stat <<< 2
move_lock_mem_cgroup
spin_lock_irqsave(&memcg->move_lock, *flags);
This patch add a nesting functionality with per-thread counter.
Signed-off-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
---
include/linux/sched.h | 1 +
mm/memcontrol.c | 22 +++++++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 84ceef5..cca3229 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1402,6 +1402,7 @@ struct task_struct {
unsigned long memsw_nr_pages; /* uncharged mem+swap usage */
} memcg_batch;
unsigned int memcg_kmem_skip_account;
+ unsigned int memcg_page_stat_accounting;
#endif
#ifdef CONFIG_HAVE_HW_BREAKPOINT
atomic_t ptrace_bp_refcnt;
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index 357371a..152f8df 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -2352,12 +2352,30 @@ again:
*/
if (!mem_cgroup_stolen(memcg))
return;
+ /*
+ * In some case, we need nested lock of this.
+ * page_remove_rmap
+ * mem_cgroup_begin_update_page_stat <<< 1
+ * set_page_dirty
+ * __set_page_dirty_buffers
+ * __set_page_dirty
+ * mem_cgroup_begin_update_page_stat <<< 2
+ * move_lock_mem_cgroup
+ * spin_lock_irqsave(&memcg->move_lock, *flags);
+ *
+ * We avoid this deadlock by having per thread counter.
+ */
+ if (current->memcg_page_stat_accounting > 0) {
+ current->memcg_page_stat_accounting++;
+ return;
+ }
move_lock_mem_cgroup(memcg, flags);
if (memcg != pc->mem_cgroup || !PageCgroupUsed(pc)) {
move_unlock_mem_cgroup(memcg, flags);
goto again;
}
+ current->memcg_page_stat_accounting = 1;
*locked = true;
}
@@ -2370,7 +2388,9 @@ void __mem_cgroup_end_update_page_stat(struct page *page, unsigned long *flags)
* lock is held because a routine modifies pc->mem_cgroup
* should take move_lock_mem_cgroup().
*/
- move_unlock_mem_cgroup(pc->mem_cgroup, flags);
+ current->memcg_page_stat_accounting--;
+ if (!current->memcg_page_stat_accounting)
+ move_unlock_mem_cgroup(pc->mem_cgroup, flags);
}
void mem_cgroup_update_page_stat(struct page *page,
--
1.7.4.1
WARNING: multiple messages have this Message-ID (diff)
From: Kamezawa Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
To: Sha Zhengju <handai.szj@gmail.com>
Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, mhocko@suse.cz,
akpm@linux-foundation.org, hughd@google.com, gthelen@google.com,
Sha Zhengju <handai.szj@taobao.com>
Subject: Re: [PATCH V2 0/3] memcg: simply lock of page stat accounting
Date: Tue, 14 May 2013 09:41:42 +0900 [thread overview]
Message-ID: <51918846.7090006@jp.fujitsu.com> (raw)
In-Reply-To: <1368421410-4795-1-git-send-email-handai.szj@taobao.com>
If you want to rewrite all things and make memcg cleaner, I don't stop it.
But, how about starting with this simeple one for your 1st purpose ?
doesn't work ? dirty ?
== this patch is untested. ==
next prev parent reply other threads:[~2013-05-14 0:41 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-13 5:03 [PATCH V2 0/3] memcg: simply lock of page stat accounting Sha Zhengju
2013-05-13 5:03 ` Sha Zhengju
2013-05-13 5:04 ` [PATCH V2 1/3] memcg: rewrite the comment about race condition " Sha Zhengju
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
[not found] ` <1368421524-4937-1-git-send-email-handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
2013-05-14 0:15 ` Kamezawa Hiroyuki
2013-05-14 0:15 ` Kamezawa Hiroyuki
[not found] ` <51918221.6090402-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2013-05-14 9:03 ` Sha Zhengju
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
[not found] ` <20130513131251.GB5246-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-05-13 13:38 ` Michal Hocko
2013-05-13 13:38 ` Michal Hocko
[not found] ` <20130513133809.GC5246-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-05-14 9:13 ` Sha Zhengju
2013-05-14 9:13 ` Sha Zhengju
[not found] ` <CAFj3OHW=FCGu6rhChLV2HgUFSRxDur4e8bmugXnq++c-P8mNRg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2013-05-14 9:28 ` Michal Hocko
2013-05-14 9:28 ` Michal Hocko
2013-05-14 8:35 ` Sha Zhengju
[not found] ` <1368421410-4795-1-git-send-email-handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org>
2013-05-14 0:41 ` Kamezawa Hiroyuki [this message]
2013-05-14 0:41 ` [PATCH V2 0/3] memcg: simply lock of page stat accounting Kamezawa Hiroyuki
[not found] ` <51918846.7090006-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2013-05-14 7:13 ` Michal Hocko
2013-05-14 7:13 ` Michal Hocko
2013-05-15 12:35 ` Konstantin Khlebnikov
[not found] ` <519380FC.1040504-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2013-05-15 13:41 ` Michal Hocko
2013-05-15 13:41 ` Michal Hocko
2013-05-16 4:28 ` Konstantin Khlebnikov
[not found] ` <51946071.4030101-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2013-05-16 13:28 ` Michal Hocko
2013-05-16 13:28 ` Michal Hocko
2013-05-17 5:57 ` Konstantin Khlebnikov
2013-05-17 8:38 ` Michal Hocko
[not found] ` <20130517083806.GB5048-2MMpYkNvuYDjFM9bn6wA6Q@public.gmane.org>
2013-05-17 10:29 ` Konstantin Khlebnikov
2013-05-17 10:29 ` Konstantin Khlebnikov
[not found] ` <5196068D.2050608-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2013-05-17 12:53 ` Michal Hocko
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=51918846.7090006@jp.fujitsu.com \
--to=kamezawa.hiroyu-+cum20s59erqfuhtdcdx3a@public.gmane.org \
--cc=akpm-de/tnXTf+JLsfHDXvbKv3WD2FQJk+8+b@public.gmane.org \
--cc=cgroups-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=gthelen-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=handai.szj-3b8fjiQLQpfQT0dZR+AlfA@public.gmane.org \
--cc=handai.szj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=hughd-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org \
--cc=linux-mm-Bw31MaZKKs3YtjvyW6yDsg@public.gmane.org \
--cc=mhocko-AlSwsSmVLrQ@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.