* [PATCH 0/3] nodemask: align nodes_and{,not} with underlying bitmap ops
@ 2026-01-14 17:22 Yury Norov
2026-01-14 17:22 ` [PATCH 1/3] nodemask: propagate boolean for nodes_and{,not} Yury Norov
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Yury Norov @ 2026-01-14 17:22 UTC (permalink / raw)
To: Andrew Morton, Alistair Popple, Byungchul Park,
David Hildenbrand, Gregory Price, Johannes Weiner, Joshua Hahn,
Liam R. Howlett, Lorenzo Stoakes, Matthew Brost, Michal Hocko,
Michal Koutný,
Mike Rapoport, Rakie Kim, Suren Baghdasaryan, Tejun Heo,
Vlastimil Babka, Waiman Long, Ying Huang, Zi Yan, cgroups
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, linux-mm, linux-kernel
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(-)
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/3] nodemask: propagate boolean for nodes_and{,not}
2026-01-14 17:22 [PATCH 0/3] nodemask: align nodes_and{,not} with underlying bitmap ops Yury Norov
@ 2026-01-14 17:22 ` Yury Norov
2026-01-14 17:56 ` Gregory Price
2026-01-14 17:22 ` [PATCH 2/3] mm: use nodes_and() return value to simplify client code Yury Norov
2026-01-14 17:22 ` [PATCH 3/3] cgroup: use nodes_and() output where appropriate Yury Norov
2 siblings, 1 reply; 7+ messages in thread
From: Yury Norov @ 2026-01-14 17:22 UTC (permalink / raw)
To: Andrew Morton, Alistair Popple, Byungchul Park,
David Hildenbrand, Gregory Price, Johannes Weiner, Joshua Hahn,
Liam R. Howlett, Lorenzo Stoakes, Matthew Brost, Michal Hocko,
Michal Koutný,
Mike Rapoport, Rakie Kim, Suren Baghdasaryan, Tejun Heo,
Vlastimil Babka, Waiman Long, Ying Huang, Zi Yan, cgroups
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, linux-mm, linux-kernel
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 <ynorov@nvidia.com>
---
include/linux/nodemask.h | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h
index bd38648c998d..204c92462f3c 100644
--- a/include/linux/nodemask.h
+++ b/include/linux/nodemask.h
@@ -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)
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] mm: use nodes_and() return value to simplify client code
2026-01-14 17:22 [PATCH 0/3] nodemask: align nodes_and{,not} with underlying bitmap ops Yury Norov
2026-01-14 17:22 ` [PATCH 1/3] nodemask: propagate boolean for nodes_and{,not} Yury Norov
@ 2026-01-14 17:22 ` Yury Norov
2026-01-14 17:56 ` Gregory Price
2026-01-14 17:22 ` [PATCH 3/3] cgroup: use nodes_and() output where appropriate Yury Norov
2 siblings, 1 reply; 7+ messages in thread
From: Yury Norov @ 2026-01-14 17:22 UTC (permalink / raw)
To: Andrew Morton, Alistair Popple, Byungchul Park,
David Hildenbrand, Gregory Price, Johannes Weiner, Joshua Hahn,
Liam R. Howlett, Lorenzo Stoakes, Matthew Brost, Michal Hocko,
Michal Koutný,
Mike Rapoport, Rakie Kim, Suren Baghdasaryan, Tejun Heo,
Vlastimil Babka, Waiman Long, Ying Huang, Zi Yan, cgroups
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, linux-mm, linux-kernel
establish_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.
Signed-off-by: Yury Norov <ynorov@nvidia.com>
---
mm/memory-tiers.c | 3 +--
mm/mempolicy.c | 3 +--
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/mm/memory-tiers.c b/mm/memory-tiers.c
index 864811fff409..2cbef49a587d 100644
--- a/mm/memory-tiers.c
+++ b/mm/memory-tiers.c
@@ -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.
diff --git a/mm/mempolicy.c b/mm/mempolicy.c
index 68a98ba57882..92a0bf7619a2 100644
--- a/mm/mempolicy.c
+++ b/mm/mempolicy.c
@@ -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);
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] cgroup: use nodes_and() output where appropriate
2026-01-14 17:22 [PATCH 0/3] nodemask: align nodes_and{,not} with underlying bitmap ops Yury Norov
2026-01-14 17:22 ` [PATCH 1/3] nodemask: propagate boolean for nodes_and{,not} Yury Norov
2026-01-14 17:22 ` [PATCH 2/3] mm: use nodes_and() return value to simplify client code Yury Norov
@ 2026-01-14 17:22 ` Yury Norov
2026-01-14 18:00 ` Gregory Price
2 siblings, 1 reply; 7+ messages in thread
From: Yury Norov @ 2026-01-14 17:22 UTC (permalink / raw)
To: Andrew Morton, Alistair Popple, Byungchul Park,
David Hildenbrand, Gregory Price, Johannes Weiner, Joshua Hahn,
Liam R. Howlett, Lorenzo Stoakes, Matthew Brost, Michal Hocko,
Michal Koutný,
Mike Rapoport, Rakie Kim, Suren Baghdasaryan, Tejun Heo,
Vlastimil Babka, Waiman Long, Ying Huang, Zi Yan, cgroups
Cc: Yury Norov, Yury Norov, Rasmus Villemoes, linux-mm, linux-kernel
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
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] nodemask: propagate boolean for nodes_and{,not}
2026-01-14 17:22 ` [PATCH 1/3] nodemask: propagate boolean for nodes_and{,not} Yury Norov
@ 2026-01-14 17:56 ` Gregory Price
0 siblings, 0 replies; 7+ messages in thread
From: Gregory Price @ 2026-01-14 17:56 UTC (permalink / raw)
To: Yury Norov
Cc: Andrew Morton, Alistair Popple, Byungchul Park,
David Hildenbrand, Johannes Weiner, Joshua Hahn, Liam R. Howlett,
Lorenzo Stoakes, Matthew Brost, Michal Hocko, Michal Koutný,
Mike Rapoport, Rakie Kim, Suren Baghdasaryan, Tejun Heo,
Vlastimil Babka, Waiman Long, Ying Huang, Zi Yan, cgroups,
Yury Norov, Rasmus Villemoes, linux-mm, linux-kernel
On Wed, Jan 14, 2026 at 12:22:13PM -0500, Yury Norov wrote:
> 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 <ynorov@nvidia.com>
Reviewed-by: Gregory Price <gourry@gourry.net>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/3] mm: use nodes_and() return value to simplify client code
2026-01-14 17:22 ` [PATCH 2/3] mm: use nodes_and() return value to simplify client code Yury Norov
@ 2026-01-14 17:56 ` Gregory Price
0 siblings, 0 replies; 7+ messages in thread
From: Gregory Price @ 2026-01-14 17:56 UTC (permalink / raw)
To: Yury Norov
Cc: Andrew Morton, Alistair Popple, Byungchul Park,
David Hildenbrand, Johannes Weiner, Joshua Hahn, Liam R. Howlett,
Lorenzo Stoakes, Matthew Brost, Michal Hocko, Michal Koutný,
Mike Rapoport, Rakie Kim, Suren Baghdasaryan, Tejun Heo,
Vlastimil Babka, Waiman Long, Ying Huang, Zi Yan, cgroups,
Yury Norov, Rasmus Villemoes, linux-mm, linux-kernel
On Wed, Jan 14, 2026 at 12:22:14PM -0500, Yury Norov wrote:
> establish_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.
>
> Signed-off-by: Yury Norov <ynorov@nvidia.com>
Reviewed-by: Gregory Price <gourry@gourry.net>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 3/3] cgroup: use nodes_and() output where appropriate
2026-01-14 17:22 ` [PATCH 3/3] cgroup: use nodes_and() output where appropriate Yury Norov
@ 2026-01-14 18:00 ` Gregory Price
0 siblings, 0 replies; 7+ messages in thread
From: Gregory Price @ 2026-01-14 18:00 UTC (permalink / raw)
To: Yury Norov
Cc: Andrew Morton, Alistair Popple, Byungchul Park,
David Hildenbrand, Johannes Weiner, Joshua Hahn, Liam R. Howlett,
Lorenzo Stoakes, Matthew Brost, Michal Hocko, Michal Koutný,
Mike Rapoport, Rakie Kim, Suren Baghdasaryan, Tejun Heo,
Vlastimil Babka, Waiman Long, Ying Huang, Zi Yan, cgroups,
Yury Norov, Rasmus Villemoes, linux-mm, linux-kernel
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>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-01-14 18:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-14 17:22 [PATCH 0/3] nodemask: align nodes_and{,not} with underlying bitmap ops Yury Norov
2026-01-14 17:22 ` [PATCH 1/3] nodemask: propagate boolean for nodes_and{,not} Yury Norov
2026-01-14 17:56 ` Gregory Price
2026-01-14 17:22 ` [PATCH 2/3] mm: use nodes_and() return value to simplify client code Yury Norov
2026-01-14 17:56 ` Gregory Price
2026-01-14 17:22 ` [PATCH 3/3] cgroup: use nodes_and() output where appropriate Yury Norov
2026-01-14 18:00 ` Gregory Price
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox