lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20211202003140.GA430494@lapt>
Date:   Wed, 1 Dec 2021 16:31:40 -0800
From:   Yury Norov <yury.norov@...il.com>
To:     Michał Mirosław <mirq-linux@...e.qmqm.pl>
Cc:     linux-kernel@...r.kernel.org,
        "James E.J. Bottomley" <jejb@...ux.ibm.com>,
        "Paul E. McKenney" <paulmck@...nel.org>,
        "Martin K. Petersen" <martin.petersen@...cle.com>,
        "Rafael J. Wysocki" <rafael@...nel.org>,
        Russell King <linux@...linux.org.uk>,
        Amitkumar Karwar <amitkarwar@...il.com>,
        Alexey Klimov <aklimov@...hat.com>,
        linux-alpha@...r.kernel.org,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Andy Gross <agross@...nel.org>,
        Mike Marciniszyn <mike.marciniszyn@...nelisnetworks.com>,
        Petr Mladek <pmladek@...e.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Andrew Lunn <andrew@...n.ch>, Andi Kleen <ak@...ux.intel.com>,
        Tejun Heo <tj@...nel.org>, Ard Biesheuvel <ardb@...nel.org>,
        Vlastimil Babka <vbabka@...e.cz>,
        Anup Patel <anup.patel@....com>, linux-ia64@...r.kernel.org,
        Andy Shevchenko <andy@...radead.org>,
        Andy Lutomirski <luto@...nel.org>,
        Matti Vaittinen <mazziesaccount@...il.com>,
        Mel Gorman <mgorman@...e.de>, Christoph Hellwig <hch@....de>,
        Palmer Dabbelt <palmer@...belt.com>,
        Catalin Marinas <catalin.marinas@....com>,
        Rasmus Villemoes <linux@...musvillemoes.dk>,
        Borislav Petkov <bp@...en8.de>, Arnd Bergmann <arnd@...db.de>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Stephen Rothwell <sfr@...b.auug.org.au>,
        David Laight <David.Laight@...lab.com>,
        Sunil Goutham <sgoutham@...vell.com>,
        David Airlie <airlied@...ux.ie>,
        Thomas Gleixner <tglx@...utronix.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>,
        Viresh Kumar <viresh.kumar@...aro.org>,
        Daniel Vetter <daniel@...ll.ch>,
        bcm-kernel-feedback-list@...adcom.com,
        Christoph Lameter <cl@...ux.com>, linux-crypto@...r.kernel.org,
        Hans de Goede <hdegoede@...hat.com>, linux-mm@...ck.org,
        Guo Ren <guoren@...nel.org>,
        linux-snps-arc@...ts.infradead.org,
        Geetha sowjanya <gakula@...vell.com>,
        Mark Rutland <mark.rutland@....com>,
        Dinh Nguyen <dinguyen@...nel.org>,
        Mauro Carvalho Chehab <mchehab@...nel.org>,
        Dennis Zhou <dennis@...nel.org>,
        Michael Ellerman <mpe@...erman.id.au>,
        Heiko Carstens <hca@...ux.ibm.com>,
        Nicholas Piggin <npiggin@...il.com>,
        Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
        Peter Zijlstra <peterz@...radead.org>,
        Geert Uytterhoeven <geert@...ux-m68k.org>,
        Randy Dunlap <rdunlap@...radead.org>,
        Roy Pledge <Roy.Pledge@....com>,
        Saeed Mahameed <saeedm@...dia.com>, Jens Axboe <axboe@...com>,
        Jason Wessel <jason.wessel@...driver.com>,
        Jakub Kicinski <kuba@...nel.org>,
        Sergey Senozhatsky <senozhatsky@...omium.org>,
        Ingo Molnar <mingo@...hat.com>,
        Stephen Boyd <sboyd@...nel.org>,
        Ian Rogers <irogers@...gle.com>,
        Steven Rostedt <rostedt@...dmis.org>,
        Sagi Grimberg <sagi@...mberg.me>,
        Sudeep Holla <sudeep.holla@....com>,
        Kalle Valo <kvalo@...eaurora.org>,
        Tariq Toukan <tariqt@...dia.com>,
        Juri Lelli <juri.lelli@...hat.com>,
        Thomas Bogendoerfer <tsbogend@...ha.franken.de>,
        Jonathan Cameron <jic23@...nel.org>,
        Ulf Hansson <ulf.hansson@...aro.org>,
        Jiri Olsa <jolsa@...hat.com>, Vineet Gupta <vgupta@...nel.org>,
        Solomon Peachy <pizza@...ftnet.org>,
        Vivien Didelot <vivien.didelot@...il.com>,
        Lee Jones <lee.jones@...aro.org>,
        Will Deacon <will@...nel.org>,
        Krzysztof Kozlowski <krzysztof.kozlowski@...onical.com>,
        kvm@...r.kernel.org, Kees Cook <keescook@...omium.org>,
        linux-arm-kernel@...ts.infradead.org,
        Subbaraya Sundeep <sbhatta@...vell.com>,
        linux-csky@...r.kernel.org, Marcin Wojtas <mw@...ihalf.com>,
        linux-mips@...r.kernel.org, Marc Zyngier <maz@...nel.org>,
        linux-perf-users@...r.kernel.org,
        Vincent Guittot <vincent.guittot@...aro.org>,
        linux-s390@...r.kernel.org, Mark Gross <markgross@...nel.org>,
        linux-riscv@...ts.infradead.org, linuxppc-dev@...ts.ozlabs.org
Subject: Re: [PATCH 0/9] lib/bitmap: optimize bitmap_weight() usage

On Mon, Nov 29, 2021 at 04:34:07PM +0000, Michał Mirosław wrote:
> Dnia 29 listopada 2021 06:38:39 UTC, Yury Norov <yury.norov@...il.com> napisał/a:
> >On Sun, Nov 28, 2021 at 07:03:41PM +0100, mirq-test@...e.qmqm.pl 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

Indeed, thanks for pointing to it.
 
> It would still be more readable, I think.

To be honest, I'm not sure that
        bitmap_weight_cmp(..., N-1) <= 0
would be an obvious replacement for the original
        bitmap_weight(...) < N
comparing to 
        bitmap_weight_lt(..., N)

I think the best thing I can do is to add bitmap_weight_cmp() as
you suggested, and turn lt and others to be wrappers on it. This
will let people choose a better function in each case.

I also think that for v2 it would be better to drop the conversion
for short bitmaps, except for switching to bitmap_empty(), because
in that case readability wins over performance; if no objections. 

Thanks,
Yury

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