Skip to contentSkip to conversation

cpuset: Enforce that a child's cpus must be a subset of the parent

PATCH In review Waiman Long 5 participants 15 messages May 30, 2018 – Jun 6, 2018

Subsystems (3)
lore
Share & tools
lore

Waiman Long

author maintainer
#0 lore raw

PATCH 1/1 cpuset: Enforce that a child's cpus must be a subset of the parent

It was found that the cpuset.cpus could contain CPUs that are not listed in their parent's cpu list as shown by the command sequence below:

  # echo "+cpuset" >cgroup.subtree_control
  # mkdir g1
  # echo 0-5 >g1/cpuset.cpus
  # mkdir g1/g11
  # echo "+cpuset" > g1/cgroup.subtree_control
  # echo 6-11 >g1/g11/cpuset.cpus
  # grep -R . g1 | grep "\.cpus"
  g1/cpuset.cpus:0-5
  g1/cpuset.cpus.effective:0-5
  g1/g11/cpuset.cpus:6-11
  g1/g11/cpuset.cpus.effective:0-5

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

---
 kernel/cgroup/cpuset.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
kernel/cgroup/cpuset.c +6 -1
index 71fb2d0..ceec438 100644
@@ -1185,12 +1185,17 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
 	if (!*buf) {
 		cpumask_clear(trialcs->cpus_allowed);
 	} else {
+		struct cpuset *parent = parent_cs(cs);
+
 		retval = cpulist_parse(buf, trialcs->cpus_allowed);
 		if (retval < 0)
 			return retval;
 
+		/*
+		 * The cpu list must be a subset of the parent.
+		 */
 		if (!cpumask_subset(trialcs->cpus_allowed,
-				    top_cpuset.cpus_allowed))
+				    parent->cpus_allowed))
 			return -EINVAL;
 	}
 
Signature · 1 line
1.8.3.1
#1 lore raw

Hi,

Quoted 15 lines · Waiman Long

It was found that the cpuset.cpus could contain CPUs that are not listed in their parent's cpu list as shown by the command sequence below:

  # echo "+cpuset" >cgroup.subtree_control
  # mkdir g1
  # echo 0-5 >g1/cpuset.cpus
  # mkdir g1/g11
  # echo "+cpuset" > g1/cgroup.subtree_control
  # echo 6-11 >g1/g11/cpuset.cpus
  # grep -R . g1 | grep "\.cpus"
  g1/cpuset.cpus:0-5
  g1/cpuset.cpus.effective:0-5
  g1/g11/cpuset.cpus:6-11
  g1/g11/cpuset.cpus.effective:0-5
Quoted 8 lines

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

Looks like it fixes the bug.

Reviewed-and-Tested-by Juri Lelli <[email protected]>

Thanks,

- Juri

#2 lore raw
In reply to Waiman Long

Hi Waiman,

Quoted 15 lines · Waiman Long

It was found that the cpuset.cpus could contain CPUs that are not listed in their parent's cpu list as shown by the command sequence below:

  # echo "+cpuset" >cgroup.subtree_control
  # mkdir g1
  # echo 0-5 >g1/cpuset.cpus
  # mkdir g1/g11
  # echo "+cpuset" > g1/cgroup.subtree_control
  # echo 6-11 >g1/g11/cpuset.cpus
  # grep -R . g1 | grep "\.cpus"
  g1/cpuset.cpus:0-5
  g1/cpuset.cpus.effective:0-5
  g1/g11/cpuset.cpus:6-11
  g1/g11/cpuset.cpus.effective:0-5
Quoted 6 lines

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

We made the distinction between user-configured CPUs and effective CPUs in commit 7e88291beefbb758, so actually it's not a bug.

#3 lore raw
Quoted 25 lines · Zefan Li

Hi Waiman,

Quoted 15 lines · Waiman Long

