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

From: Chen Ridong
Date: Sat Oct 25 2025 - 03:05:53 EST


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;

--
2.34.1