Re: [RFC PATCH -v4 01/22] cpuset: add early empty cpumask check in partition_xcpus_add/del

From: Guopeng Zhang

Date: Tue Nov 03 2026 - 05:37:13 EST




在 2026/11/1 19:41, Ridong Chen 写道:
> From: Chen Ridong <chenridong@xxxxxxxxxx>
>
> Add a check for an empty cpumask at the start of partition_xcpus_add()
> and partition_xcpus_del(). This allows the functions to return early,
> avoiding unnecessary computation when there is no work to be done. With
> these changes, partition_xcpus_add() and partition_xcpus_del() can be
> called even if xcpus is empty. The caller no longer needs to check whether
> xcpus is empty, eliminating many conditional statements.
>
> Signed-off-by: Chen Ridong <chenridong@xxxxxxxxxx>
> Signed-off-by: Ridong Chen <chenridong@xxxxxxxxxx>
> ---
> kernel/cgroup/cpuset.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 3219f927c35e..72e1df1295e1 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -1315,10 +1315,13 @@ static void partition_xcpus_add(int new_prs, struct cpuset *parent,
> {
> WARN_ON_ONCE(new_prs < 0);
> lockdep_assert_held(&callback_lock);
> +
> + if (cpumask_empty(xcpus))
> + return;
> +
> if (!parent)
> parent = &top_cpuset;
>
> -
> if (parent == &top_cpuset)
> cpumask_or(subpartitions_cpus, subpartitions_cpus, xcpus);
>
> @@ -1342,6 +1345,10 @@ static void partition_xcpus_del(int old_prs, struct cpuset *parent,
> {
> WARN_ON_ONCE(old_prs < 0);
> lockdep_assert_held(&callback_lock);
> +
> + if (cpumask_empty(xcpus))
> + return;
> +
> if (!parent)
> parent = &top_cpuset;
>

Reviewed-by: Guopeng Zhang <zhangguopeng@xxxxxxxxxx>

Thanks,
Guopeng