[patch] mm, memcg: do not allow tasks to be attached with zero limit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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 from this list: send the line "unsubscribe cgroups" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [Monitors]

  Powered by Linux