From patchwork Thu Apr 5 08:04:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10323849 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 3D5D0600CB for ; Thu, 5 Apr 2018 08:06:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2D7A2290B3 for ; Thu, 5 Apr 2018 08:06:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1EA41290B6; Thu, 5 Apr 2018 08:06:35 +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 ADD21290B3 for ; Thu, 5 Apr 2018 08:06:34 +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=bC5d3y8eON5VFGgmm1X1OiIRAg TiHsyGWFY0170bPK62NEXE9lxbVqu3pUl2NU7o2TsNKqT6h+tySBh3F+jjLktjGRiWz/qeXdcHCB2 oLSpps7EgY9I6z8fX6IqXWqkh/qDGVrZWP3v6fwNWIwdpI7UvD1Yj2i340s3dqQ+mKxNs8/PLmbwP yEpIm7kniZujNS9k4KY3EqnUI1/1OGoo6b9RYanbpyLvK723w6jDbtG8FEyfQpWVplf3wOlST8jhL 5XBjht8z5hCyqjz28O10IzISdYUMvRqCqqiQgvRZ/dMJ6e7suT+X0FIIAEZnBb/XcQsBGnw/n99aF ICZ5n2Iw==; 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 1f3zuX-00045m-2X; Thu, 05 Apr 2018 08:06:21 +0000 Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f3ztl-0003VA-UB for linux-arm-kernel@lists.infradead.org; Thu, 05 Apr 2018 08:05:36 +0000 Received: by mail-pl0-x242.google.com with SMTP id x4-v6so18051716pln.7 for ; Thu, 05 Apr 2018 01:05:25 -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=TFn2gDSieLwf2+iSC9j4T+7O1VoDltt0bxsu3h1caZZKREdNmnPfLvYArFuaoeigu/ mE/RT8HIW9ep77mvWZc7AtHhNO90jiB+kHfokdvJw6yFU6cmxWXrOU2QzsepsACKTz3/ n+vgGG0xVJ5c8uY6421dDoZnLC51j9tX42z6q4FfJ34xVPdFwWTj1njtX5rkGIARAgfA zpjRwCsvDMlV2E2PyIqIcyR4oZxHpIpCAao7Oz8mWlzAEY89dELcE/BummLJwFw0pLwF A2rwfKTcESr4gcMdarBBbyUxEgQ+Cgf1FDSxwVD2hnIcjlLH2dbUFhE4Ly+VnZfYR85A uqjg== 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=hdX0R96gKmMDnSCN1s/rpaSNb2cWix0xS70umdT9mko5M4EF0F6ncdK6uKeo6gd4yR 03z5ErL9S6OUQG8FI+DkHLWtBRSKkxd+fog3bECeEhaabny/kD7NTDvP8fyHs5neYImQ r22KmUrT8gs1ft5tBN6yYMduyRr1vcl9y5rakFrQF9QNciu7kAQ30QgPnp3zuMZaAW1O Lur7dIrsHhimeLDhjdkUrZcqFoTUd7Q5LbUPBC0RzT3BPLAIMCef/loUmB0QjjgZKFtB oVjpM3GO5G9LdGDmB1ZG1vu2kFEUBXDV2z5sdMKI2IB7GX/hu1lTsIeUYusuk0k1NlB5 KmYg== X-Gm-Message-State: AElRT7GznWphQVfLhqwt4U4cgbrG7EKKYJBJAgXaM86ma5uSKS8ILsqB aqnuGFogfFpEVEftxgbtm7Q6QDU4 X-Google-Smtp-Source: AIpwx48t4GlAcGAKAPx5oCC5fk16FrG1kcv5kLjAIka7DMHlS+EGZ1YeTISbYsTXHPkUSK/YalchpQ== X-Received: by 10.99.37.196 with SMTP id l187mr14241483pgl.221.1522915525312; Thu, 05 Apr 2018 01:05:25 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id 2sm14983690pft.33.2018.04.05.01.05.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Apr 2018 01:05:24 -0700 (PDT) From: Jia He To: Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Andrew Morton , Michal Hocko Subject: [PATCH v7 2/5] arm: arm64: page_alloc: reduce unnecessary binary search in memblock_next_valid_pfn() Date: Thu, 5 Apr 2018 01:04:35 -0700 Message-Id: <1522915478-5044-3-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522915478-5044-1-git-send-email-hejianet@gmail.com> References: <1522915478-5044-1-git-send-email-hejianet@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180405_010534_005880_4EC8C518 X-CRM114-Status: GOOD ( 19.41 ) 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*/