linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Relax cpuset validation for cgroup v2
@ 2021-04-13  9:02 Odin Ugedal
  2021-04-13  9:02 ` [PATCH 1/2] cgroup2: cpuset: Disable subset validation on set Odin Ugedal
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Odin Ugedal @ 2021-04-13  9:02 UTC (permalink / raw)
  To: tj, lizefan.x; +Cc: cgroups, linux-kernel, Odin Ugedal

Two small validation relaxations for cgroup v2, making it easier to
manage the hierarchy without the current pain points. Both changes
work for both mems and cpus (but I have no NUMA machine to test mems).

Hopefully the patches has an ok description about what change they
provide, and why they are helpful.

Odin Ugedal (2):
  cgroup2: cpuset: Disable subset validation on set
  cgroup2: cpuset: Always allow setting empty cpuset

 kernel/cgroup/cpuset.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

-- 
2.31.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] cgroup2: cpuset: Disable subset validation on set
  2021-04-13  9:02 [PATCH 0/2] Relax cpuset validation for cgroup v2 Odin Ugedal
@ 2021-04-13  9:02 ` Odin Ugedal
  2021-04-13  9:02 ` [PATCH 2/2] cgroup2: cpuset: Always allow setting empty cpuset Odin Ugedal
  2021-04-13 11:10 ` [PATCH 0/2] Relax cpuset validation for cgroup v2 Tejun Heo
  2 siblings, 0 replies; 4+ messages in thread
From: Odin Ugedal @ 2021-04-13  9:02 UTC (permalink / raw)
  To: tj, lizefan.x; +Cc: cgroups, linux-kernel, Odin Ugedal

Due to how cpuset works in v2, there is no need to check if direct
children are subsets of the new cpuset. In v2, the effective cpuset
of a cgroup is the intersection between the effective value of the parent
and the cpuset.cpus value of the cgroup, with a fallback to the effective
parent value in case the intersection is an empty set.

Therefore, in v2, it is allowed to set cpuset.cpus to a a value that is
not a subset of the parents effective value, resulting in inheriting the
effective cpuset from the parent. Therefore the validation when updating
the parent cpuset (in this case) is not necessary, and can be disabled.

Example:

  /sys/fs/cgroup/A     (cpus=1-2,cpus.effective=1-2)
  /sys/fs/cgroup/A/B   (cpus="", cpus.effective=1-2)

  Setting cpus to 3-4 is possible for A/B

  /sys/fs/cgroup/A     (cpus=1-2,cpus.effective=1-2)
  /sys/fs/cgroup/A/B   (cpus=3-4,cpus.effective=1-2)

  Setting cpus to 1 for A would result in an -EBUSY error, but
  with this patch it will work as expected:

  /sys/fs/cgroup/A     (cpus=1,  cpus.effective=1)
  /sys/fs/cgroup/A/B   (cpus=3-4,cpus.effective=1)

This also applies in a similar manner on cpuset.mems.

Signed-off-by: Odin Ugedal <odin@uged.al>
---
 kernel/cgroup/cpuset.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 5258b68153e0..f543c4c6084a 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -572,11 +572,13 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial)
 
 	rcu_read_lock();
 
-	/* Each of our child cpusets must be a subset of us */
+	/* On legacy hierarchy, each of our child cpusets must be a subset of us */
 	ret = -EBUSY;