It was found that the cpuset.cpus could contain CPUs that are not listed in their parent's cpu list as shown by the command sequence below:

  # echo "+cpuset" >cgroup.subtree_control
  # mkdir g1
  # echo 0-5 >g1/cpuset.cpus
  # mkdir g1/g11
  # echo "+cpuset" > g1/cgroup.subtree_control
  # echo 6-11 >g1/g11/cpuset.cpus
  # grep -R . g1 | grep "\.cpus"
  g1/cpuset.cpus:0-5
  g1/cpuset.cpus.effective:0-5
  g1/g11/cpuset.cpus:6-11
  g1/g11/cpuset.cpus.effective:0-5
Quoted 6 lines

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

Quoted 2 lines

We made the distinction between user-configured CPUs and effective CPUs in commit 7e88291beefbb758, so actually it's not a bug.

Why though; that makes no sense what so ever.

#4 lore raw
In reply to Zefan Li
Quoted 25 lines · Zefan Li

Hi Waiman,

Quoted 15 lines · Waiman Long

It was found that the cpuset.cpus could contain CPUs that are not listed in their parent's cpu list as shown by the command sequence below:

  # echo "+cpuset" >cgroup.subtree_control
  # mkdir g1
  # echo 0-5 >g1/cpuset.cpus
  # mkdir g1/g11
  # echo "+cpuset" > g1/cgroup.subtree_control
  # echo 6-11 >g1/g11/cpuset.cpus
  # grep -R . g1 | grep "\.cpus"
  g1/cpuset.cpus:0-5
  g1/cpuset.cpus.effective:0-5
  g1/g11/cpuset.cpus:6-11
  g1/g11/cpuset.cpus.effective:0-5
Quoted 6 lines

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

Quoted 3 lines

We made the distinction between user-configured CPUs and effective CPUs in commit 7e88291beefbb758, so actually it's not a bug.

I remember the original reason is to support restoration of the original cpu after cpu offline->online. We use user-configured CPUs to remember if the cpu should be restored in the cpuset after it's onlined.

#5 lore raw
Quoted 26 lines · Zefan Li
Quoted 25 lines · Zefan Li

Hi Waiman,

Quoted 21 lines · Waiman Long

It was found that the cpuset.cpus could contain CPUs that are not listed in their parent's cpu list as shown by the command sequence below:

  # echo "+cpuset" >cgroup.subtree_control
  # mkdir g1
  # echo 0-5 >g1/cpuset.cpus
  # mkdir g1/g11
  # echo "+cpuset" > g1/cgroup.subtree_control
  # echo 6-11 >g1/g11/cpuset.cpus
  # grep -R . g1 | grep "\.cpus"
  g1/cpuset.cpus:0-5
  g1/cpuset.cpus.effective:0-5
  g1/g11/cpuset.cpus:6-11
  g1/g11/cpuset.cpus.effective:0-5

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

Quoted 7 lines
Quoted 3 lines

We made the distinction between user-configured CPUs and effective CPUs in commit 7e88291beefbb758, so actually it's not a bug.

I remember the original reason is to support restoration of the original cpu after cpu offline->online. We use user-configured CPUs to remember if the cpu should be restored in the cpuset after it's onlined.

AFAICT you can do that and still have the child a subset of the parent, no?

#6 lore raw
Quoted 31 lines · Peter Zijlstra
Quoted 30 lines · Zefan Li
Quoted 28 lines · Zefan Li

Hi Waiman,

Quoted 15 lines · Waiman Long

It was found that the cpuset.cpus could contain CPUs that are not listed in their parent's cpu list as shown by the command sequence below:

  # echo "+cpuset" >cgroup.subtree_control
  # mkdir g1
  # echo 0-5 >g1/cpuset.cpus
  # mkdir g1/g11
  # echo "+cpuset" > g1/cgroup.subtree_control
  # echo 6-11 >g1/g11/cpuset.cpus
  # grep -R . g1 | grep "\.cpus"
  g1/cpuset.cpus:0-5
  g1/cpuset.cpus.effective:0-5
  g1/g11/cpuset.cpus:6-11
  g1/g11/cpuset.cpus.effective:0-5
