From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A73FC433EF for ; Sun, 28 Nov 2021 23:36:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1C77A6B006C; Sun, 28 Nov 2021 18:36:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 19EAB6B0071; Sun, 28 Nov 2021 18:36:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 017EA6B0072; Sun, 28 Nov 2021 18:36:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id E5B186B006C for ; Sun, 28 Nov 2021 18:36:40 -0500 (EST) Received: from smtpin28.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id A86EA886ED for ; Sun, 28 Nov 2021 23:36:30 +0000 (UTC) X-FDA: 78859950498.28.8ABFB7C Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by imf27.hostedemail.com (Postfix) with ESMTP id C0F9070000B9 for ; Sun, 28 Nov 2021 23:36:28 +0000 (UTC) Received: by mail-qk1-f169.google.com with SMTP id i9so20967351qki.3 for ; Sun, 28 Nov 2021 15:36:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=+pvPLMMOaG75eXeO+MYWVtFy7p98nfe1U4iD6DUFgqs=; b=FqHxiwrQ7QYivLGpovhQrNQCHUCj7LxMV2WH4G2Ujzkjgck5ZuLpYg6YmyS5/pcjd8 PioI6TsqEy6uPfhoz8wEavEgHnpCryLeBpBEb8dr5G6s12WteiFVLQFxrBR47EVsTB3X ndIWwpq8YabRGonzz7m7f+N7UJXzBMp2vfRHxXo9M1u6ZB6qiEh6DrJAZ2z7gRkAQ5sC IqRPeZsbgWqH6z7gZV/iyVzYOISv9QQ48jjOTsL+5HMXkolOWVbHK0gj+h+Ra3+OPnrQ HZwGnjmshXRb1nFHqTfVME98Ezv2622Zg9Ol7LGc837jR3cjnZ1W8PCl/MaA7m1eTWjV ggTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=+pvPLMMOaG75eXeO+MYWVtFy7p98nfe1U4iD6DUFgqs=; b=q2J3w1rWJ6miUiqGmxyt/g1GWq8Sg+uPAkrks2QVVUV3i5CSlnuEoQgHB2MnNq+nE9 vtCo1NYzVTwQzyRiDVqADYu1mgbWFdIULHfBex11BeA2vv7zYB5/a2BX2+k0xnm6z75z kJx/IBQMJjADZi9+cSgA0wI976KInbgnkPTYExwAlo5BOd7TvHYdrie5k8bAjU6gzEvR ub0D5y4wbkg6vOvFVy6lmahiZJTcCqiy+zjl1q9N7auuQoHqTvcnIgzGzH84RymaYNJ7 l25eZjkbt6XMNfwklz3FETrUqnNpx0G3llWZPTU4CrCQ11hKvyjvi9VhFMb976Oiqow4 kZ9Q== X-Gm-Message-State: AOAM532mJPy143iXpZkodg5IqR5aB7zmXWGM3WH1/bcuq2fRWrmwDJfb ZHSk3s3M5FwSfP7wW4ouGzA= X-Google-Smtp-Source: ABdhPJwjz8dPYMt9os+urjypBO3KPO0n0aAUmhuhKTUddMw0/hFm/BxjybZbsejId+j0oxfauAhjwQ== X-Received: by 2002:a05:620a:4491:: with SMTP id x17mr26762094qkp.528.1638142589577; Sun, 28 Nov 2021 15:36:29 -0800 (PST) Received: from localhost ([66.216.211.25]) by smtp.gmail.com with ESMTPSA id h19sm8013261qth.63.2021.11.28.15.36.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Nov 2021 15:36:28 -0800 (PST) Date: Sun, 28 Nov 2021 15:36:27 -0800 From: Yury Norov To: Nicholas Piggin Cc: Arnaldo Carvalho de Melo , Andy Gross , David Airlie , Alexey Klimov , Andi Kleen , Andrew Morton , Alexander Shishkin , Amitkumar Karwar , Andrew Lunn , Andy Shevchenko , Anup Patel , Ard Biesheuvel , Arnd Bergmann , Jens Axboe , bcm-kernel-feedback-list@broadcom.com, Borislav Petkov , Catalin Marinas , Christoph Lameter , Daniel Vetter , Dave Hansen , David Laight , Dennis Zhou , Dinh Nguyen , Geetha sowjanya , Geert Uytterhoeven , Greg Kroah-Hartman , Guo Ren , Heiko Carstens , Christoph Hellwig , Hans de Goede , Ian Rogers , Jason Wessel , "James E.J. Bottomley" , Jonathan Cameron , Jiri Olsa , Juri Lelli , Kees Cook , Krzysztof Kozlowski , Jakub Kicinski , Kalle Valo , kvm@vger.kernel.org, Lee Jones , linux-alpha@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Russell King , linux-crypto@vger.kernel.org, linux-csky@vger.kernel.org, linux-ia64@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Rasmus Villemoes , linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-snps-arc@lists.infradead.org, Andy Lutomirski , Mark Gross , Mark Rutland , "Martin K. Petersen" , Marc Zyngier , Matti Vaittinen , Mauro Carvalho Chehab , Mel Gorman , Mike Marciniszyn , Ingo Molnar , Michael Ellerman , Marcin Wojtas , Palmer Dabbelt , "Paul E. McKenney" , Peter Zijlstra , Solomon Peachy , Petr Mladek , "Rafael J. Wysocki" , Randy Dunlap , Steven Rostedt , Roy Pledge , Saeed Mahameed , Sagi Grimberg , Subbaraya Sundeep , Stephen Boyd , Sergey Senozhatsky , Stephen Rothwell , Sunil Goutham , Sudeep Holla , Tariq Toukan , Thomas Gleixner , Tejun Heo , Thomas Bogendoerfer , Ulf Hansson , Vlastimil Babka , Vineet Gupta , Vincent Guittot , Viresh Kumar , Vivien Didelot , Will Deacon Subject: Re: [PATCH 0/9] lib/bitmap: optimize bitmap_weight() usage Message-ID: <20211128233627.GA323159@lapt> References: <20211128035704.270739-1-yury.norov@gmail.com> <1638096766.3elxdzb8ly.astroid@bobo.none> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1638096766.3elxdzb8ly.astroid@bobo.none> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: C0F9070000B9 X-Stat-Signature: m1uz4p8s5pgbi18npxsbbno6kcnzrnzw Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=FqHxiwrQ; spf=pass (imf27.hostedemail.com: domain of yury.norov@gmail.com designates 209.85.222.169 as permitted sender) smtp.mailfrom=yury.norov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1638142588-977558 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, Nov 28, 2021 at 09:08:41PM +1000, Nicholas Piggin wrote: > Excerpts from Yury Norov's message of November 28, 2021 1:56 pm: > > 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. > > There would be no change to callers if you maintain counters like what > is done for num_online_cpus() today. Maybe some fixes to arch code that > does not use set_cpu_possible() etc APIs required, but AFAIKS it would > be better to fix such cases anyway. Thanks, Nick. I'll try to do this.