From patchwork Fri Oct 1 18:12:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12531571 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3547C433F5 for ; Fri, 1 Oct 2021 18:14:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B07A6135E for ; Fri, 1 Oct 2021 18:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1355762AbhJASQP (ORCPT ); Fri, 1 Oct 2021 14:16:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355899AbhJASPq (ORCPT ); Fri, 1 Oct 2021 14:15:46 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7B593C0617B1; Fri, 1 Oct 2021 11:13:27 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id v19so7109283pjh.2; Fri, 01 Oct 2021 11:13:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nf81eMg0W7fVWw+dS1fRTqTJZj1jgno6nh0Ggg55AFs=; b=lLZwpryZB98PlGeM8ZanBwznPLR+qj4BAk9K/uf8CR1i4Vr7ohWNGkej3kVUNqXdVG 1Jz42et237u6yAI2fLT63htNSZHBQhI5hTW5QlTYMfJALg2QS7K341SuCyg4JVoN+kGK yOPWlwz1SZqxUrFbg0dAknq0LNE8mNSh0R3dX8vDH2CEQhdIdhjfR7r7zRN3uJrZXcfW 4oysstkJLDNrmHqITg7OwYcRcURoNhlMq4pNYfSkpvdiR3XB3A3qF8SPFy4Vr8b3LYgh GIuCVYH1I8wQMVDx8yJeJME3oPJHo6nsCRdz2f0rkYcuGYqLc+cVhFZggI3dGfdtYMGP dgRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nf81eMg0W7fVWw+dS1fRTqTJZj1jgno6nh0Ggg55AFs=; b=l6HFr1nt7qh0YTsftDmPPReVwkhz4PNG3YiKB/OHM14AV6ANoZbMCRNxw6h+K/rgHE zxQd/ekpNvg9LyzqY+u2MBtC5oIBSG1azmSA16U3tS+ZJv30T+bwsPNGeRYMajEsXU89 WFa9f5vjE6LH+Uvn9pD5DN5VMfabp/Zvgd3RIZWLZ97QIMYkjFKlUX7DXEmWJqeYvDrE claKN5qBowbuVZfu+ThuzsuQ6Y/1lgNR1AqMjz72eE5pQCZSlNHA5c4WCYJ2v1L4DzUz tB1t65PnjyqKlL94GGYdKy9Ppcc53oTGq5BRu0iTvMdN49s1+mEc8wFgN1s1BkSvg+8P HHpw== X-Gm-Message-State: AOAM5335lupF2e6siSxDYqKRu9XAoZEPPDKMqoL6XzJADckrb3acsjIx VT4iy6HLVxXwtu0LvMPQEHo= X-Google-Smtp-Source: ABdhPJwxSbuZpik63wXkHcsR03oG0P45JgB69KyL2Up8CkB/6v40eakk14TkFHTNdybDdRPkK7Axtg== X-Received: by 2002:a17:90a:2841:: with SMTP id p1mr15463362pjf.153.1633112006983; Fri, 01 Oct 2021 11:13:26 -0700 (PDT) Received: from localhost (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id o2sm8177868pja.7.2021.10.01.11.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 11:13:26 -0700 (PDT) From: Yury Norov To: Stephen Rothwell Cc: Yury Norov , Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mmc@vger.kernel.org, linux-perf-users@vger.kernel.org, kvm@vger.kernel.org, "James E.J. Bottomley" , Alexander Lobakin , Alexander Shishkin , Alexey Klimov , Andrea Merello , Andy Shevchenko , Arnaldo Carvalho de Melo , Arnd Bergmann , Ben Gardon , Benjamin Herrenschmidt , Brian Cain , Catalin Marinas , Christoph Lameter , Daniel Bristot de Oliveira , David Hildenbrand , Dennis Zhou , Geert Uytterhoeven , Heiko Carstens , Ian Rogers , Ingo Molnar , Jaegeuk Kim , Jakub Kicinski , Jiri Olsa , Joe Perches , Jonas Bonn , Leo Yan , Mark Rutland , Namhyung Kim , Palmer Dabbelt , Paolo Bonzini , Peter Xu , Peter Zijlstra , Petr Mladek , Rasmus Villemoes , Rich Felker , Samuel Mendoza-Jonas , Sean Christopherson , Sergey Senozhatsky , Shuah Khan , Stefan Kristiansson , Steven Rostedt , Tejun Heo , Thomas Bogendoerfer , Ulf Hansson , Will Deacon , Wolfram Sang , Yoshinori Sato Subject: [PATCH 13/16] mm/percpu: micro-optimize pcpu_is_populated() Date: Fri, 1 Oct 2021 11:12:42 -0700 Message-Id: <20211001181245.228419-14-yury.norov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211001181245.228419-1-yury.norov@gmail.com> References: <20211001181245.228419-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org bitmap_next_clear_region() calls find_next_zero_bit() and find_next_bit() sequentially to find a range of clear bits. In case of pcpu_is_populated() there's a chance to return earlier if bitmap has all bits set. Signed-off-by: Yury Norov Tested-by: Wolfram Sang Acked-by: Dennis Zhou --- mm/percpu.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/mm/percpu.c b/mm/percpu.c index e0a986818903..1cf0bb904b1d 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1070,17 +1070,18 @@ static void pcpu_block_update_hint_free(struct pcpu_chunk *chunk, int bit_off, static bool pcpu_is_populated(struct pcpu_chunk *chunk, int bit_off, int bits, int *next_off) { - unsigned int page_start, page_end, rs, re; + unsigned int start, end; - page_start = PFN_DOWN(bit_off * PCPU_MIN_ALLOC_SIZE); - page_end = PFN_UP((bit_off + bits) * PCPU_MIN_ALLOC_SIZE); + start = PFN_DOWN(bit_off * PCPU_MIN_ALLOC_SIZE); + end = PFN_UP((bit_off + bits) * PCPU_MIN_ALLOC_SIZE); - rs = page_start; - bitmap_next_clear_region(chunk->populated, &rs, &re, page_end); - if (rs >= page_end) + start = find_next_zero_bit(chunk->populated, end, start); + if (start >= end) return true; - *next_off = re * PAGE_SIZE / PCPU_MIN_ALLOC_SIZE; + end = find_next_bit(chunk->populated, end, start + 1); + + *next_off = end * PAGE_SIZE / PCPU_MIN_ALLOC_SIZE; return false; }