Quoted 6 lines

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

We made the distinction between user-configured CPUs and effective CPUs in commit 7e88291beefbb758, so actually it's not a bug.

Quoted 6 lines
Quoted 3 lines

I remember the original reason is to support restoration of the original cpu after cpu offline->online. We use user-configured CPUs to remember if the cpu should be restored in the cpuset after it's onlined.

AFAICT you can do that and still have the child a subset of the parent, no?

Plus this is not hotplug, but a user decision. It could make sense to keep .cpus unmodified after hotplug events, but does it make sense to let the user be able to choose cpus outside the parent domain?

#7 lore raw
In reply to Peter Zijlstra
Quoted 31 lines · Peter Zijlstra
Quoted 30 lines · Zefan Li
Quoted 28 lines · Zefan Li

Hi Waiman,

Quoted 15 lines · Waiman Long

It was found that the cpuset.cpus could contain CPUs that are not listed in their parent's cpu list as shown by the command sequence below:

  # echo "+cpuset" >cgroup.subtree_control
  # mkdir g1
  # echo 0-5 >g1/cpuset.cpus
  # mkdir g1/g11
  # echo "+cpuset" > g1/cgroup.subtree_control
  # echo 6-11 >g1/g11/cpuset.cpus
  # grep -R . g1 | grep "\.cpus"
  g1/cpuset.cpus:0-5
  g1/cpuset.cpus.effective:0-5
  g1/g11/cpuset.cpus:6-11
  g1/g11/cpuset.cpus.effective:0-5
Quoted 6 lines

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

We made the distinction between user-configured CPUs and effective CPUs in commit 7e88291beefbb758, so actually it's not a bug.

Quoted 7 lines
Quoted 3 lines

I remember the original reason is to support restoration of the original cpu after cpu offline->online. We use user-configured CPUs to remember if the cpu should be restored in the cpuset after it's onlined.

AFAICT you can do that and still have the child a subset of the parent, no?
.

Sure. IIRC this was suggested by Tejun as he had done something similar to devcgroup.

author maintainer
#8 lore raw
Quoted 30 lines · Zefan Li
Quoted 29 lines · Peter Zijlstra
Quoted 28 lines · Zefan Li
Quoted 27 lines · Zefan Li

Hi Waiman,

Quoted 15 lines · Waiman Long

It was found that the cpuset.cpus could contain CPUs that are not listed in their parent's cpu list as shown by the command sequence below:

  # echo "+cpuset" >cgroup.subtree_control
  # mkdir g1
  # echo 0-5 >g1/cpuset.cpus
  # mkdir g1/g11
  # echo "+cpuset" > g1/cgroup.subtree_control
  # echo 6-11 >g1/g11/cpuset.cpus
  # grep -R . g1 | grep "\.cpus"
  g1/cpuset.cpus:0-5
  g1/cpuset.cpus.effective:0-5
  g1/g11/cpuset.cpus:6-11
  g1/g11/cpuset.cpus.effective:0-5
Quoted 6 lines

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

We made the distinction between user-configured CPUs and effective CPUs in commit 7e88291beefbb758, so actually it's not a bug.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I remember the original reason is to support restoration of the original cpu after cpu offline->online. We use user-configured CPUs to remember if the cpu should be restored in the cpuset after it's onlined.

AFAICT you can do that and still have the child a subset of the parent, no?
.

Sure. IIRC this was suggested by Tejun as he had done something similar to devcgroup.

OK, let wait until Tejun has time to chime in. For me, it just look weird to be able to do that.

Another corner case that is not handled is when cpus_allowed is empty. In this case, it falls back to the parent's effective cpus. On the other hand, it can also be argued that an empty cpus_allowed is a transient state and a cpuset shouldn't have cpus undefined while creating children.

