Re: [PATCH RFC v2 02/22] cpuset: add early empty cpumask check in partition_xcpus_add/del

From: Waiman Long

Date: Wed Nov 12 2025 - 15:18:24 EST


On 10/25/25 2:48 AM, Chen Ridong wrote:
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.

Signed-off-by: Chen Ridong <chenridong@xxxxxxxxxx>
---
kernel/cgroup/cpuset.c | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 6af4d80b53c4..3ba9ca4e8f5e 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -1345,6 +1345,9 @@ static bool 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 false;
+
if (!parent)
parent = &top_cpuset;
@@ -1377,6 +1380,9 @@ static bool 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 false;
+
if (!parent)
parent = &top_cpuset;

partition_xcpus_add() and partition_xcpus_del() are supposed to be called only when action is really needed. The empty xcpus check should be done earlier to avoid calling them in the first  place. So unless you are planning to change the logic that they will always be called even if action is not really needed. If so, you have to state in the commit log.

Cheers,
Longman