From patchwork Wed Apr 4 02:56:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10321997 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B03C760467 for ; Wed, 4 Apr 2018 02:58:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DD5228691 for ; Wed, 4 Apr 2018 02:58:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 921A82872C; Wed, 4 Apr 2018 02:58:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1B71828691 for ; Wed, 4 Apr 2018 02:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UsSRZl5twThfk306JFmY5qzZo+PdfAneYIu5A8fxjSg=; b=BBpCaHK+A4CI042EtYEuqa1b/6 DkIAmMPoJPdxDuIZ44ouHoSRJLSsWddUfo37+jFiKiOWnvzEuOs2pe47pgK2KQO9CaGcs978nH/jL YPpe8Jdp8qWOw8bQYP9ZUIZVj3uUL4UUKGnh9nuQTCGzsyvCxJbPsivRDfi0ahtOKTbkgJ8Jvhitt ngvxUiPou4cYwAcvNtj7fAsYgGSG0b0QwxUO2P/j5O9YB/lORVaSdO/bmIlL38Jt4Zr7n01WF+WtV tqKosWXMqN5XszSfKSwScqC3KdJrnPs9C5+P9dTBrDcIkC7h3Kdz5q6mbi3aVJ4LY+uk+ERevlZuZ GR/G5T5A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3Yd1-0007x2-HI; Wed, 04 Apr 2018 02:58:27 +0000 Received: from mail-pl0-x241.google.com ([2607:f8b0:400e:c01::241]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3Ybv-0007BW-2r for linux-arm-kernel@lists.infradead.org; Wed, 04 Apr 2018 02:57:24 +0000 Received: by mail-pl0-x241.google.com with SMTP id u11-v6so12027768plq.1 for ; Tue, 03 Apr 2018 19:57: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; bh=dyMI+v3VoOQghzg/SFDaXUCaWcnyG1p6iYj3OzZ8sfg=; b=XzXjmbgjcUoA0dJg7mhgRJYiW1F3yS4GaOpDyQYlGQSJRycMYzEE29IV8JdWYMbifo 0pngrJysxD/xq5jfAJuOgYaUlHYYlQoRk8/MvO6bloje1vEBCATsMmuy+Nxp48uICW+m X+XM2QSzW1XD9LnkYcx34uv+szrf/X48AwVkoTpXbKnxhciRBTCB5siONvyXf4jhwVhN F0tD91kKVmFBxYNnYPt4kb/6K1Q5auaLLc3YcivznoGUqYyz9uSPk5msQAZ5FCN0HldN sRRmDCwNHXWrfc8AZxyM8JHqV8qsoaPVy2vRzEV4BIJOEpmabbzw2k2U0sChV+y3c4vB dWaQ== 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; bh=dyMI+v3VoOQghzg/SFDaXUCaWcnyG1p6iYj3OzZ8sfg=; b=gbo73HmnjhAjEBMVK4pimT2rkFPDXRzydYjg5KPkqlVs+W+yx3SaF7GAgkCyg6G6ze pMZuhDPg/LmsBbf3gwa3zjghAHC+/fvxtJQ2tuJGqPlDqhUDe7YQUSeB9zyqubMpRsOH EDofBNhXbvJCmAS+K2AjQkcPkXIUg71PS4dw2iXcHQA/NPWcxgQOORP6ctZZpQvSB3Yy ouVcLFzukBofko0P8JkisK73nGpZwy+9wkb0JAW5dwmpMSSIfqVZtiNvhrIDWQyS1jat HGKNIy7RKYmQSVFE7+gDoYT8P4qnyiEnbV1QP0so99QICTrryEBzuC952fTh2yQJ4mzO bxwg== X-Gm-Message-State: AElRT7G9VGkpc8MFEYIvn791735tHmKBSnKmQHbUKjIRdq1XbuJtwwUF 9lVVAqNWb4Da2/J4b5FpdU8= X-Google-Smtp-Source: AIpwx4/fqjs+E1m7OjUPxgliR0RoV4aFky/mptIqPoEfpduTbEerN75bh3mq9py763HsUf20QxKrwg== X-Received: by 10.99.180.6 with SMTP id s6mr10540882pgf.81.1522810628553; Tue, 03 Apr 2018 19:57:08 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id a4sm8020701pfj.107.2018.04.03.19.56.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 03 Apr 2018 19:57:08 -0700 (PDT) From: Jia He To: Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Andrew Morton , Michal Hocko Subject: [PATCH v6 2/5] arm: arm64: page_alloc: reduce unnecessary binary search in memblock_next_valid_pfn() Date: Tue, 3 Apr 2018 19:56:16 -0700 Message-Id: <1522810579-7466-3-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522810579-7466-1-git-send-email-hejianet@gmail.com> References: <1522810579-7466-1-git-send-email-hejianet@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180403_195719_148917_5ADAF11B X-CRM114-Status: GOOD ( 19.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gioh Kim , Wei Yang , linux-mm@kvack.org, Eugeniu Rosca , Petr Tesarik , Nikolay Borisov , Jia He , Pavel Tatashin , Daniel Jordan , AKASHI Takahiro , Vlastimil Babka , Andrey Ryabinin , Laura Abbott , Daniel Vacek , Mel Gorman , Vladimir Murzin , Kees Cook , Philip Derrin , YASUAKI ISHIMATSU , Jia He , Kemi Wang , linux-arm-kernel@lists.infradead.org, Steve Capper , linux-kernel@vger.kernel.org, James Morse , Johannes Weiner MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Commit b92df1de5d28 ("mm: page_alloc: skip over regions of invalid pfns where possible") optimized the loop in memmap_init_zone(). But there is still some room for improvement. E.g. if pfn and pfn+1 are in the same memblock region, we can simply pfn++ instead of doing the binary search in memblock_next_valid_pfn. Signed-off-by: Jia He --- include/linux/arm96_common.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/include/linux/arm96_common.h b/include/linux/arm96_common.h index a6f68ea..2f4dea4 100644 --- a/include/linux/arm96_common.h +++ b/include/linux/arm96_common.h @@ -5,32 +5,47 @@ #ifndef __ARM96_COMMON_H #define __ARM96_COMMON_H #ifdef CONFIG_HAVE_ARCH_PFN_VALID +static int early_region_idx __init_memblock = -1; /* HAVE_MEMBLOCK is always enabled on arm and arm64 */ ulong __init_memblock memblock_next_valid_pfn(ulong pfn) { struct memblock_type *type = &memblock.memory; - unsigned int right = type->cnt; - unsigned int mid, left = 0; + struct memblock_region *regions = type->regions; + uint right = type->cnt; + uint mid, left = 0; + ulong start_pfn, end_pfn; phys_addr_t addr = PFN_PHYS(++pfn); + /* fast path, return pfn+1 if next pfn is in the same region */ + if (early_region_idx != -1) { + start_pfn = PFN_DOWN(regions[early_region_idx].base); + end_pfn = PFN_DOWN(regions[early_region_idx].base + + regions[early_region_idx].size); + + if (pfn >= start_pfn && pfn < end_pfn) + return pfn; + } + + /* slow path, do the binary searching */ do { mid = (right + left) / 2; - if (addr < type->regions[mid].base) + if (addr < regions[mid].base) right = mid; - else if (addr >= (type->regions[mid].base + - type->regions[mid].size)) + else if (addr >= (regions[mid].base + regions[mid].size)) left = mid + 1; else { - /* addr is within the region, so pfn is valid */ + early_region_idx = mid; return pfn; } } while (left < right); if (right == type->cnt) return -1UL; - else - return PHYS_PFN(type->regions[right].base); + + early_region_idx = right; + + return PHYS_PFN(regions[early_region_idx].base); } EXPORT_SYMBOL(memblock_next_valid_pfn); #endif /*CONFIG_HAVE_ARCH_PFN_VALID*/