From patchwork Tue Oct 5 05:40:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12535523 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 C3CF9C433F5 for ; Tue, 5 Oct 2021 05:42:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B00606128A for ; Tue, 5 Oct 2021 05:42:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232954AbhJEFoQ (ORCPT ); Tue, 5 Oct 2021 01:44:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33946 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232941AbhJEFnq (ORCPT ); Tue, 5 Oct 2021 01:43:46 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E5D9C0617AA; Mon, 4 Oct 2021 22:41:39 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id k26so16431890pfi.5; Mon, 04 Oct 2021 22:41:39 -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=ItK3sXhsAM1f1ASq5u4DaKGjX0YlsAxopFtfKS5hkUGd2sSnkTU+qaKgXZTN57kjrH YyTiguK30n8ixSoHgKeQTHnWXideSR4lXu6Y5AQ1qutTOlTpCfF4vK091PRnFnIemVFq IdLl4+cpPVnnyEkM35F/tFy+WN6FWqNQHEoCuIJJdJ07OO/Q8/wG/CUh7W07ELnQf6LA Vr259OX/kYoyfHAjZHTpVnA1b0afzM45P5r63b+WD8ltL0vaY5hYThrMKobSsbekeQoA FkrL760sIbMTlMuhmcDJ60JMRRgj+4U7jqSsffEqH3hUo3OB+xMEQxsIgIFbn37xPzfn +Aiw== 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=DNvrV5Uek0CPr+ZZiOcz9k8+rxdaZj6XJBT+M3kSqRFeaEqoZOyMIN1fVu+3zlP3Ad iZevV1AFrdUKa3cUQFMPetHKPUra3qbEZVpPRo4rOQJLmX2gu3dFge4vrEsVs0hxvr+f j79M1hctL/6ALhuNgmbvAnuNdUYlVQ/o3+HecmgcYuzPHcBrPgGR1+IS+PxXyupATJrj FGFKkC8UrNQX4iM/XSiAD1uUPLRmyZuubUoNWewcs3+b3ZAjdxdrCgp+9J+seCj9AeJi X0j73XcEi632p7+DE19jt1OWZ92DEa35/hSe9kcI8iyX667DNRvIb+GjbSMBtYjuFhp4 cqSw== X-Gm-Message-State: AOAM530+8Ce72thtaIB0v2F4GQSK6Xb6Zkva9H12ZAJazdO4rxxm9D0q 6sgXM4BXjKm5TX2fvC4nBgg= X-Google-Smtp-Source: ABdhPJwkGoS5lx+2DFRKSI4puA9sR0Q04TQBSdoQwr4TaY60RgunHwEUf0OU253yIkwHPeX5ysEAEg== X-Received: by 2002:a63:1a65:: with SMTP id a37mr14296966pgm.338.1633412498651; Mon, 04 Oct 2021 22:41:38 -0700 (PDT) Received: from localhost (searspoint.nvidia.com. [216.228.112.21]) by smtp.gmail.com with ESMTPSA id u19sm10821033pfg.18.2021.10.04.22.41.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Oct 2021 22:41:38 -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: Mon, 4 Oct 2021 22:40:56 -0700 Message-Id: <20211005054059.475634-14-yury.norov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211005054059.475634-1-yury.norov@gmail.com> References: <20211005054059.475634-1-yury.norov@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@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; }