From: Li Zefan <lizf@cn.fujitsu.com>
To: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
Balbir Singh <balbir@linux.vnet.ibm.com>,
Paul Menage <menage@google.com>
Cc: Daisuke Nishimura <nishimura@mxp.nes.nec.co.jp>,
Linux Containers <containers@lists.linux-foundation.org>,
"linux-mm@kvack.org" <linux-mm@kvack.org>
Subject: [RFC][PATCH] memcg: fix a race when setting memcg.swappiness
Date: Wed, 14 Jan 2009 11:24:18 +0800 [thread overview]
Message-ID: <496D5AE2.2020403@cn.fujitsu.com> (raw)
(suppose: memcg->use_hierarchy == 0 and memcg->swappiness == 60)
echo 10 > /memcg/0/swappiness |
mem_cgroup_swappiness_write() |
... | echo 1 > /memcg/0/use_hierarchy
| mkdir /mnt/0/1
| sub_memcg->swappiness = 60;
memcg->swappiness = 10; |
In the above scenario, we end up having 2 different swappiness
values in a single hierarchy.
Note we can't use hierarchy_lock here, because it doesn't protect
the create() method.
Though IMO use cgroup_lock() in simple write functions is OK,
Paul would like to avoid it. And he sugguested use a counter to
count the number of children instead of check cgrp->children list:
=================
create() does:
lock memcg_parent
memcg->swappiness = memcg->parent->swappiness;
memcg_parent->child_count++;
unlock memcg_parent
and write() does:
lock memcg
if (!memcg->child_count) {
memcg->swappiness = swappiness;
} else {
report error;
}
unlock memcg
destroy() does:
lock memcg_parent
memcg_parent->child_count--;
unlock memcg_parent
=================
And there is a suble differnce with checking cgrp->children,
that a cgroup is removed from parent's list in cgroup_rmdir(),
while memcg->child_count is decremented in cgroup_diput().
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
mm/memcontrol.c | 10 +++++++++-
1 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
index e2996b8..0274223 100644
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -1971,6 +1971,7 @@ static int mem_cgroup_swappiness_write(struct cgroup *cgrp, struct cftype *cft,
{
struct mem_cgroup *memcg = mem_cgroup_from_cont(cgrp);
struct mem_cgroup *parent;
+
if (val > 100)
return -EINVAL;
@@ -1978,15 +1979,22 @@ static int mem_cgroup_swappiness_write(struct cgroup *cgrp, struct cftype *cft,
return -EINVAL;
parent = mem_cgroup_from_cont(cgrp->parent);
+
+ cgroup_lock();
+
/* If under hierarchy, only empty-root can set this value */
if ((parent->use_hierarchy) ||
- (memcg->use_hierarchy && !list_empty(&cgrp->children)))
+ (memcg->use_hierarchy && !list_empty(&cgrp->children))) {
+ cgroup_unlock();
return -EINVAL;
+ }
spin_lock(&memcg->reclaim_param_lock);
memcg->swappiness = val;
spin_unlock(&memcg->reclaim_param_lock);
+ cgroup_unlock();
+
return 0;
}
--
1.5.4.rc3
--
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 reply other threads:[~2009-01-14 3:25 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-14 3:24 Li Zefan [this message]
[not found] ` <496D5AE2.2020403-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-01-14 4:26 ` [RFC][PATCH] memcg: fix a race when setting memcg.swappiness KAMEZAWA Hiroyuki
2009-01-14 4:26 ` KAMEZAWA Hiroyuki
2009-01-14 6:47 ` Li Zefan
[not found] ` <496D8A76.9040509-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-01-14 7:05 ` KAMEZAWA Hiroyuki
2009-01-14 7:05 ` KAMEZAWA Hiroyuki
[not found] ` <20090114160551.143d7980.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-01-14 7:22 ` Li Zefan
2009-01-14 7:22 ` Li Zefan
2009-01-14 7:29 ` KAMEZAWA Hiroyuki
[not found] ` <496D929E.9040408-BthXqXjhjHXQFUHtdCDX3A@public.gmane.org>
2009-01-14 7:29 ` KAMEZAWA Hiroyuki
[not found] ` <20090114132616.3cb7d568.kamezawa.hiroyu-+CUm20s59erQFUHtdCDX3A@public.gmane.org>
2009-01-14 6:47 ` Li Zefan
-- strict thread matches above, loose matches on Subject: below --
2009-01-14 3:24 Li Zefan
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=496D5AE2.2020403@cn.fujitsu.com \
--to=lizf@cn.fujitsu.com \
--cc=balbir@linux.vnet.ibm.com \
--cc=containers@lists.linux-foundation.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-mm@kvack.org \
--cc=menage@google.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 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.