* [PATCH -next 1/3] cgroup/cpuset: Correct invalid remote parition prs
2024-08-16 8:27 [PATCH -next 0/3] Some optimizations about cpuset Chen Ridong
@ 2024-08-16 8:27 ` Chen Ridong
2024-08-19 2:14 ` Waiman Long
2024-08-16 8:27 ` [PATCH -next 2/3] cgroup/cpuset: remove fetch_xcpus Chen Ridong
` (2 subsequent siblings)
3 siblings, 1 reply; 11+ messages in thread
From: Chen Ridong @ 2024-08-16 8:27 UTC (permalink / raw)
To: tj, lizefan.x, hannes, longman, adityakali, sergeh, mkoutny
Cc: cgroups, linux-kernel
When enable a remote partition, I found that:
cd /sys/fs/cgroup/
mkdir test
mkdir test/test1
echo +cpuset > cgroup.subtree_control
echo +cpuset > test/cgroup.subtree_control
echo 3 > test/test1/cpuset.cpus
echo root > test/test1/cpuset.cpus.partition
cat test/test1/cpuset.cpus.partition
root invalid (Parent is not a partition root)
The parent of a remote partition could not be a root. This is due to the
emtpy effective_xcpus. It would be better to prompt the message "invalid
cpu list in cpuset.cpus.exclusive".
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
kernel/cgroup/cpuset.c | 42 +++++++++++++++++++++++-------------------
1 file changed, 23 insertions(+), 19 deletions(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index e34fd6108b06..fdd5346616d3 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -80,6 +80,7 @@ enum prs_errcode {
PERR_HOTPLUG,
PERR_CPUSEMPTY,
PERR_HKEEPING,
+ PERR_PMT,
};
static const char * const perr_strings[] = {
@@ -91,6 +92,7 @@ static const char * const perr_strings[] = {
[PERR_HOTPLUG] = "No cpu available due to hotplug",
[PERR_CPUSEMPTY] = "cpuset.cpus and cpuset.cpus.exclusive are empty",
[PERR_HKEEPING] = "partition config conflicts with housekeeping setup",
+ [PERR_PMT] = "Enable partition not permitted",
};
struct cpuset {
@@ -1669,7 +1671,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
* The user must have sysadmin privilege.
*/
if (!capable(CAP_SYS_ADMIN))
- return 0;
+ return PERR_PMT;
/*
* The requested exclusive_cpus must not be allocated to other
@@ -1683,7 +1685,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
if (cpumask_empty(tmp->new_cpus) ||
cpumask_intersects(tmp->new_cpus, subpartitions_cpus) ||
cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus))
- return 0;
+ return PERR_INVCPUS;
spin_lock_irq(&callback_lock);
isolcpus_updated = partition_xcpus_add(new_prs, NULL, tmp->new_cpus);
@@ -1698,7 +1700,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
*/
update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
update_sibling_cpumasks(&top_cpuset, NULL, tmp);
- return 1;
+ return 0;
}
/*
@@ -3151,24 +3153,26 @@ static int update_prstate(struct cpuset *cs, int new_prs)
goto out;
if (!old_prs) {
- enum partition_cmd cmd = (new_prs == PRS_ROOT)
- ? partcmd_enable : partcmd_enablei;
-
/*
- * cpus_allowed and exclusive_cpus cannot be both empty.
- */
- if (xcpus_empty(cs)) {
- err = PERR_CPUSEMPTY;
- goto out;
- }
+ * If parent is valid partition, enable local partiion.
+ * Otherwise, enable a remote partition.
+ */
+ if (is_partition_valid(parent)) {
+ enum partition_cmd cmd = (new_prs == PRS_ROOT)
+ ? partcmd_enable : partcmd_enablei;
- err = update_parent_effective_cpumask(cs, cmd, NULL, &tmpmask);
- /*
- * If an attempt to become local partition root fails,
- * try to become a remote partition root instead.
- */
- if (err && remote_partition_enable(cs, new_prs, &tmpmask))
- err = 0;
+ /*
+ * cpus_allowed and exclusive_cpus cannot be both empty.
+ */
+ if (xcpus_empty(cs)) {
+ err = PERR_CPUSEMPTY;
+ goto out;
+ }
+
+ err = update_parent_effective_cpumask(cs, cmd, NULL, &tmpmask);
+ } else {
+ err = remote_partition_enable(cs, new_prs, &tmpmask);
+ }
} else if (old_prs && new_prs) {
/*
* A change in load balance state only, no change in cpumasks.
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH -next 1/3] cgroup/cpuset: Correct invalid remote parition prs
2024-08-16 8:27 ` [PATCH -next 1/3] cgroup/cpuset: Correct invalid remote parition prs Chen Ridong
@ 2024-08-19 2:14 ` Waiman Long
2024-08-19 2:18 ` Waiman Long
0 siblings, 1 reply; 11+ messages in thread
From: Waiman Long @ 2024-08-19 2:14 UTC (permalink / raw)
To: Chen Ridong, tj, lizefan.x, hannes, adityakali, sergeh, mkoutny
Cc: cgroups, linux-kernel
On 8/16/24 04:27, Chen Ridong wrote:
> When enable a remote partition, I found that:
>
> cd /sys/fs/cgroup/
> mkdir test
> mkdir test/test1
> echo +cpuset > cgroup.subtree_control
> echo +cpuset > test/cgroup.subtree_control
> echo 3 > test/test1/cpuset.cpus
> echo root > test/test1/cpuset.cpus.partition
> cat test/test1/cpuset.cpus.partition
> root invalid (Parent is not a partition root)
>
> The parent of a remote partition could not be a root. This is due to the
> emtpy effective_xcpus. It would be better to prompt the message "invalid
> cpu list in cpuset.cpus.exclusive".
>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
> kernel/cgroup/cpuset.c | 42 +++++++++++++++++++++++-------------------
> 1 file changed, 23 insertions(+), 19 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index e34fd6108b06..fdd5346616d3 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -80,6 +80,7 @@ enum prs_errcode {
> PERR_HOTPLUG,
> PERR_CPUSEMPTY,
> PERR_HKEEPING,
> + PERR_PMT,
> };
>
> static const char * const perr_strings[] = {
> @@ -91,6 +92,7 @@ static const char * const perr_strings[] = {
> [PERR_HOTPLUG] = "No cpu available due to hotplug",
> [PERR_CPUSEMPTY] = "cpuset.cpus and cpuset.cpus.exclusive are empty",
> [PERR_HKEEPING] = "partition config conflicts with housekeeping setup",
> + [PERR_PMT] = "Enable partition not permitted",
> };
>
> struct cpuset {
> @@ -1669,7 +1671,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
> * The user must have sysadmin privilege.
> */
> if (!capable(CAP_SYS_ADMIN))
> - return 0;
> + return PERR_PMT;
>
> /*
> * The requested exclusive_cpus must not be allocated to other
> @@ -1683,7 +1685,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
> if (cpumask_empty(tmp->new_cpus) ||
> cpumask_intersects(tmp->new_cpus, subpartitions_cpus) ||
> cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus))
> - return 0;
> + return PERR_INVCPUS;
>
> spin_lock_irq(&callback_lock);
> isolcpus_updated = partition_xcpus_add(new_prs, NULL, tmp->new_cpus);
> @@ -1698,7 +1700,7 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
> */
> update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
> update_sibling_cpumasks(&top_cpuset, NULL, tmp);
> - return 1;
> + return 0;
> }
Since you are changing the meaning of the function returned value, you
should also update the return value comment as well.
>
> /*
> @@ -3151,24 +3153,26 @@ static int update_prstate(struct cpuset *cs, int new_prs)
> goto out;
>
> if (!old_prs) {
> - enum partition_cmd cmd = (new_prs == PRS_ROOT)
> - ? partcmd_enable : partcmd_enablei;
> -
> /*
> - * cpus_allowed and exclusive_cpus cannot be both empty.
> - */
> - if (xcpus_empty(cs)) {
> - err = PERR_CPUSEMPTY;
> - goto out;
> - }
> + * If parent is valid partition, enable local partiion.
> + * Otherwise, enable a remote partition.
> + */
> + if (is_partition_valid(parent)) {
> + enum partition_cmd cmd = (new_prs == PRS_ROOT)
> + ? partcmd_enable : partcmd_enablei;
>
> - err = update_parent_effective_cpumask(cs, cmd, NULL, &tmpmask);
> - /*
> - * If an attempt to become local partition root fails,
> - * try to become a remote partition root instead.
> - */
> - if (err && remote_partition_enable(cs, new_prs, &tmpmask))
> - err = 0;
> + /*
> + * cpus_allowed and exclusive_cpus cannot be both empty.
> + */
> + if (xcpus_empty(cs)) {
> + err = PERR_CPUSEMPTY;
> + goto out;
> + }
The xcpus_empty() check should be done for both local and remote partition.
Cheers,
Longman
> +
> + err = update_parent_effective_cpumask(cs, cmd, NULL, &tmpmask);
> + } else {
> + err = remote_partition_enable(cs, new_prs, &tmpmask);
> + }
> } else if (old_prs && new_prs) {
> /*
> * A change in load balance state only, no change in cpumasks.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH -next 1/3] cgroup/cpuset: Correct invalid remote parition prs
2024-08-19 2:14 ` Waiman Long
@ 2024-08-19 2:18 ` Waiman Long
2024-08-19 6:25 ` chenridong
0 siblings, 1 reply; 11+ messages in thread
From: Waiman Long @ 2024-08-19 2:18 UTC (permalink / raw)
To: Chen Ridong, tj, lizefan.x, hannes, adityakali, sergeh, mkoutny
Cc: cgroups, linux-kernel
On 8/18/24 22:14, Waiman Long wrote:
>
> On 8/16/24 04:27, Chen Ridong wrote:
>> When enable a remote partition, I found that:
>>
>> cd /sys/fs/cgroup/
>> mkdir test
>> mkdir test/test1
>> echo +cpuset > cgroup.subtree_control
>> echo +cpuset > test/cgroup.subtree_control
>> echo 3 > test/test1/cpuset.cpus
>> echo root > test/test1/cpuset.cpus.partition
>> cat test/test1/cpuset.cpus.partition
>> root invalid (Parent is not a partition root)
>>
>> The parent of a remote partition could not be a root. This is due to the
>> emtpy effective_xcpus. It would be better to prompt the message "invalid
>> cpu list in cpuset.cpus.exclusive".
>>
>> Signed-off-by: Chen Ridong <chenridong@huawei.com>
>> ---
>> kernel/cgroup/cpuset.c | 42 +++++++++++++++++++++++-------------------
>> 1 file changed, 23 insertions(+), 19 deletions(-)
>>
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index e34fd6108b06..fdd5346616d3 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -80,6 +80,7 @@ enum prs_errcode {
>> PERR_HOTPLUG,
>> PERR_CPUSEMPTY,
>> PERR_HKEEPING,
>> + PERR_PMT,
One more thing, the "PMT" acronym for the error code is hard to decode.
I will suggest you either use the "PERMISSION" or "ACCESS" like the
EACCESS errno.
Cheers,
Longman
>> };
>> static const char * const perr_strings[] = {
>> @@ -91,6 +92,7 @@ static const char * const perr_strings[] = {
>> [PERR_HOTPLUG] = "No cpu available due to hotplug",
>> [PERR_CPUSEMPTY] = "cpuset.cpus and cpuset.cpus.exclusive are
>> empty",
>> [PERR_HKEEPING] = "partition config conflicts with
>> housekeeping setup",
>> + [PERR_PMT] = "Enable partition not permitted",
>> };
>> struct cpuset {
>> @@ -1669,7 +1671,7 @@ static int remote_partition_enable(struct
>> cpuset *cs, int new_prs,
>> * The user must have sysadmin privilege.
>> */
>> if (!capable(CAP_SYS_ADMIN))
>> - return 0;
>> + return PERR_PMT;
>> /*
>> * The requested exclusive_cpus must not be allocated to other
>> @@ -1683,7 +1685,7 @@ static int remote_partition_enable(struct
>> cpuset *cs, int new_prs,
>> if (cpumask_empty(tmp->new_cpus) ||
>> cpumask_intersects(tmp->new_cpus, subpartitions_cpus) ||
>> cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus))
>> - return 0;
>> + return PERR_INVCPUS;
>> spin_lock_irq(&callback_lock);
>> isolcpus_updated = partition_xcpus_add(new_prs, NULL,
>> tmp->new_cpus);
>> @@ -1698,7 +1700,7 @@ static int remote_partition_enable(struct
>> cpuset *cs, int new_prs,
>> */
>> update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
>> update_sibling_cpumasks(&top_cpuset, NULL, tmp);
>> - return 1;
>> + return 0;
>> }
>
> Since you are changing the meaning of the function returned value, you
> should also update the return value comment as well.
>
>> /*
>> @@ -3151,24 +3153,26 @@ static int update_prstate(struct cpuset *cs,
>> int new_prs)
>> goto out;
>> if (!old_prs) {
>> - enum partition_cmd cmd = (new_prs == PRS_ROOT)
>> - ? partcmd_enable : partcmd_enablei;
>> -
>> /*
>> - * cpus_allowed and exclusive_cpus cannot be both empty.
>> - */
>> - if (xcpus_empty(cs)) {
>> - err = PERR_CPUSEMPTY;
>> - goto out;
>> - }
>> + * If parent is valid partition, enable local partiion.
>> + * Otherwise, enable a remote partition.
>> + */
>> + if (is_partition_valid(parent)) {
>> + enum partition_cmd cmd = (new_prs == PRS_ROOT)
>> + ? partcmd_enable : partcmd_enablei;
>> - err = update_parent_effective_cpumask(cs, cmd, NULL,
>> &tmpmask);
>> - /*
>> - * If an attempt to become local partition root fails,
>> - * try to become a remote partition root instead.
>> - */
>> - if (err && remote_partition_enable(cs, new_prs, &tmpmask))
>> - err = 0;
>> + /*
>> + * cpus_allowed and exclusive_cpus cannot be both empty.
>> + */
>> + if (xcpus_empty(cs)) {
>> + err = PERR_CPUSEMPTY;
>> + goto out;
>> + }
>
> The xcpus_empty() check should be done for both local and remote
> partition.
>
> Cheers,
> Longman
>
>> +
>> + err = update_parent_effective_cpumask(cs, cmd, NULL,
>> &tmpmask);
>> + } else {
>> + err = remote_partition_enable(cs, new_prs, &tmpmask);
>> + }
>> } else if (old_prs && new_prs) {
>> /*
>> * A change in load balance state only, no change in cpumasks.
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH -next 1/3] cgroup/cpuset: Correct invalid remote parition prs
2024-08-19 2:18 ` Waiman Long
@ 2024-08-19 6:25 ` chenridong
0 siblings, 0 replies; 11+ messages in thread
From: chenridong @ 2024-08-19 6:25 UTC (permalink / raw)
To: Waiman Long, tj, lizefan.x, hannes, adityakali, sergeh, mkoutny
Cc: cgroups, linux-kernel
On 2024/8/19 10:18, Waiman Long wrote:
> On 8/18/24 22:14, Waiman Long wrote:
>>
>> On 8/16/24 04:27, Chen Ridong wrote:
>>> When enable a remote partition, I found that:
>>>
>>> cd /sys/fs/cgroup/
>>> mkdir test
>>> mkdir test/test1
>>> echo +cpuset > cgroup.subtree_control
>>> echo +cpuset > test/cgroup.subtree_control
>>> echo 3 > test/test1/cpuset.cpus
>>> echo root > test/test1/cpuset.cpus.partition
>>> cat test/test1/cpuset.cpus.partition
>>> root invalid (Parent is not a partition root)
>>>
>>> The parent of a remote partition could not be a root. This is due to the
>>> emtpy effective_xcpus. It would be better to prompt the message "invalid
>>> cpu list in cpuset.cpus.exclusive".
>>>
>>> Signed-off-by: Chen Ridong <chenridong@huawei.com>
>>> ---
>>> kernel/cgroup/cpuset.c | 42 +++++++++++++++++++++++-------------------
>>> 1 file changed, 23 insertions(+), 19 deletions(-)
>>>
>>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>>> index e34fd6108b06..fdd5346616d3 100644
>>> --- a/kernel/cgroup/cpuset.c
>>> +++ b/kernel/cgroup/cpuset.c
>>> @@ -80,6 +80,7 @@ enum prs_errcode {
>>> PERR_HOTPLUG,
>>> PERR_CPUSEMPTY,
>>> PERR_HKEEPING,
>>> + PERR_PMT,
>
> One more thing, the "PMT" acronym for the error code is hard to decode.
> I will suggest you either use the "PERMISSION" or "ACCESS" like the
> EACCESS errno.
>
> Cheers,
> Longman
>
Thanks, will do.
>>> };
>>> static const char * const perr_strings[] = {
>>> @@ -91,6 +92,7 @@ static const char * const perr_strings[] = {
>>> [PERR_HOTPLUG] = "No cpu available due to hotplug",
>>> [PERR_CPUSEMPTY] = "cpuset.cpus and cpuset.cpus.exclusive are
>>> empty",
>>> [PERR_HKEEPING] = "partition config conflicts with
>>> housekeeping setup",
>>> + [PERR_PMT] = "Enable partition not permitted",
>>> };
>>> struct cpuset {
>>> @@ -1669,7 +1671,7 @@ static int remote_partition_enable(struct
>>> cpuset *cs, int new_prs,
>>> * The user must have sysadmin privilege.
>>> */
>>> if (!capable(CAP_SYS_ADMIN))
>>> - return 0;
>>> + return PERR_PMT;
>>> /*
>>> * The requested exclusive_cpus must not be allocated to other
>>> @@ -1683,7 +1685,7 @@ static int remote_partition_enable(struct
>>> cpuset *cs, int new_prs,
>>> if (cpumask_empty(tmp->new_cpus) ||
>>> cpumask_intersects(tmp->new_cpus, subpartitions_cpus) ||
>>> cpumask_subset(top_cpuset.effective_cpus, tmp->new_cpus))
>>> - return 0;
>>> + return PERR_INVCPUS;
>>> spin_lock_irq(&callback_lock);
>>> isolcpus_updated = partition_xcpus_add(new_prs, NULL,
>>> tmp->new_cpus);
>>> @@ -1698,7 +1700,7 @@ static int remote_partition_enable(struct
>>> cpuset *cs, int new_prs,
>>> */
>>> update_tasks_cpumask(&top_cpuset, tmp->new_cpus);
>>> update_sibling_cpumasks(&top_cpuset, NULL, tmp);
>>> - return 1;
>>> + return 0;
>>> }
>>
>> Since you are changing the meaning of the function returned value, you
>> should also update the return value comment as well.
>>
Will do.
>>> /*
>>> @@ -3151,24 +3153,26 @@ static int update_prstate(struct cpuset *cs,
>>> int new_prs)
>>> goto out;
>>> if (!old_prs) {
>>> - enum partition_cmd cmd = (new_prs == PRS_ROOT)
>>> - ? partcmd_enable : partcmd_enablei;
>>> -
>>> /*
>>> - * cpus_allowed and exclusive_cpus cannot be both empty.
>>> - */
>>> - if (xcpus_empty(cs)) {
>>> - err = PERR_CPUSEMPTY;
>>> - goto out;
>>> - }
>>> + * If parent is valid partition, enable local partiion.
>>> + * Otherwise, enable a remote partition.
>>> + */
>>> + if (is_partition_valid(parent)) {
>>> + enum partition_cmd cmd = (new_prs == PRS_ROOT)
>>> + ? partcmd_enable : partcmd_enablei;
>>> - err = update_parent_effective_cpumask(cs, cmd, NULL,
>>> &tmpmask);
>>> - /*
>>> - * If an attempt to become local partition root fails,
>>> - * try to become a remote partition root instead.
>>> - */
>>> - if (err && remote_partition_enable(cs, new_prs, &tmpmask))
>>> - err = 0;
>>> + /*
>>> + * cpus_allowed and exclusive_cpus cannot be both empty.
>>> + */
>>> + if (xcpus_empty(cs)) {
>>> + err = PERR_CPUSEMPTY;
>>> + goto out;
>>> + }
>>
>> The xcpus_empty() check should be done for both local and remote
>> partition.
>>
>> Cheers,
>> Longman
>>
Thanks, I will do it at V2.
Thanks,
Ridong
>>> +
>>> + err = update_parent_effective_cpumask(cs, cmd, NULL,
>>> &tmpmask);
>>> + } else {
>>> + err = remote_partition_enable(cs, new_prs, &tmpmask);
>>> + }
>>> } else if (old_prs && new_prs) {
>>> /*
>>> * A change in load balance state only, no change in cpumasks.
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH -next 2/3] cgroup/cpuset: remove fetch_xcpus
2024-08-16 8:27 [PATCH -next 0/3] Some optimizations about cpuset Chen Ridong
2024-08-16 8:27 ` [PATCH -next 1/3] cgroup/cpuset: Correct invalid remote parition prs Chen Ridong
@ 2024-08-16 8:27 ` Chen Ridong
2024-08-19 17:24 ` Saket Kumar Bhaskar
2024-08-19 18:28 ` Waiman Long
2024-08-16 8:27 ` [PATCH -next 3/3] cgroup/cpuset: remove use_parent_ecpus of cpuset Chen Ridong
2024-08-19 22:01 ` [PATCH -next 0/3] Some optimizations about cpuset Tejun Heo
3 siblings, 2 replies; 11+ messages in thread
From: Chen Ridong @ 2024-08-16 8:27 UTC (permalink / raw)
To: tj, lizefan.x, hannes, longman, adityakali, sergeh, mkoutny
Cc: cgroups, linux-kernel
Both fetch_xcpus and user_xcpus functions are used to retrieve the value
of exclusive_cpus. If exclusive_cpus is not set, cpus_allowed is the
implicit value used as exclusive in a local partition. I can not imagine
a scenario where effective_xcpus is not empty when exclusive_cpus is
empty. Therefore, I suggest removing the fetch_xcpus function.
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
kernel/cgroup/cpuset.c | 13 +++----------
1 file changed, 3 insertions(+), 10 deletions(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index fdd5346616d3..8be0259065f5 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -771,13 +771,6 @@ static inline bool xcpus_empty(struct cpuset *cs)
cpumask_empty(cs->exclusive_cpus);
}
-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;
-}
-
/*
* cpusets_are_exclusive() - check if two cpusets are exclusive
*
@@ -785,8 +778,8 @@ static inline struct cpumask *fetch_xcpus(struct cpuset *cs)
*/
static inline bool cpusets_are_exclusive(struct cpuset *cs1, struct cpuset *cs2)
{
- struct cpumask *xcpus1 = fetch_xcpus(cs1);
- struct cpumask *xcpus2 = fetch_xcpus(cs2);
+ struct cpumask *xcpus1 = user_xcpus(cs1);
+ struct cpumask *xcpus2 = user_xcpus(cs2);
if (cpumask_intersects(xcpus1, xcpus2))
return false;
@@ -2585,7 +2578,7 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
invalidate = true;
rcu_read_lock();
cpuset_for_each_child(cp, css, parent) {
- struct cpumask *xcpus = fetch_xcpus(trialcs);
+ struct cpumask *xcpus = user_xcpus(trialcs);
if (is_partition_valid(cp) &&
cpumask_intersects(xcpus, cp->effective_xcpus)) {
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH -next 2/3] cgroup/cpuset: remove fetch_xcpus
2024-08-16 8:27 ` [PATCH -next 2/3] cgroup/cpuset: remove fetch_xcpus Chen Ridong
@ 2024-08-19 17:24 ` Saket Kumar Bhaskar
2024-08-19 18:28 ` Waiman Long
1 sibling, 0 replies; 11+ messages in thread
From: Saket Kumar Bhaskar @ 2024-08-19 17:24 UTC (permalink / raw)
To: Chen Ridong
Cc: tj, lizefan.x, hannes, longman, adityakali, sergeh, mkoutny,
cgroups, linux-kernel
On Fri, Aug 16, 2024 at 08:27:26AM +0000, Chen Ridong wrote:
> Both fetch_xcpus and user_xcpus functions are used to retrieve the value
> of exclusive_cpus. If exclusive_cpus is not set, cpus_allowed is the
> implicit value used as exclusive in a local partition. I can not imagine
> a scenario where effective_xcpus is not empty when exclusive_cpus is
> empty. Therefore, I suggest removing the fetch_xcpus function.
>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
> kernel/cgroup/cpuset.c | 13 +++----------
> 1 file changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index fdd5346616d3..8be0259065f5 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -771,13 +771,6 @@ static inline bool xcpus_empty(struct cpuset *cs)
> cpumask_empty(cs->exclusive_cpus);
> }
>
> -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;
> -}
> -
> /*
> * cpusets_are_exclusive() - check if two cpusets are exclusive
> *
> @@ -785,8 +778,8 @@ static inline struct cpumask *fetch_xcpus(struct cpuset *cs)
> */
> static inline bool cpusets_are_exclusive(struct cpuset *cs1, struct cpuset *cs2)
> {
> - struct cpumask *xcpus1 = fetch_xcpus(cs1);
> - struct cpumask *xcpus2 = fetch_xcpus(cs2);
> + struct cpumask *xcpus1 = user_xcpus(cs1);
> + struct cpumask *xcpus2 = user_xcpus(cs2);
>
> if (cpumask_intersects(xcpus1, xcpus2))
> return false;
> @@ -2585,7 +2578,7 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
> invalidate = true;
> rcu_read_lock();
> cpuset_for_each_child(cp, css, parent) {
> - struct cpumask *xcpus = fetch_xcpus(trialcs);
> + struct cpumask *xcpus = user_xcpus(trialcs);
>
> if (is_partition_valid(cp) &&
> cpumask_intersects(xcpus, cp->effective_xcpus)) {
> --
> 2.34.1
>
Hi,
In update_cpumask too fetch_xcpus is used. You may want to remove it from there too.
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 40ec4abaf440..1b4ee6403de6 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -2587,7 +2587,7 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
invalidate = true;
rcu_read_lock();
cpuset_for_each_child(cp, css, parent) {
- struct cpumask *xcpus = fetch_xcpus(trialcs);
+ struct cpumask *xcpus = user_xcpus(trialcs);
if (is_partition_valid(cp) &&
cpumask_intersects(xcpus, cp->effective_xcpus)) {
Reviewed-by: Saket Kumar Bhaskar <skb99@linux.ibm.com>
Thanks,
Saket
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH -next 2/3] cgroup/cpuset: remove fetch_xcpus
2024-08-16 8:27 ` [PATCH -next 2/3] cgroup/cpuset: remove fetch_xcpus Chen Ridong
2024-08-19 17:24 ` Saket Kumar Bhaskar
@ 2024-08-19 18:28 ` Waiman Long
1 sibling, 0 replies; 11+ messages in thread
From: Waiman Long @ 2024-08-19 18:28 UTC (permalink / raw)
To: Chen Ridong, tj, lizefan.x, hannes, adityakali, sergeh, mkoutny
Cc: cgroups, linux-kernel
On 8/16/24 04:27, Chen Ridong wrote:
> Both fetch_xcpus and user_xcpus functions are used to retrieve the value
> of exclusive_cpus. If exclusive_cpus is not set, cpus_allowed is the
> implicit value used as exclusive in a local partition. I can not imagine
> a scenario where effective_xcpus is not empty when exclusive_cpus is
> empty. Therefore, I suggest removing the fetch_xcpus function.
>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
> kernel/cgroup/cpuset.c | 13 +++----------
> 1 file changed, 3 insertions(+), 10 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index fdd5346616d3..8be0259065f5 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -771,13 +771,6 @@ static inline bool xcpus_empty(struct cpuset *cs)
> cpumask_empty(cs->exclusive_cpus);
> }
>
> -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;
> -}
> -
> /*
> * cpusets_are_exclusive() - check if two cpusets are exclusive
> *
> @@ -785,8 +778,8 @@ static inline struct cpumask *fetch_xcpus(struct cpuset *cs)
> */
> static inline bool cpusets_are_exclusive(struct cpuset *cs1, struct cpuset *cs2)
> {
> - struct cpumask *xcpus1 = fetch_xcpus(cs1);
> - struct cpumask *xcpus2 = fetch_xcpus(cs2);
> + struct cpumask *xcpus1 = user_xcpus(cs1);
> + struct cpumask *xcpus2 = user_xcpus(cs2);
>
> if (cpumask_intersects(xcpus1, xcpus2))
> return false;
> @@ -2585,7 +2578,7 @@ static int update_cpumask(struct cpuset *cs, struct cpuset *trialcs,
> invalidate = true;
> rcu_read_lock();
> cpuset_for_each_child(cp, css, parent) {
> - struct cpumask *xcpus = fetch_xcpus(trialcs);
> + struct cpumask *xcpus = user_xcpus(trialcs);
>
> if (is_partition_valid(cp) &&
> cpumask_intersects(xcpus, cp->effective_xcpus)) {
LGTM.
Reviewed-by: Waiman Long <longman@redhat.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH -next 3/3] cgroup/cpuset: remove use_parent_ecpus of cpuset
2024-08-16 8:27 [PATCH -next 0/3] Some optimizations about cpuset Chen Ridong
2024-08-16 8:27 ` [PATCH -next 1/3] cgroup/cpuset: Correct invalid remote parition prs Chen Ridong
2024-08-16 8:27 ` [PATCH -next 2/3] cgroup/cpuset: remove fetch_xcpus Chen Ridong
@ 2024-08-16 8:27 ` Chen Ridong
2024-08-19 18:43 ` Waiman Long
2024-08-19 22:01 ` [PATCH -next 0/3] Some optimizations about cpuset Tejun Heo
3 siblings, 1 reply; 11+ messages in thread
From: Chen Ridong @ 2024-08-16 8:27 UTC (permalink / raw)
To: tj, lizefan.x, hannes, longman, adityakali, sergeh, mkoutny
Cc: cgroups, linux-kernel
use_parent_ecpus is used to track whether the children are using the
parent's effective_cpus. When a parent's effective_cpus is changed
due to changes in a child partition's effective_xcpus, any child
using parent'effective_cpus must call update_cpumasks_hier. However,
if a child is not a valid partition, it is sufficient to determine
whether to call update_cpumasks_hier based on whether the child's
effective_cpus is going to change. To make the code more succinct,
it is suggested to remove use_parent_ecpus.
Signed-off-by: Chen Ridong <chenridong@huawei.com>
---
kernel/cgroup/cpuset.c | 30 ++++--------------------------
1 file changed, 4 insertions(+), 26 deletions(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 8be0259065f5..71c24542966b 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -185,12 +185,6 @@ struct cpuset {
/* partition root state */
int partition_root_state;
- /*
- * Default hierarchy only:
- * use_parent_ecpus - set if using parent's effective_cpus
- */
- int use_parent_ecpus;
-
/*
* number of SCHED_DEADLINE tasks attached to this cpuset, so that we
* know when to rebuild associated root domain bandwidth information.
@@ -1505,11 +1499,8 @@ static void reset_partition_data(struct cpuset *cs)
if (is_cpu_exclusive(cs))
clear_bit(CS_CPU_EXCLUSIVE, &cs->flags);
}
- if (!cpumask_and(cs->effective_cpus,
- parent->effective_cpus, cs->cpus_allowed)) {
- cs->use_parent_ecpus = true;
+ if (!cpumask_and(cs->effective_cpus, parent->effective_cpus, cs->cpus_allowed))
cpumask_copy(cs->effective_cpus, parent->effective_cpus);
- }
}
/*
@@ -1683,8 +1674,6 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
spin_lock_irq(&callback_lock);
isolcpus_updated = partition_xcpus_add(new_prs, NULL, tmp->new_cpus);
list_add(&cs->remote_sibling, &remote_children);
- if (cs->use_parent_ecpus)
- cs->use_parent_ecpus = false;
spin_unlock_irq(&callback_lock);
update_unbound_workqueue_cpumask(isolcpus_updated);
@@ -2309,13 +2298,8 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
* it is a partition root that has explicitly distributed
* out all its CPUs.
*/
- if (is_in_v2_mode() && !remote && cpumask_empty(tmp->new_cpus)) {
+ if (is_in_v2_mode() && !remote && cpumask_empty(tmp->new_cpus))
cpumask_copy(tmp->new_cpus, parent->effective_cpus);
- if (!cp->use_parent_ecpus)
- cp->use_parent_ecpus = true;
- } else if (cp->use_parent_ecpus) {
- cp->use_parent_ecpus = false;
- }
if (remote)
goto get_css;
@@ -2452,8 +2436,7 @@ static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *cs,
* Check all its siblings and call update_cpumasks_hier()
* if their effective_cpus will need to be changed.
*
- * With the addition of effective_xcpus which is a subset of
- * cpus_allowed. It is possible a change in parent's effective_cpus
+ * It is possible a change in parent's effective_cpus
* due to a change in a child partition's effective_xcpus will impact
* its siblings even if they do not inherit parent's effective_cpus
* directly.
@@ -2467,8 +2450,7 @@ static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *cs,
cpuset_for_each_child(sibling, pos_css, parent) {
if (sibling == cs)
continue;
- if (!sibling->use_parent_ecpus &&
- !is_partition_valid(sibling)) {
+ if (!is_partition_valid(sibling)) {
compute_effective_cpumask(tmp->new_cpus, sibling,
parent);
if (cpumask_equal(tmp->new_cpus, sibling->effective_cpus))
@@ -4128,7 +4110,6 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
if (is_in_v2_mode()) {
cpumask_copy(cs->effective_cpus, parent->effective_cpus);
cs->effective_mems = parent->effective_mems;
- cs->use_parent_ecpus = true;
}
spin_unlock_irq(&callback_lock);
@@ -4194,9 +4175,6 @@ static void cpuset_css_offline(struct cgroup_subsys_state *css)
is_sched_load_balance(cs))
update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);
- if (cs->use_parent_ecpus)
- cs->use_parent_ecpus = false;
-
cpuset_dec();
clear_bit(CS_ONLINE, &cs->flags);
--
2.34.1
^ permalink raw reply related [flat|nested] 11+ messages in thread* Re: [PATCH -next 3/3] cgroup/cpuset: remove use_parent_ecpus of cpuset
2024-08-16 8:27 ` [PATCH -next 3/3] cgroup/cpuset: remove use_parent_ecpus of cpuset Chen Ridong
@ 2024-08-19 18:43 ` Waiman Long
0 siblings, 0 replies; 11+ messages in thread
From: Waiman Long @ 2024-08-19 18:43 UTC (permalink / raw)
To: Chen Ridong, tj, lizefan.x, hannes, adityakali, sergeh, mkoutny
Cc: cgroups, linux-kernel
On 8/16/24 04:27, Chen Ridong wrote:
> use_parent_ecpus is used to track whether the children are using the
> parent's effective_cpus. When a parent's effective_cpus is changed
> due to changes in a child partition's effective_xcpus, any child
> using parent'effective_cpus must call update_cpumasks_hier. However,
> if a child is not a valid partition, it is sufficient to determine
> whether to call update_cpumasks_hier based on whether the child's
> effective_cpus is going to change. To make the code more succinct,
> it is suggested to remove use_parent_ecpus.
>
> Signed-off-by: Chen Ridong <chenridong@huawei.com>
> ---
> kernel/cgroup/cpuset.c | 30 ++++--------------------------
> 1 file changed, 4 insertions(+), 26 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 8be0259065f5..71c24542966b 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -185,12 +185,6 @@ struct cpuset {
> /* partition root state */
> int partition_root_state;
>
> - /*
> - * Default hierarchy only:
> - * use_parent_ecpus - set if using parent's effective_cpus
> - */
> - int use_parent_ecpus;
> -
> /*
> * number of SCHED_DEADLINE tasks attached to this cpuset, so that we
> * know when to rebuild associated root domain bandwidth information.
> @@ -1505,11 +1499,8 @@ static void reset_partition_data(struct cpuset *cs)
> if (is_cpu_exclusive(cs))
> clear_bit(CS_CPU_EXCLUSIVE, &cs->flags);
> }
> - if (!cpumask_and(cs->effective_cpus,
> - parent->effective_cpus, cs->cpus_allowed)) {
> - cs->use_parent_ecpus = true;
> + if (!cpumask_and(cs->effective_cpus, parent->effective_cpus, cs->cpus_allowed))
> cpumask_copy(cs->effective_cpus, parent->effective_cpus);
> - }
> }
>
> /*
> @@ -1683,8 +1674,6 @@ static int remote_partition_enable(struct cpuset *cs, int new_prs,
> spin_lock_irq(&callback_lock);
> isolcpus_updated = partition_xcpus_add(new_prs, NULL, tmp->new_cpus);
> list_add(&cs->remote_sibling, &remote_children);
> - if (cs->use_parent_ecpus)
> - cs->use_parent_ecpus = false;
> spin_unlock_irq(&callback_lock);
> update_unbound_workqueue_cpumask(isolcpus_updated);
>
> @@ -2309,13 +2298,8 @@ static void update_cpumasks_hier(struct cpuset *cs, struct tmpmasks *tmp,
> * it is a partition root that has explicitly distributed
> * out all its CPUs.
> */
> - if (is_in_v2_mode() && !remote && cpumask_empty(tmp->new_cpus)) {
> + if (is_in_v2_mode() && !remote && cpumask_empty(tmp->new_cpus))
> cpumask_copy(tmp->new_cpus, parent->effective_cpus);
> - if (!cp->use_parent_ecpus)
> - cp->use_parent_ecpus = true;
> - } else if (cp->use_parent_ecpus) {
> - cp->use_parent_ecpus = false;
> - }
>
> if (remote)
> goto get_css;
> @@ -2452,8 +2436,7 @@ static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *cs,
> * Check all its siblings and call update_cpumasks_hier()
> * if their effective_cpus will need to be changed.
> *
> - * With the addition of effective_xcpus which is a subset of
> - * cpus_allowed. It is possible a change in parent's effective_cpus
> + * It is possible a change in parent's effective_cpus
> * due to a change in a child partition's effective_xcpus will impact
> * its siblings even if they do not inherit parent's effective_cpus
> * directly.
> @@ -2467,8 +2450,7 @@ static void update_sibling_cpumasks(struct cpuset *parent, struct cpuset *cs,
> cpuset_for_each_child(sibling, pos_css, parent) {
> if (sibling == cs)
> continue;
> - if (!sibling->use_parent_ecpus &&
> - !is_partition_valid(sibling)) {
> + if (!is_partition_valid(sibling)) {
> compute_effective_cpumask(tmp->new_cpus, sibling,
> parent);
> if (cpumask_equal(tmp->new_cpus, sibling->effective_cpus))
> @@ -4128,7 +4110,6 @@ static int cpuset_css_online(struct cgroup_subsys_state *css)
> if (is_in_v2_mode()) {
> cpumask_copy(cs->effective_cpus, parent->effective_cpus);
> cs->effective_mems = parent->effective_mems;
> - cs->use_parent_ecpus = true;
> }
> spin_unlock_irq(&callback_lock);
>
> @@ -4194,9 +4175,6 @@ static void cpuset_css_offline(struct cgroup_subsys_state *css)
> is_sched_load_balance(cs))
> update_flag(CS_SCHED_LOAD_BALANCE, cs, 0);
>
> - if (cs->use_parent_ecpus)
> - cs->use_parent_ecpus = false;
> -
> cpuset_dec();
> clear_bit(CS_ONLINE, &cs->flags);
>
LGTM
Reviewed-by: Waiman Long <longman@redhat.com>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH -next 0/3] Some optimizations about cpuset
2024-08-16 8:27 [PATCH -next 0/3] Some optimizations about cpuset Chen Ridong
` (2 preceding siblings ...)
2024-08-16 8:27 ` [PATCH -next 3/3] cgroup/cpuset: remove use_parent_ecpus of cpuset Chen Ridong
@ 2024-08-19 22:01 ` Tejun Heo
3 siblings, 0 replies; 11+ messages in thread
From: Tejun Heo @ 2024-08-19 22:01 UTC (permalink / raw)
To: Chen Ridong
Cc: lizefan.x, hannes, longman, adityakali, sergeh, mkoutny, cgroups,
linux-kernel
On Fri, Aug 16, 2024 at 08:27:24AM +0000, Chen Ridong wrote:
> Chen Ridong (3):
> cgroup/cpuset: Correct invalid remote parition prs
> cgroup/cpuset: remove fetch_xcpus
> cgroup/cpuset: remove use_parent_ecpus of cpuset
Looks like the first patch needs update. I'll wait for the v2 patchset.
Thanks.
--
tejun
^ permalink raw reply [flat|nested] 11+ messages in thread