-	cpuset_for_each_child(c, css, cur)
-		if (!is_cpuset_subset(c, trial))
-			goto out;
+	if (!is_in_v2_mode()) {
+		cpuset_for_each_child(c, css, cur)
+			if (!is_cpuset_subset(c, trial))
+				goto out;
+	}
 
 	/* Remaining checks don't apply to root cpuset */
 	ret = 0;
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] cgroup2: cpuset: Always allow setting empty cpuset
  2021-04-13  9:02 [PATCH 0/2] Relax cpuset validation for cgroup v2 Odin Ugedal
  2021-04-13  9:02 ` [PATCH 1/2] cgroup2: cpuset: Disable subset validation on set Odin Ugedal
@ 2021-04-13  9:02 ` Odin Ugedal
  2021-04-13 11:10 ` [PATCH 0/2] Relax cpuset validation for cgroup v2 Tejun Heo
  2 siblings, 0 replies; 4+ messages in thread
From: Odin Ugedal @ 2021-04-13  9:02 UTC (permalink / raw)
  To: tj, lizefan.x; +Cc: cgroups, linux-kernel, Odin Ugedal

Due to how cpuset works in v2, there is no need to disallow setting an
empty cpuset when tasks are attached. In v2, the effective cpuset of a
cgroup is the intersection between the effective value of the parent and
the cpuset.cpus value of the cgroup, with a fallback to the effective
parent value in case the intersection is an empty set.

Allowing this will make it easier to move the cpuset of a nested cgroup
hierarchy where multiple cgroup use the cpuset.cpus, since the current
solution is to manually update the cpuset of each cgroup when doing this,
causing it be quite complex to change. It also makes it possible to
disable cpuset for a populated cgroup (or one of its ancestors), without
having to manually write the effective value into cpuset.cpus.

This also applies in a similar manner on cpuset.mems.

Signed-off-by: Odin Ugedal <odin@uged.al>
---
 kernel/cgroup/cpuset.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index f543c4c6084a..33a55d461ec3 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -609,11 +609,12 @@ static int validate_change(struct cpuset *cur, struct cpuset *trial)
 	}
 
 	/*
-	 * Cpusets with tasks - existing or newly being attached - can't
-	 * be changed to have empty cpus_allowed or mems_allowed.
+	 * On legacy hierarchy, cpusets with tasks - existing or newly being
+	 * attached - can't be changed to have empty cpus_allowed or
+	 * mems_allowed.
 	 */
 	ret = -ENOSPC;
-	if ((cgroup_is_populated(cur->css.cgroup) || cur->attach_in_progress)) {
+	if (!is_in_v2_mode() && (cgroup_is_populated(cur->css.cgroup) || cur->attach_in_progress)) {
 		if (!cpumask_empty(cur->cpus_allowed) &&
 		    cpumask_empty(trial->cpus_allowed))
 			goto out;
-- 
2.31.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] Relax cpuset validation for cgroup v2
  2021-04-13  9:02 [PATCH 0/2] Relax cpuset validation for cgroup v2 Odin Ugedal
  2021-04-13  9:02 ` [PATCH 1/2] cgroup2: cpuset: Disable subset validation on set Odin Ugedal
  2021-04-13  9:02 ` [PATCH 2/2] cgroup2: cpuset: Always allow setting empty cpuset Odin Ugedal
@ 2021-04-13 11:10 ` Tejun Heo
  2 siblings, 0 replies; 4+ messages in thread
From: Tejun Heo @ 2021-04-13 11:10 UTC (permalink / raw)
  To: Odin Ugedal; +Cc: lizefan.x, cgroups, linux-kernel

On Tue, Apr 13, 2021 at 11:02:33AM +0200, Odin Ugedal wrote:
> Two small validation relaxations for cgroup v2, making it easier to
> manage the hierarchy without the current pain points. Both changes
> work for both mems and cpus (but I have no NUMA machine to test mems).
> 
> Hopefully the patches has an ok description about what change they
> provide, and why they are helpful.

I'm generally in favor of removing configuration constraints but let's hear
what Li thinks.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-13 11:11 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-13  9:02 [PATCH 0/2] Relax cpuset validation for cgroup v2 Odin Ugedal
2021-04-13  9:02 ` [PATCH 1/2] cgroup2: cpuset: Disable subset validation on set Odin Ugedal
2021-04-13  9:02 ` [PATCH 2/2] cgroup2: cpuset: Always allow setting empty cpuset Odin Ugedal
2021-04-13 11:10 ` [PATCH 0/2] Relax cpuset validation for cgroup v2 Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).