From: David Rientjes <rientjes@google.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@suse.cz>,
Balbir Singh <bsingharora@gmail.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
cgroups@vger.kernel.org, linux-mm@kvack.org
Subject: [patch] mm, memcg: do not allow tasks to be attached with zero limit
Date: Wed, 7 Mar 2012 19:14:49 -0800 (PST) [thread overview]
Message-ID: <alpine.DEB.2.00.1203071914150.15244@chino.kir.corp.google.com> (raw)
This patch prevents tasks from being attached to a memcg if there is a
hard limit of zero. Additionally, the hard limit may not be changed to
zero if there are tasks attached.
This is consistent with cpusets which do not allow tasks to be attached
if there are no mems and prevents all mems from being removed if there
are tasks attached.
Signed-off-by: David Rientjes <rientjes@google.com>
---
mm/memcontrol.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/mm/memcontrol.c b/mm/memcontrol.c
--- a/mm/memcontrol.c
+++ b/mm/memcontrol.c
@@ -3868,9 +3868,14 @@ static int mem_cgroup_write(struct cgroup *cont, struct cftype *cft,
ret = res_counter_memparse_write_strategy(buffer, &val);
if (ret)
break;
- if (type == _MEM)
+ if (type == _MEM) {
+ /* Don't allow zero limit with tasks attached */
+ if (!val && cgroup_task_count(cont)) {
+ ret = -ENOSPC;
+ break;
+ }
ret = mem_cgroup_resize_limit(memcg, val);
- else
+ } else
ret = mem_cgroup_resize_memsw_limit(memcg, val);
break;
case RES_SOFT_LIMIT:
@@ -5306,6 +5311,10 @@ static int mem_cgroup_can_attach(struct cgroup_subsys *ss,
int ret = 0;
struct mem_cgroup *memcg = mem_cgroup_from_cont(cgroup);
+ /* Don't allow tasks attached with a zero limit */
+ if (!res_counter_read_u64(&memcg->res, RES_LIMIT))
+ return -ENOSPC;
+
if (memcg->move_charge_at_immigrate) {
struct mm_struct *mm;
struct mem_cgroup *from = mem_cgroup_from_task(p);
--
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 internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next reply other threads:[~2012-03-08 3:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-08 3:14 David Rientjes [this message]
2012-03-08 6:15 ` KAMEZAWA Hiroyuki
2012-03-08 20:29 ` Andrew Morton
2012-03-09 1:22 ` KAMEZAWA Hiroyuki
2012-03-09 1:38 ` Andrew Morton
2012-03-09 1:57 ` KAMEZAWA Hiroyuki
2012-03-13 16:51 ` Johannes Weiner
2012-03-14 9:42 ` 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=alpine.DEB.2.00.1203071914150.15244@chino.kir.corp.google.com \
--to=rientjes@google.com \
--cc=akpm@linux-foundation.org \
--cc=bsingharora@gmail.com \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--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