cgroup/cpuset: Do not clear xcpus when clearing cpus
Subsystems (3)
PATCH 1/1 cgroup/cpuset: Do not clear xcpus when clearing cpus
After commit 737bb142a00d ("cgroup/cpuset: Make cpuset.cpus.exclusive independent of cpuset.cpus"), cpuset.cpus.exclusive and cpuset.cpus became independent. However we found that cpuset.cpus.exclusive.effective is cleared when cpuset.cpus is clear. To fix this issue, just remove xcpus clearing when cpuset.cpus is being cleared.
It can be reproduced as below:
cd /sys/fs/cgroup/
mkdir test
echo +cpuset > cgroup.subtree_control
cd test
echo 3 > cpuset.cpus.exclusive
cat cpuset.cpus.exclusive.effective
3
echo > cpuset.cpus
cat cpuset.cpus.exclusive.effective // was cleared
--- kernel/cgroup/cpuset.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/cgroup/cpuset.c +2 -3
@@ -2523,10 +2523,9 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,* that parsing. The validate_change() call ensures that cpusets * with tasks have cpus. */ -if (!*buf) { +if (!*buf)cpumask_clear (trialcs->cpus_allowed); -cpumask_clear (trialcs->effective_xcpus); - }else { +else { retval =cpulist_parse (buf, trialcs->cpus_allowed);if (retval <0 )return retval;
Signature · 1 line
2.34.1
Quoted 29 lines · Chen Ridong
After commit
737bb142a00d("cgroup/cpuset: Make cpuset.cpus.exclusive independent of cpuset.cpus"), cpuset.cpus.exclusive and cpuset.cpus became independent. However we found that cpuset.cpus.exclusive.effective is cleared when cpuset.cpus is clear. To fix this issue, just remove xcpus clearing when cpuset.cpus is being cleared.It can be reproduced as below:
cd/sys/fs/cgroup/
mkdir test
echo +cpuset > cgroup.subtree_control
cd test
echo 3 > cpuset.cpus.exclusive
cat cpuset.cpus.exclusive.effective
3
echo > cpuset.cpus
cat cpuset.cpus.exclusive.effective // was clearedSigned-off-by Chen Ridong <[email protected]>--- kernel/cgroup/cpuset.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)kernel/cgroup/cpuset.c +0
-0@@ -2523,10 +2523,9 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,* that parsing. The validate_change() call ensures that cpusets * with tasks have cpus.
kernel/cgroup/cpuset.c static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs, · line 2531
Quoted 10 lines
kernel/cgroup/cpuset.c +2
-3*/ -if (!*buf) { +if (!*buf)cpumask_clear (trialcs->cpus_allowed); -cpumask_clear (trialcs->effective_xcpus); - }else { +else { retval =cpulist_parse (buf, trialcs->cpus_allowed);if (retval <0 )return retval;
Yes, that is a corner case bug that has not been properly handled.
Waiman Long
maintainerQuoted 44 lines · Waiman Long
Quoted 39 lines · Chen Ridong
After commit
737bb142a00d("cgroup/cpuset: Make cpuset.cpus.exclusive independent of cpuset.cpus"), cpuset.cpus.exclusive and cpuset.cpus became independent. However we found that cpuset.cpus.exclusive.effective is cleared when cpuset.cpus is clear. To fix this issue, just remove xcpus clearing when cpuset.cpus is being cleared.It can be reproduced as below:
cd/sys/fs/cgroup/
mkdir test
echo +cpuset > cgroup.subtree_control
cd test
echo 3 > cpuset.cpus.exclusive
cat cpuset.cpus.exclusive.effective
3
echo > cpuset.cpus
cat cpuset.cpus.exclusive.effective // was clearedSigned-off-by Chen Ridong <[email protected]>---
kernel/cgroup/cpuset.c| 5 ++---1 file changed, 2 insertions(+), 3 deletions(-)kernel/cgroup/cpuset.c +2
-3@@ -2523,10 +2523,9 @@ static int update_cpumask(struct cpuset *cs,struct cpuset *trialcs, * that parsing. The validate_change() call ensures that cpusets * with tasks have cpus. */ - if (!*buf) { + if (!*buf) cpumask_clear(trialcs->cpus_allowed); - cpumask_clear(trialcs->effective_xcpus); - } else { + else { retval = cpulist_parse(buf, trialcs->cpus_allowed); if (retval < 0)Quoted 1 line
return retval;
Yes, that is a corner case bug that has not been properly handled.
Quoted 2 lines
Reviewed-by Waiman Long <[email protected]>
With a second thought, I think we should keep the clearing of effective_xcpus if exclusive_cpus is empty. IOW
kernel/cgroup/cpuset.c +0 -0
@@ -2516,7 +2516,8 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
*/
if (!*buf) { cpumask_clear(trialcs->cpus_allowed);
- cpumask_clear(trialcs->effective_xcpus); + if (cpumask_empty(trialcs->exclusive_cpus))
+ cpumask_clear(trialcs->effective_xcpus);
} else {
retval = cpulist_parse(buf, trialcs->cpus_allowed); if (retval < 0)
Thanks,
Longman
Quoted 69 lines · Waiman Long
Quoted 46 lines · Waiman Long
Quoted 41 lines · Chen Ridong
After commit
737bb142a00d("cgroup/cpuset: Make cpuset.cpus.exclusive independent of cpuset.cpus"), cpuset.cpus.exclusive and cpuset.cpus became independent. However we found that cpuset.cpus.exclusive.effective
is cleared when cpuset.cpus is clear. To fix this issue, just remove xcpus
clearing when cpuset.cpus is being cleared.It can be reproduced as below:
cd/sys/fs/cgroup/
mkdir test
echo +cpuset > cgroup.subtree_control
cd test
echo 3 > cpuset.cpus.exclusive
cat cpuset.cpus.exclusive.effective
3
echo > cpuset.cpus
cat cpuset.cpus.exclusive.effective // was clearedSigned-off-by Chen Ridong <[email protected]>---
kernel/cgroup/cpuset.c| 5 ++---1 file changed, 2 insertions(+), 3 deletions(-)kernel/cgroup/cpuset.c +2
-3@@ -2523,10 +2523,9 @@ static int update_cpumask(struct cpuset *cs,struct cpuset *trialcs, * that parsing. The validate_change() call ensures that cpusets * with tasks have cpus. */ - if (!*buf) { + if (!*buf) cpumask_clear(trialcs->cpus_allowed); - cpumask_clear(trialcs->effective_xcpus); - } else { + else { retval = cpulist_parse(buf, trialcs->cpus_allowed); if (retval < 0)Quoted 1 line
return retval;
Yes, that is a corner case bug that has not been properly handled.
Quoted 2 lines
Reviewed-by Waiman Long <[email protected]>With a second thought, I think we should keep the clearing of
effective_xcpusifexclusive_cpusis empty. IOWkernel/cgroup/cpuset.c +2
-1@@ -2516,7 +2516,8 @@ static int update_cpumask(struct cpuset *cs, structcpuset *trialcs, */ if (!*buf) { cpumask_clear(trialcs->cpus_allowed); - cpumask_clear(trialcs->effective_xcpus); + if (cpumask_empty(trialcs->exclusive_cpus)) +cpumask_clear (trialcs->effective_xcpus); } else { retval = cpulist_parse(buf, trialcs->cpus_allowed);if (retval < 0)
Quoted 3 lines
Thanks,
Longman
Hi Longman,
Is there any situation in which we could land here for or after clearing exclusive_cpus. AFAIK only way we could landup after clearing exclusive_cpus to update_exclusive_cpumask(), which anyway clears effective_xcpus. In that case, clearing effective_xcpus would be redundant in update_cpumask().
Also, is there any situation in which we could end up clearing exclusive_cpus without clearing effective_xcpus as we have a piece of code:
static inline struct cpumask *fetch_xcpus(struct cpuset *cs)
{
return !cpumask_empty(cs->exclusive_cpus) ? cs->exclusive_cpus :
cpumask_empty(cs->effective_xcpus) ? cs->cpus_allowed
: cs->effective_xcpus;
}Thanks,
Saket