[cgroup/for-6.20 PATCH v2 1/4] cgroup/cpuset: Streamline rm_siblings_excl_cpus()

Waiman Long posted 4 patches 1 month, 1 week ago
There is a newer version of this series
[cgroup/for-6.20 PATCH v2 1/4] cgroup/cpuset: Streamline rm_siblings_excl_cpus()
Posted by Waiman Long 1 month, 1 week ago
If exclusive_cpus is set, effective_xcpus must be a subset of
exclusive_cpus. Currently, rm_siblings_excl_cpus() checks both
exclusive_cpus and effective_xcpus consecutively. It is simpler
to check only exclusive_cpus if non-empty or just effective_xcpus
otherwise.

No functional change is expected.

Signed-off-by: Waiman Long <longman@redhat.com>
---
 kernel/cgroup/cpuset.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 221da921b4f9..da2b3b51630e 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1355,23 +1355,29 @@ static int rm_siblings_excl_cpus(struct cpuset *parent, struct cpuset *cs,
 	int retval = 0;
 
 	if (cpumask_empty(excpus))
-		return retval;
+		return 0;
 
 	/*
-	 * Exclude exclusive CPUs from siblings
+	 * Remove exclusive CPUs from siblings
 	 */
 	rcu_read_lock();
 	cpuset_for_each_child(sibling, css, parent) {
+		struct cpumask *sibling_xcpus;
+
 		if (sibling == cs)
 			continue;
 
-		if (cpumask_intersects(excpus, sibling->exclusive_cpus)) {
-			cpumask_andnot(excpus, excpus, sibling->exclusive_cpus);
-			retval++;
-			continue;
-		}
-		if (cpumask_intersects(excpus, sibling->effective_xcpus)) {
-			cpumask_andnot(excpus, excpus, sibling->effective_xcpus);
+		/*
+		 * If exclusive_cpus is defined, effective_xcpus will always
+		 * be a subset. Otherwise, effective_xcpus will only be set
+		 * in a valid partition root.
+		 */
+		sibling_xcpus = cpumask_empty(sibling->exclusive_cpus)
+			      ? sibling->effective_xcpus
+			      : sibling->exclusive_cpus;
+
+		if (cpumask_intersects(excpus, sibling_xcpus)) {
+			cpumask_andnot(excpus, excpus, sibling_xcpus);
 			retval++;
 		}
 	}
-- 
2.52.0
Re: [cgroup/for-6.20 PATCH v2 1/4] cgroup/cpuset: Streamline rm_siblings_excl_cpus()
Posted by Chen Ridong 1 month ago

On 2026/1/2 3:15, Waiman Long wrote:
> If exclusive_cpus is set, effective_xcpus must be a subset of
> exclusive_cpus. Currently, rm_siblings_excl_cpus() checks both
> exclusive_cpus and effective_xcpus consecutively. It is simpler
> to check only exclusive_cpus if non-empty or just effective_xcpus
> otherwise.
> 
> No functional change is expected.
> 
> Signed-off-by: Waiman Long <longman@redhat.com>
> ---
>  kernel/cgroup/cpuset.c | 24 +++++++++++++++---------
>  1 file changed, 15 insertions(+), 9 deletions(-)
> 
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 221da921b4f9..da2b3b51630e 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1355,23 +1355,29 @@ static int rm_siblings_excl_cpus(struct cpuset *parent, struct cpuset *cs,
>  	int retval = 0;
>  
>  	if (cpumask_empty(excpus))
> -		return retval;
> +		return 0;
>  
>  	/*
> -	 * Exclude exclusive CPUs from siblings
> +	 * Remove exclusive CPUs from siblings
>  	 */
>  	rcu_read_lock();
>  	cpuset_for_each_child(sibling, css, parent) {
> +		struct cpumask *sibling_xcpus;
> +
>  		if (sibling == cs)
>  			continue;
>  
> -		if (cpumask_intersects(excpus, sibling->exclusive_cpus)) {
> -			cpumask_andnot(excpus, excpus, sibling->exclusive_cpus);
> -			retval++;
> -			continue;
> -		}
> -		if (cpumask_intersects(excpus, sibling->effective_xcpus)) {
> -			cpumask_andnot(excpus, excpus, sibling->effective_xcpus);
> +		/*
> +		 * If exclusive_cpus is defined, effective_xcpus will always
> +		 * be a subset. Otherwise, effective_xcpus will only be set
> +		 * in a valid partition root.
> +		 */
> +		sibling_xcpus = cpumask_empty(sibling->exclusive_cpus)
> +			      ? sibling->effective_xcpus
> +			      : sibling->exclusive_cpus;
> +
> +		if (cpumask_intersects(excpus, sibling_xcpus)) {
> +			cpumask_andnot(excpus, excpus, sibling_xcpus);
>  			retval++;
>  		}
>  	}

LGTM

Reviewed-by: Chen Ridong<chenridong@huawei.com>

-- 
Best regards,
Ridong