From patchwork Mon Jul 19 02:17:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yury Norov X-Patchwork-Id: 12384587 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1FAB3C636C8 for ; Mon, 19 Jul 2021 02:18:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id BF15561168 for ; Mon, 19 Jul 2021 02:18:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BF15561168 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 639E06B012D; Sun, 18 Jul 2021 22:18:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6103C8D00FA; Sun, 18 Jul 2021 22:18:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 416BB6B012F; Sun, 18 Jul 2021 22:18:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 1AFC36B012D for ; Sun, 18 Jul 2021 22:18:10 -0400 (EDT) Received: from smtpin04.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B62B3180301CC for ; Mon, 19 Jul 2021 02:18:08 +0000 (UTC) X-FDA: 78377727456.04.49FE838 Received: from mail-qk1-f171.google.com (mail-qk1-f171.google.com [209.85.222.171]) by imf17.hostedemail.com (Postfix) with ESMTP id 77BE0F0003B8 for ; Mon, 19 Jul 2021 02:18:08 +0000 (UTC) Received: by mail-qk1-f171.google.com with SMTP id a80so3951020qkg.11 for ; Sun, 18 Jul 2021 19:18:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8jO4nyGRdRSlBrG+WtYYiYryUcVMfftUEaMWXVUBDHo=; b=SKGJyt71wEAPu9gRSETzpS6ZnOKx6a1bVyzPQQZ7wf8q9e73XNqg20Rep9KCsgrJy+ 6Hc3QqOXLFgPBymAhgv3OdB98lsEtfYwD4ait9F9Gu9xVNNl1pArXFG2hWMtL3OO6agz SxH8WuxRAMY8Vfw1gSSYi+51LcEQc9Oi+X4vTKka5FVLiWWv51br36NbOaUPqU1D51w9 SjDbXTB+VSgkS8I43DHq5z+4+zymugAbk3ZEwYK0fZpqFfb3P53OivY0S/RgGvti2oPv 4ZuW/H1CYbkP//CQIV/63MPo7glEXQQl+QC6U1KHSvlP4kzxCfosoWd9BYTo07k0Y6y4 l+SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8jO4nyGRdRSlBrG+WtYYiYryUcVMfftUEaMWXVUBDHo=; b=kiTYXuq+MwNRkvZXJcNHoOSsNs9lI9Y4Lkw3W/AfAJxppiRjn3YBQh8V7fxB9SYxqe NqtDqxFRm39UunvCnUraXGfSCG79xrguPTR4qDv2U5bbd0/IhKT1ZSJXgvyc5ODaiEdi yAaH/yfwtOrgoBTzYUsFkX1W4GRwRGv7DMS/jTwfcCsOHtPOnJCo/1+VxLdEECtcWVlv mORzK/lgqsnXjhBIjh0DNcfQi6BUsa2Bc8rzeuNjTYGgAvu0SUyLG3FpHvD75QUEgyjk abiFB5UcpqLOK4j7TUrOljgP4v/Uep9cxfzDTtEGHd0nuZSsPUDTxlpH7nQY3fm7MOk5 F6Og== X-Gm-Message-State: AOAM5309vmFYaJIXclVK0fa4eencxoRjGvXbHJDVM5rcq6sgQk37jHsA Ku/ej9W8XBrJ0tlMoR8Nfmk= X-Google-Smtp-Source: ABdhPJzYvqeefWrAr6+pDZNfg1zE1hHMkxSmnfBnpZkpOG8dZNMF6D/di1+589JFQPt7g2NDmTm3GA== X-Received: by 2002:a05:620a:f91:: with SMTP id b17mr3591105qkn.107.1626661087768; Sun, 18 Jul 2021 19:18:07 -0700 (PDT) Received: from localhost ([207.98.216.60]) by smtp.gmail.com with ESMTPSA id o27sm3351949qkk.124.2021.07.18.19.18.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 18 Jul 2021 19:18:07 -0700 (PDT) From: Yury Norov To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-mmc@vger.kernel.org Cc: Yury Norov , Andy Shevchenko , Rasmus Villemoes , Petr Mladek , Sergey Senozhatsky , Tejun Heo , Steven Rostedt , Wolfram Sang , Ulf Hansson , Dennis Zhou , Christoph Lameter , Andrew Morton Subject: [PATCH 1/4] mm/percpu: micro-optimize pcpu_is_populated() Date: Sun, 18 Jul 2021 19:17:52 -0700 Message-Id: <20210719021755.883182-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210719021755.883182-1-yury.norov@gmail.com> References: <20210719021755.883182-1-yury.norov@gmail.com> MIME-Version: 1.0 Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20161025 header.b=SKGJyt71; spf=pass (imf17.hostedemail.com: domain of yurynorov@gmail.com designates 209.85.222.171 as permitted sender) smtp.mailfrom=yurynorov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam05 X-Stat-Signature: aqrq7swyu4kctehxkhexiaoetg9jb4fp X-Rspamd-Queue-Id: 77BE0F0003B8 X-HE-Tag: 1626661088-369698 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: 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 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 7f2e0151c4e2..25461571dcc5 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1071,17 +1071,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; }