nodemask: align nodes_and{,not} with underlying bitmap ops
Subsystems (5)
cover nodemask: align nodes_and{,not} with underlying bitmap ops
nodes_and{,not} are void despite that underlying bitmap_and(,not) return boolean, true if the result bitmap is non-empty. Align nodemask API, and simplify client code.
Yury Norov (3):
nodemask: propagate boolean for nodes_and{,not}
mm: use nodes_and() return value to simplify client code
cgroup: use nodes_and() output where appropriate
include/linux/nodemask.h | 8 ++++---- kernel/cgroup/cpuset.c | 7 +++---- mm/memory-tiers.c | 3 +-- mm/mempolicy.c | 3 +-- 4 files changed, 9 insertions(+), 12 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/3 nodemask: propagate boolean for nodes_and{,not}
Bitmap functions bitmap_and{,not} return boolean depending on emptiness of the result bitmap. The corresponding nodemask helpers ignore the returned value.
Propagate the underlying bitmaps result to nodemasks users, as it simplifies user code.
--- include/linux/nodemask.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
include/linux/nodemask.h +4 -4
@@ -157,10 +157,10 @@ static __always_inline bool __node_test_and_set(int node, nodemask_t *addr)#define nodes_and (dst, src1, src2) \ __nodes_and(&(dst), &(src1), &(src2), MAX_NUMNODES) -static __always_inline void __nodes_and(nodemask_t *dstp, const nodemask_t *src1p, +static __always_inline bool __nodes_and(nodemask_t *dstp, const nodemask_t *src1p,const nodemask_t *src2p,unsigned int nbits) { -bitmap_and (dstp->bits, src1p->bits, src2p->bits, nbits); +return bitmap_and (dstp->bits, src1p->bits, src2p->bits, nbits); }#define nodes_or (dst, src1, src2) \
@@ -181,10 +181,10 @@ static __always_inline void __nodes_xor(nodemask_t *dstp, const nodemask_t *src1#define nodes_andnot (dst, src1, src2) \ __nodes_andnot(&(dst), &(src1), &(src2), MAX_NUMNODES) -static __always_inline void __nodes_andnot(nodemask_t *dstp, const nodemask_t *src1p, +static __always_inline bool __nodes_andnot(nodemask_t *dstp, const nodemask_t *src1p,const nodemask_t *src2p,unsigned int nbits) { -bitmap_andnot (dstp->bits, src1p->bits, src2p->bits, nbits); +return bitmap_andnot (dstp->bits, src1p->bits, src2p->bits, nbits); }#define nodes_copy (dst, src) __nodes_copy(&(dst), &(src), MAX_NUMNODES)
Signature · 1 line
2.43.0
Re: [PATCH 1/3] nodemask: propagate boolean for nodes_and{,not}
Quoted 8 lines · Yury Norov
Bitmap functions bitmap_and{,not} return boolean depending on emptiness of the result bitmap. The corresponding nodemask helpers ignore the returned value.
Propagate the underlying bitmaps result to nodemasks users, as it simplifies user code.
Signed-off-by Yury Norov <[email protected]>
Re: [PATCH 1/3] nodemask: propagate boolean for nodes_and{,not}
In reply to Yury NorovQuoted 9 lines · Yury Norov
Bitmap functions bitmap_and{,not} return boolean depending on emptiness of the result bitmap. The corresponding nodemask helpers ignore the returned value.
Propagate the underlying bitmaps result to nodemasks users, as it simplifies user code.
Signed-off-by Yury Norov <[email protected]>---
Signature · 3 lines
Cheers David
PATCH 2/3 mm: use nodes_and() return value to simplify client code
In reply to Yury Norovestablish_demotion_targets() and kernel_migrate_pages() call node_empty() immediately after calling nodes_and(). Now that nodes_and() return false if nodemask is empty, drop the latter.
--- mm/memory-tiers.c | 3 +-- mm/mempolicy.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
mm/memory-tiers.c +1 -2
@@ -475,8 +475,7 @@ static void establish_demotion_targets(void)*/ list_for_each_entry_reverse (memtier, &memory_tiers, list) { tier_nodes =get_memtier_nodemask (memtier); -nodes_and (tier_nodes, node_states[N_CPU ], tier_nodes); -if (!nodes_empty (tier_nodes)) { +if (nodes_and (tier_nodes, node_states[N_CPU ], tier_nodes)) {/* * abstract distance below the max value of this memtier * is considered toptier.
mm/mempolicy.c +1 -2
@@ -1909,8 +1909,7 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode, } task_nodes =cpuset_mems_allowed (current); -nodes_and (*new, *new, task_nodes); -if (nodes_empty (*new)) +if (!nodes_and (*new, *new, task_nodes)) goto out_put; err =security_task_movememory (task);
Signature · 1 line
2.43.0
Re: [PATCH 2/3] mm: use nodes_and() return value to simplify client code
Quoted 5 lines · Yury Norov
establish_demotion_targets()andkernel_migrate_pages()callnode_empty()immediately after callingnodes_and(). Now thatnodes_and()return false if nodemask is empty, drop the latter.Signed-off-by Yury Norov <[email protected]>
Re: [PATCH 2/3] mm: use nodes_and() return value to simplify client code
In reply to Yury NorovQuoted 5 lines · Yury Norov
establish_demotion_targets()andkernel_migrate_pages()callnode_empty()immediately after callingnodes_and(). Now thatnodes_and()return false if nodemask is empty, drop the latter.Signed-off-by Yury Norov <[email protected]>
Quoted 33 lines
--- mm/memory-tiers.c | 3 +-- mm/mempolicy.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)mm/memory-tiers.c +1
-2@@ -475,8 +475,7 @@ static void establish_demotion_targets(void)*/ list_for_each_entry_reverse (memtier, &memory_tiers, list) { tier_nodes =get_memtier_nodemask (memtier); -nodes_and (tier_nodes, node_states[N_CPU ], tier_nodes); -if (!nodes_empty (tier_nodes)) { +if (nodes_and (tier_nodes, node_states[N_CPU ], tier_nodes)) {/* * abstract distance below the max value of this memtier * is considered toptier. mm/mempolicy.c +1
-2@@ -1909,8 +1909,7 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode, } task_nodes =cpuset_mems_allowed (current); -nodes_and (*new, *new, task_nodes); -if (nodes_empty (*new)) +if (!nodes_and (*new, *new, task_nodes)) goto out_put; err =security_task_movememory (task);
Re: [PATCH 2/3] mm: use nodes_and() return value to simplify client code
In reply to Yury NorovQuoted 5 lines · Yury Norov
establish_demotion_targets()andkernel_migrate_pages()callnode_empty()immediately after callingnodes_and(). Now thatnodes_and()return false if nodemask is empty, drop the latter.Signed-off-by Yury Norov <[email protected]>
Signature · 3 lines
Cheers David
PATCH 3/3 cgroup: use nodes_and() output where appropriate
In reply to Yury NorovNow 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).
--- kernel/cgroup/cpuset.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
kernel/cgroup/cpuset.c +3 -4
@@ -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. */
Signature · 1 line
2.43.0
Re: [PATCH 3/3] cgroup: use nodes_and() output where appropriate
Quoted 5 lines · Yury Norov
Now that
nodes_and()returns true if the result nodemask is not empty, drop uselessnodes_intersects()inguarantee_online_mems()andnodes_empty()inupdate_nodemasks_hier(), which both are O(N).Signed-off-by Yury Norov <[email protected]>
This is a nice simplification, thank you!
Re: [PATCH 3/3] cgroup: use nodes_and() output where appropriate
In reply to Yury NorovQuoted 8 lines · Yury Norov
Now that
nodes_and()returns true if the result nodemask is not empty, drop uselessnodes_intersects()inguarantee_online_mems()andnodes_empty()inupdate_nodemasks_hier(), which both are O(N).Signed-off-by Yury Norov <[email protected]>--- kernel/cgroup/cpuset.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
Nice improvement.
Re: [PATCH 3/3] cgroup: use nodes_and() output where appropriate
In reply to Yury NorovQuoted 30 lines · Yury Norov
Now that
nodes_and()returns true if the result nodemask is not empty, drop uselessnodes_intersects()inguarantee_online_mems()andnodes_empty()inupdate_nodemasks_hier(), which both are O(N).Signed-off-by Yury Norov <[email protected]>--- kernel/cgroup/cpuset.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)kernel/cgroup/cpuset.c +2
-3@@ -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);
kernel/cgroup/cpuset.c static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems) · line 2873
Quoted 10 lines
kernel/cgroup/cpuset.c +1
-1/* * 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. */
Chen Ridong
Reviewed-byRe: [PATCH 3/3] cgroup: use nodes_and() output where appropriate
Quoted 30 lines · Waiman Long
Quoted 29 lines · Yury Norov
Now that
nodes_and()returns true if the result nodemask is not empty, drop uselessnodes_intersects()inguarantee_online_mems()andnodes_empty()inupdate_nodemasks_hier(), which both are O(N).Signed-off-by Yury Norov <[email protected]>---
kernel/cgroup/cpuset.c| 7 +++----1 file changed, 3 insertions(+), 4 deletions(-)kernel/cgroup/cpuset.c +2
-2@@ -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); /*
Quoted 9 lines
kernel/cgroup/cpuset.c static void update_nodemasks_hier(struct cpuset *cs, nodemask_t *new_mems) · line 2873
Quoted 7 lines
kernel/cgroup/cpuset.c +1
-1* 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 <[email protected]>
Signature · 2 lines
Best regards, Ridong
Re: [PATCH 3/3] cgroup: use nodes_and() output where appropriate
In reply to Yury NorovQuoted 5 lines · Yury Norov
Now that
nodes_and()returns true if the result nodemask is not empty, drop uselessnodes_intersects()inguarantee_online_mems()andnodes_empty()inupdate_nodemasks_hier(), which both are O(N).Signed-off-by Yury Norov <[email protected]>
Please feel free to route together with the prerequisite patches.
Thanks.
Signature · 1 line
tejun
Quoted 9 lines · On Wed, 14 Jan 2026 12:22:12 -0500 Yury Norov <[email protected]> wrote:
nodes_and{,not} are void despite that underlying
bitmap_and(,not)return boolean, true if the result bitmap is non-empty. Align nodemask API, and simplify client code.Yury Norov (3):
nodemask: propagate boolean for nodes_and{,not}
mm: usenodes_and()return value to simplify client code
cgroup: usenodes_and()output where appropriate
Quoted 8 lines
include/linux/nodemask.h | 8 ++++---- kernel/cgroup/cpuset.c | 7 +++---- mm/memory-tiers.c | 3 +-- mm/mempolicy.c | 3 +-- 4 files changed, 9 insertions(+), 12 deletions(-)Signature · 1 line
2.43.0
The entire set LGTM, thank you for this patchset! Feel free to add:
For the entire series. Have a great day!
Joshua