[PATCH 1/9] lib/bitmap: add bitmap_weight_{eq,gt,le}

2021-11-27 Thread Yury Norov
Many kernel users call bitmap_weight() to compare the result against some number or expression: if (bitmap_weight(...) > 1) do_something(); It works OK, but may be significantly improved for large bitmaps: if first few words count set bits to a number greater than given, we

[PATCH 0/9] lib/bitmap: optimize bitmap_weight() usage

2021-11-27 Thread Yury Norov
In many cases people use bitmap_weight()-based functions like this: if (num_present_cpus() > 1) do_something(); This may take considerable amount of time on many-cpus machines because num_present_cpus() will traverse every word of underlying cpumask unconditionally. We ca

[PATCH 2/9] lib/bitmap: implement bitmap_{empty, full} with bitmap_weight_eq()

2021-11-27 Thread Yury Norov
Now as we have bitmap_weight_eq(), switch bitmap_full() and bitmap_empty() to using it. Signed-off-by: Yury Norov --- include/linux/bitmap.h | 26 ++ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 9960

[PATCH 4/9] tools: sync bitmap_weight() usage with the kernel

2021-11-27 Thread Yury Norov
bitmap_weight() counts all set bits in the bitmap unconditionally. However in some cases we can traverse a part of bitmap when we only need to check if number of set bits is greater, less or equal to some number. This patch adds bitmap_weight_{eq,gt,le}, reimplements bitmap_{empty,full} and replac

[PATCH 3/9] all: replace bitmap_weigth() with bitmap_{empty, full, eq, gt, le}

2021-11-27 Thread Yury Norov
bitmap_weight() counts all set bits in the bitmap unconditionally. However in some cases we can traverse a part of bitmap when we only need to check if number of set bits is greater, less or equal to some number. This patch replaces bitmap_weight() with one of bitmap_{empty,full,eq,gt,le), as appr

[PATCH 5/9] lib/cpumask: add cpumask_weight_{eq,gt,le}

2021-11-27 Thread Yury Norov
Add cpumask_weight_{eq,gt,le} and replace cpumask_weight() with one of cpumask_weight_{empty,eq,gt,le} where appropriate. This allows cpumask_weight_*() to return earlier depending on the condition. Signed-off-by: Yury Norov --- arch/alpha/kernel/process.c | 2 +- arch/ia64/kernel/

[PATCH 6/9] lib/nodemask: add nodemask_weight_{eq,gt,le}

2021-11-27 Thread Yury Norov
Add nodemask_weight_{eq,gt,le} and replace nodemask_weight() where appropriate. This allows nodemask_weight_*() to return earlier depending on the condition. Signed-off-by: Yury Norov --- arch/x86/mm/amdtopology.c| 2 +- arch/x86/mm/numa_emulation.c | 4 ++-- drivers/acpi/numa/srat.c |

[PATCH 8/9] lib/nodemask: add num_node_state_eq()

2021-11-27 Thread Yury Norov
Add num_node_state_eq() and replace num_node_state() with it in page_alloc_init(). Signed-off-by: Yury Norov --- include/linux/nodemask.h | 5 + mm/page_alloc.c | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/include/linux/nodemask.h b/include/linux/nodemask.h

[PATCH 9/9] MAINTAINERS: add cpumask and nodemask files to BITMAP_API

2021-11-27 Thread Yury Norov
cpumask and nodemask APIs are thin wrappers around basic bitmap API, and corresponding files are not formally maintained. This patch adds them to BITMAP_API section, so that bitmap folks would have closer look at it. Signed-off-by: Yury Norov --- MAINTAINERS | 4 1 file changed, 4 insertion

[PATCH 7/9] lib/cpumask: add num_{possible, present, active}_cpus_{eq, gt, le}

2021-11-27 Thread Yury Norov
Add num_{possible,present,active}_cpus_{eq,gt,le} and replace num_*_cpus() with one of new functions where appropriate. This allows num_*_cpus_*() to return earlier depending on the condition. Signed-off-by: Yury Norov --- arch/arc/kernel/smp.c | 2 +- arch/arm/kernel/ma

Re: [PATCH 2/9] lib/bitmap: implement bitmap_{empty,full} with bitmap_weight_eq()

2021-11-27 Thread Yury Norov
On Sun, Nov 28, 2021 at 05:37:19AM +0100, Michał Mirosław wrote: > On Sat, Nov 27, 2021 at 07:56:57PM -0800, Yury Norov wrote: > > Now as we have bitmap_weight_eq(), switch bitmap_full() and > > bitmap_empty() to using it. > [...] > > -static inline bool bitmap_empty(const unsigned long *src, unsig

Re: [PATCH 7/9] lib/cpumask: add num_{possible,present,active}_cpus_{eq,gt,le}

2021-11-27 Thread Yury Norov
(restore CC list) On Sun, Nov 28, 2021 at 05:56:51AM +0100, Michał Mirosław wrote: > On Sat, Nov 27, 2021 at 07:57:02PM -0800, Yury Norov wrote: > > Add num_{possible,present,active}_cpus_{eq,gt,le} and replace num_*_cpus() > > with one of new functions where appropriate. This allows num_*_cpus_*(