Cheers,
Longman

maintainer
#9 lore raw

Hello,

Quoted 17 lines · Waiman Long
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

We made the distinction between user-configured CPUs and effective CPUs in commit 7e88291beefbb758, so actually it's not a bug.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I remember the original reason is to support restoration of the original cpu after cpu offline->online. We use user-configured CPUs to remember if the cpu should be restored in the cpuset after it's onlined.

AFAICT you can do that and still have the child a subset of the parent, no?
.

Sure. IIRC this was suggested by Tejun as he had done something similar to devcgroup.

Quoted 7 lines

OK, let wait until Tejun has time to chime in. For me, it just look weird to be able to do that.

Another corner case that is not handled is when cpus_allowed is empty. In this case, it falls back to the parent's effective cpus. On the other hand, it can also be argued that an empty cpus_allowed is a transient state and a cpuset shouldn't have cpus undefined while creating children.

Tying together what's configured and what's applied may feel attractive on the surface but it's a long term headache.

* It's inconsistent with what other controllers are doing. All the limit resource configs declare the upper bound the specific cgroup can consume regardless of what's actually available to it. They limit but don't guarantee access.

* Which decouples a given cgroup's configurations from its ancestors', which allows an ancestor to take away resources that it granted before and then also giving it back later. No matter what you do, if you couple configs of cgroup hierarchy, you end up restricting what an ancestor can do to its sub-hierarchy, which can quickly become a difficult operational headache.

So, let's please stay away from it even if that means a bit of overhead in terms of interface.

Thanks.

Signature · 1 line
tejun
#10 lore raw
Quoted 15 lines · Tejun Heo

Tying together what's configured and what's applied may feel attractive on the surface but it's a long term headache.

* It's inconsistent with what other controllers are doing. All the limit resource configs declare the upper bound the specific cgroup can consume regardless of what's actually available to it. They limit but don't guarantee access.

* Which decouples a given cgroup's configurations from its ancestors', which allows an ancestor to take away resources that it granted before and then also giving it back later. No matter what you do, if you couple configs of cgroup hierarchy, you end up restricting what an ancestor can do to its sub-hierarchy, which can quickly become a difficult operational headache.

Quoted 2 lines

So, let's please stay away from it even if that means a bit of overhead in terms of interface.

Urgh, that again :/

I'm still not convinced by your arguments though. The root container can access all the sub-groups anyway and can grub around in them to take away resources if it really wants to.

For cpuset in particular randomly restricting on the ancestor level can create an unrecoverable trainwreck inside a container. Affinities are not recoverable. Once a runnable task ends up with an empty set, its affinities are reset and the smaller (empty) set is lost.

maintainer
#11 lore raw

Hello,

Quoted 4 lines · Peter Zijlstra
Quoted 2 lines

So, let's please stay away from it even if that means a bit of overhead in terms of interface.

Urgh, that again :/

Yeah, well, it's pretty important.

Quoted 3 lines

I'm still not convinced by your arguments though. The root container can access all the sub-groups anyway and can grub around in them to take away resources if it really wants to.

That's really messy and if you delegated away a subtree, you can't walk the subtree in a race free way, not easily anyway.

Quoted 4 lines

For cpuset in particular randomly restricting on the ancestor level can create an unrecoverable trainwreck inside a container. Affinities are not recoverable. Once a runnable task ends up with an empty set, its affinities are reset and the smaller (empty) set is lost.

Yeah, for cpuset, it's messier, but it isn't different from hotunplug scenario, right? I think the best we can do there is putting ancestor operation on an equal footing as hotplug ops.

Thanks.

Signature · 1 line
tejun
#12 lore raw
Quoted 8 lines · Tejun Heo

Hello,

Quoted 4 lines · Peter Zijlstra
Quoted 2 lines

So, let's please stay away from it even if that means a bit of overhead in terms of interface.

Urgh, that again :/

Quoted 8 lines

Yeah, well, it's pretty important.

Quoted 3 lines

I'm still not convinced by your arguments though. The root container can access all the sub-groups anyway and can grub around in them to take away resources if it really wants to.

That's really messy and if you delegated away a subtree, you can't walk the subtree in a race free way, not easily anyway.

Messy perhaps, but taking away resources you gave out earlier isn't particularly nice either way around.

Not sure the races matter, if you win, the delegate can't undo it, if you loose, you try again until you win.

It's not like cgroup stuff gets changed often, so a conflict causing you to loose should be very rare indeed.

Quoted 8 lines
Quoted 4 lines

For cpuset in particular randomly restricting on the ancestor level can create an unrecoverable trainwreck inside a container. Affinities are not recoverable. Once a runnable task ends up with an empty set, its affinities are reset and the smaller (empty) set is lost.

Yeah, for cpuset, it's messier, but it isn't different from hotunplug scenario, right? I think the best we can do there is putting ancestor operation on an equal footing as hotplug ops.

Right, but hotplug is exceedingly rare, while I get the impression you think it is perfectly fine to recind on your resource grants.

maintainer
#13 lore raw

Hello, Peter.

Sorry about late reply.

Quoted 6 lines · Peter Zijlstra
Quoted 3 lines

Yeah, for cpuset, it's messier, but it isn't different from hotunplug scenario, right? I think the best we can do there is putting ancestor operation on an equal footing as hotplug ops.

Right, but hotplug is exceedingly rare, while I get the impression you think it is perfectly fine to recind on your resource grants.

Well, yeah, for a trivial example, imagine dynamic workload management where you wanna restrict what a side-loaded batch workload can do on and off peak hours. All other controllers can do that. It'd be a really odd design trade-off if we make that really clumsy for cpuset especially given that we wouldn't be gaining any actual functionalities.

Thanks.

Signature · 1 line
tejun
author maintainer
#14 lore raw
In reply to Tejun Heo
Quoted 42 lines · Tejun Heo

Hello,

Quoted 17 lines · Waiman Long
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

As the intersection of g11's cpus and that of g1 is empty, the effective cpus of g11 is just that of g1. The check in update_cpumask() is now corrected to make sure that cpus in a child cpus must be a subset of its parent's cpus. The error "write error: Invalid argument" will now be reported in the above case.

We made the distinction between user-configured CPUs and effective CPUs in commit 7e88291beefbb758, so actually it's not a bug.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

I remember the original reason is to support restoration of the original cpu after cpu offline->online. We use user-configured CPUs to remember if the cpu should be restored in the cpuset after it's onlined.

AFAICT you can do that and still have the child a subset of the parent, no?
.

Sure. IIRC this was suggested by Tejun as he had done something similar to devcgroup.

Quoted 7 lines

OK, let wait until Tejun has time to chime in. For me, it just look weird to be able to do that.

Another corner case that is not handled is when cpus_allowed is empty. In this case, it falls back to the parent's effective cpus. On the other hand, it can also be argued that an empty cpus_allowed is a transient state and a cpuset shouldn't have cpus undefined while creating children.

Tying together what's configured and what's applied may feel attractive on the surface but it's a long term headache.

* It's inconsistent with what other controllers are doing. All the limit resource configs declare the upper bound the specific cgroup can consume regardless of what's actually available to it. They limit but don't guarantee access.

* Which decouples a given cgroup's configurations from its ancestors', which allows an ancestor to take away resources that it granted before and then also giving it back later. No matter what you do, if you couple configs of cgroup hierarchy, you end up restricting what an ancestor can do to its sub-hierarchy, which can quickly become a difficult operational headache.

Quoted 5 lines

So, let's please stay away from it even if that means a bit of overhead in terms of interface.

Thanks.

I am fine with that argument. I will update the patch documentation to include this information as I think it is important for the users to be aware of that.

Cheers,
Longman