Re: [PATCH 0/9] lib/bitmap: optimize bitmap_weight() usage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
- To: Yury Norov <yury.norov@xxxxxxxxx>
- Subject: Re: [PATCH 0/9] lib/bitmap: optimize bitmap_weight() usage
- From: Michał Mirosław <mirq-linux@xxxxxxxxxxxx>
- Date: Mon, 29 Nov 2021 16:34:07 +0000
- Cc: linux-kernel@xxxxxxxxxxxxxxx, "James E.J. Bottomley" <jejb@xxxxxxxxxxxxx>, "Paul E. McKenney" <paulmck@xxxxxxxxxx>, "Martin K. Petersen" <martin.petersen@xxxxxxxxxx>, "Rafael J. Wysocki" <rafael@xxxxxxxxxx>, Russell King <linux@xxxxxxxxxxxxxxx>, Amitkumar Karwar <amitkarwar@xxxxxxxxx>, Alexey Klimov <aklimov@xxxxxxxxxx>, linux-alpha@xxxxxxxxxxxxxxx, Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>, Andy Gross <agross@xxxxxxxxxx>, Mike Marciniszyn <mike.marciniszyn@xxxxxxxxxxxxxxxxxxxx>, Petr Mladek <pmladek@xxxxxxxx>, Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>, Andrew Lunn <andrew@xxxxxxx>, Andi Kleen <ak@xxxxxxxxxxxxxxx>, Tejun Heo <tj@xxxxxxxxxx>, Ard Biesheuvel <ardb@xxxxxxxxxx>, Vlastimil Babka <vbabka@xxxxxxx>, Anup Patel <anup.patel@xxxxxxx>, linux-ia64@xxxxxxxxxxxxxxx, Andy Shevchenko <andy@xxxxxxxxxxxxx>, Andy Lutomirski <luto@xxxxxxxxxx>, Matti Vaittinen <mazziesaccount@xxxxxxxxx>, Mel Gorman <mgorman@xxxxxxx>, Christoph Hellwig <hch@xxxxxx>, Palmer Dabbelt <palmer@xxxxxxxxxxx>, Catalin Marinas <catalin.marinas@xxxxxxx>, Rasmus Villemoes <linux@xxxxxxxxxxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, Arnd Bergmann <arnd@xxxxxxxx>, Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>, Stephen Rothwell <sfr@xxxxxxxxxxxxxxxx>, David Laight <David.Laight@xxxxxxxxxx>, Sunil Goutham <sgoutham@xxxxxxxxxxx>, David Airlie <airlied@xxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, Viresh Kumar <viresh.kumar@xxxxxxxxxx>, Daniel Vetter <daniel@xxxxxxxx>, bcm-kernel-feedback-list@xxxxxxxxxxxx, Christoph Lameter <cl@xxxxxxxxx>, linux-crypto@xxxxxxxxxxxxxxx, Hans de Goede <hdegoede@xxxxxxxxxx>, linux-mm@xxxxxxxxx, Guo Ren <guoren@xxxxxxxxxx>, linux-snps-arc@xxxxxxxxxxxxxxxxxxx, Geetha sowjanya <gakula@xxxxxxxxxxx>, Mark Rutland <mark.rutland@xxxxxxx>, Dinh Nguyen <dinguyen@xxxxxxxxxx>, Mauro Carvalho Chehab <mchehab@xxxxxxxxxx>, Dennis Zhou <dennis@xxxxxxxxxx>, Michael Ellerman <mpe@xxxxxxxxxxxxxx>, Heiko Carstens <hca@xxxxxxxxxxxxx>, Nicholas Piggin <npiggin@xxxxxxxxx>, Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>, Peter Zijlstra <peterz@xxxxxxxxxxxxx>, Geert Uytterhoeven <geert@xxxxxxxxxxxxxx>, Randy Dunlap <rdunlap@xxxxxxxxxxxxx>, Roy Pledge <Roy.Pledge@xxxxxxx>, Saeed Mahameed <saeedm@xxxxxxxxxx>, Jens Axboe <axboe@xxxxxx>, Jason Wessel <jason.wessel@xxxxxxxxxxxxx>, Jakub Kicinski <kuba@xxxxxxxxxx>, Sergey Senozhatsky <senozhatsky@xxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Stephen Boyd <sboyd@xxxxxxxxxx>, Ian Rogers <irogers@xxxxxxxxxx>, Steven Rostedt <rostedt@xxxxxxxxxxx>, Sagi Grimberg <sagi@xxxxxxxxxxx>, Sudeep Holla <sudeep.holla@xxxxxxx>, Kalle Valo <kvalo@xxxxxxxxxxxxxx>, Tariq Toukan <tariqt@xxxxxxxxxx>, Juri Lelli <juri.lelli@xxxxxxxxxx>, Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx>, Jonathan Cameron <jic23@xxxxxxxxxx>, Ulf Hansson <ulf.hansson@xxxxxxxxxx>, Jiri Olsa <jolsa@xxxxxxxxxx>, Vineet Gupta <vgupta@xxxxxxxxxx>, Solomon Peachy <pizza@xxxxxxxxxxxx>, Vivien Didelot <vivien.didelot@xxxxxxxxx>, Lee Jones <lee.jones@xxxxxxxxxx>, Will Deacon <will@xxxxxxxxxx>, Krzysztof Kozlowski <krzysztof.kozlowski@xxxxxxxxxxxxx>, kvm@xxxxxxxxxxxxxxx, Kees Cook <keescook@xxxxxxxxxxxx>, linux-arm-kernel@xxxxxxxxxxxxxxxxxxx, Subbaraya Sundeep <sbhatta@xxxxxxxxxxx>, linux-csky@xxxxxxxxxxxxxxx, Marcin Wojtas <mw@xxxxxxxxxxxx>, linux-mips@xxxxxxxxxxxxxxx, Marc Zyngier <maz@xxxxxxxxxx>, linux-perf-users@xxxxxxxxxxxxxxx, Vincent Guittot <vincent.guittot@xxxxxxxxxx>, linux-s390@xxxxxxxxxxxxxxx, Mark Gross <markgross@xxxxxxxxxx>, linux-riscv@xxxxxxxxxxxxxxxxxxx, linuxppc-dev@xxxxxxxxxxxxxxxx
- In-reply-to: <20211129063839.GA338729@lapt>
- References: <20211128035704.270739-1-yury.norov@gmail.com> <YaPEfZ0t9UFGwpml@qmqm.qmqm.pl> <20211129063839.GA338729@lapt>
- User-agent: K-9 Mail for Android
Dnia 29 listopada 2021 06:38:39 UTC, Yury Norov <yury.norov@xxxxxxxxx> napisał/a:
>On Sun, Nov 28, 2021 at 07:03:41PM +0100, mirq-test@xxxxxxxxxxxx wrote:
>> On Sat, Nov 27, 2021 at 07:56:55PM -0800, Yury Norov wrote:
>> > 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 can significantly improve on it for many real cases if stop traversing
>> > the mask as soon as we count present cpus to any number greater than 1:
>> >
>> > if (num_present_cpus_gt(1))
>> > do_something();
>> >
>> > To implement this idea, the series adds bitmap_weight_{eq,gt,le}
>> > functions together with corresponding wrappers in cpumask and nodemask.
>>
>> Having slept on it I have more structured thoughts:
>>
>> First, I like substituting bitmap_empty/full where possible - I think
>> the change stands on its own, so could be split and sent as is.
>
>Ok, I can do it.
>
>> I don't like the proposed API very much. One problem is that it hides
>> the comparison operator and makes call sites less readable:
>>
>> bitmap_weight(...) > N
>>
>> becomes:
>>
>> bitmap_weight_gt(..., N)
>>
>> and:
>> bitmap_weight(...) <= N
>>
>> becomes:
>>
>> bitmap_weight_lt(..., N+1)
>> or:
>> !bitmap_weight_gt(..., N)
>>
>> I'd rather see something resembling memcmp() API that's known enough
>> to be easier to grasp. For above examples:
>>
>> bitmap_weight_cmp(..., N) > 0
>> bitmap_weight_cmp(..., N) <= 0
>> ...
>
>bitmap_weight_cmp() cannot be efficient. Consider this example:
>
>bitmap_weight_lt(1000 0000 0000 0000, 1) == false
> ^
> stop here
>
>bitmap_weight_cmp(1000 0000 0000 0000, 1) == 0
> ^
> stop here
>
>I agree that '_gt' is less verbose than '>', but the advantage of
>'_gt' over '>' is proportional to length of bitmap, and it means
>that this API should exist.
Thank you for the example. Indeed, for less-than to be efficient here you would need to replace
bitmap_weight_cmp(..., N) < 0
with
bitmap_weight_cmp(..., N-1) <= 0
It would still be more readable, I think.
Best Regards
Michał Mirosław
[Index of Archives]
[Linux Kernel]
[Sparc Linux]
[DCCP]
[Linux ARM]
[Yosemite News]
[Linux SCSI]
[Linux x86_64]
[Linux for Ham Radio]