Now that nodes_and() returns true if the result nodemask is not empty,
drop useless nodes_intersects() in guarantee_online_mems() and
nodes_empty() in update_nodemasks_hier(), which both are O(N).
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
kernel/cgroup/cpuset.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 3e8cc34d8d50..e962efbb300d 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -456,9 +456,8 @@ static void guarantee_active_cpus(struct task_struct *tsk,
*/
static void guarantee_online_mems(struct cpuset *cs, nodemask_t *pmask)
{
- while (!nodes_intersects(cs->effective_mems, node_states[N_MEMORY]))
+ while (!nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]))
cs = parent_cs(cs);
- nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]);
}
/**
@@ -2862,13 +2861,13 @@ static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
cpuset_for_each_descendant_pre(cp, pos_css, cs) {
struct cpuset *parent = parent_cs(cp);
- nodes_and(*new_mems, cp->mems_allowed, parent->effective_mems);
+ bool has_mems = nodes_and(*new_mems, cp->mems_allowed, parent->effective_mems);
/*
* If it becomes empty, inherit the effective mask of the
* parent, which is guaranteed to have some MEMs.
*/
- if (is_in_v2_mode() && nodes_empty(*new_mems))
+ if (is_in_v2_mode() && !has_mems)
*new_mems = parent->effective_mems;
/* Skip the whole subtree if the nodemask remains the same. */
--
2.43.0
On Wed, Jan 14, 2026 at 12:22:15PM -0500, Yury Norov wrote: > Now that nodes_and() returns true if the result nodemask is not empty, > drop useless nodes_intersects() in guarantee_online_mems() and > nodes_empty() in update_nodemasks_hier(), which both are O(N). > > Signed-off-by: Yury Norov <ynorov@nvidia.com> Acked-by: Tejun Heo <tj@kernel.org> Please feel free to route together with the prerequisite patches. Thanks. -- tejun
On 1/14/26 12:22 PM, Yury Norov wrote:
> Now that nodes_and() returns true if the result nodemask is not empty,
> drop useless nodes_intersects() in guarantee_online_mems() and
> nodes_empty() in update_nodemasks_hier(), which both are O(N).
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
> ---
> kernel/cgroup/cpuset.c | 7 +++----
> 1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
> index 3e8cc34d8d50..e962efbb300d 100644
> --- a/kernel/cgroup/cpuset.c
> +++ b/kernel/cgroup/cpuset.c
> @@ -456,9 +456,8 @@ static void guarantee_active_cpus(struct task_struct *tsk,
> */
> static void guarantee_online_mems(struct cpuset *cs, nodemask_t *pmask)
> {
> - while (!nodes_intersects(cs->effective_mems, node_states[N_MEMORY]))
> + while (!nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]))
> cs = parent_cs(cs);
> - nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]);
> }
>
> /**
> @@ -2862,13 +2861,13 @@ static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
> cpuset_for_each_descendant_pre(cp, pos_css, cs) {
> struct cpuset *parent = parent_cs(cp);
>
> - nodes_and(*new_mems, cp->mems_allowed, parent->effective_mems);
> + bool has_mems = nodes_and(*new_mems, cp->mems_allowed, parent->effective_mems);
>
> /*
> * If it becomes empty, inherit the effective mask of the
> * parent, which is guaranteed to have some MEMs.
> */
> - if (is_in_v2_mode() && nodes_empty(*new_mems))
> + if (is_in_v2_mode() && !has_mems)
> *new_mems = parent->effective_mems;
>
> /* Skip the whole subtree if the nodemask remains the same. */
Reviewed-by: Waiman Long <longman@redhat.com>
On 2026/1/15 6:33, Waiman Long wrote:
> On 1/14/26 12:22 PM, Yury Norov wrote:
>> Now that nodes_and() returns true if the result nodemask is not empty,
>> drop useless nodes_intersects() in guarantee_online_mems() and
>> nodes_empty() in update_nodemasks_hier(), which both are O(N).
>>
>> Signed-off-by: Yury Norov <ynorov@nvidia.com>
>> ---
>> kernel/cgroup/cpuset.c | 7 +++----
>> 1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
>> index 3e8cc34d8d50..e962efbb300d 100644
>> --- a/kernel/cgroup/cpuset.c
>> +++ b/kernel/cgroup/cpuset.c
>> @@ -456,9 +456,8 @@ static void guarantee_active_cpus(struct task_struct *tsk,
>> */
>> static void guarantee_online_mems(struct cpuset *cs, nodemask_t *pmask)
>> {
>> - while (!nodes_intersects(cs->effective_mems, node_states[N_MEMORY]))
>> + while (!nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]))
>> cs = parent_cs(cs);
>> - nodes_and(*pmask, cs->effective_mems, node_states[N_MEMORY]);
>> }
>> /**
>> @@ -2862,13 +2861,13 @@ static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems)
>> cpuset_for_each_descendant_pre(cp, pos_css, cs) {
>> struct cpuset *parent = parent_cs(cp);
>> - nodes_and(*new_mems, cp->mems_allowed, parent->effective_mems);
>> + bool has_mems = nodes_and(*new_mems, cp->mems_allowed, parent->effective_mems);
>> /*
>> * If it becomes empty, inherit the effective mask of the
>> * parent, which is guaranteed to have some MEMs.
>> */
>> - if (is_in_v2_mode() && nodes_empty(*new_mems))
>> + if (is_in_v2_mode() && !has_mems)
>> *new_mems = parent->effective_mems;
>> /* Skip the whole subtree if the nodemask remains the same. */
> Reviewed-by: Waiman Long <longman@redhat.com>
>
Reviewed-by: Chen Ridong <chenridong@huaweicloud.com>
--
Best regards,
Ridong
On Wed, Jan 14, 2026 at 12:22:15PM -0500, Yury Norov <ynorov@nvidia.com> wrote: > Now that nodes_and() returns true if the result nodemask is not empty, > drop useless nodes_intersects() in guarantee_online_mems() and > nodes_empty() in update_nodemasks_hier(), which both are O(N). > > Signed-off-by: Yury Norov <ynorov@nvidia.com> > --- > kernel/cgroup/cpuset.c | 7 +++---- > 1 file changed, 3 insertions(+), 4 deletions(-) Nice improvement. Reviewed-by: Michal Koutný <mkoutny@suse.com>
On Wed, Jan 14, 2026 at 12:22:15PM -0500, Yury Norov wrote: > Now that nodes_and() returns true if the result nodemask is not empty, > drop useless nodes_intersects() in guarantee_online_mems() and > nodes_empty() in update_nodemasks_hier(), which both are O(N). > > Signed-off-by: Yury Norov <ynorov@nvidia.com> This is a nice simplification, thank you! Reviewed-by: Gregory Price <gourry@gourry.net>
© 2016 - 2026 Red Hat, Inc.