From patchwork Wed Apr 11 07:21:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10334951 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 CE9716053B for ; Wed, 11 Apr 2018 07:26:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B4FEA23B23 for ; Wed, 11 Apr 2018 07:26:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A94332871C; Wed, 11 Apr 2018 07:26:52 +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=-2.9 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=ham 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 496D823B23 for ; Wed, 11 Apr 2018 07:26:52 +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=lPiKH8Df0LDMGiJZ9PTV1fvEuV2JeTB0ZjOmj2M02to=; b=NVjC34Iq/eUO9+3Fp1hdkEk7Tb /pyCtKw8oiz8QwNm2quQsBagLLxIf/i0Qm6FZWA1x7j/TLQjImRd7qhjsHJzulHqm4JIhUj/4ME3e WBig+XN6oaMPeg/AuhOer77Sw6TxGNtE4TsXvSQ8m/dGhXZgfVFxe6Amy8/OwJobKbjrvH8eXOIwo ByLd3DSqII3O+GHv2Y2o8/zb+hM8d1YU+XO71oLE8dEybmFPlTmddRTUlzyEcMqgUXq+N7HVEwSio 62v3DoD4+sxWOUIS1qDcE1qGxNFjpOUjSD3O385MufxD+SmZ3DtAeqXKEabf2JJvBoCE/clBHVRpA exV5KXlg==; 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 1f6A9V-0004zc-Jq; Wed, 11 Apr 2018 07:26:45 +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 1f6A72-0002PU-MJ for linux-arm-kernel@lists.infradead.org; Wed, 11 Apr 2018 07:24:25 +0000 Received: by mail-pl0-x241.google.com with SMTP id 61-v6so737403plb.2 for ; Wed, 11 Apr 2018 00:24:02 -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=N1Cw5ECHaCaF06TbZ6/mN+FA5B85KCw7bdG3vLv2Qkw=; b=KHmDsiT1BS2dnf6wBkR0dGe3BtXXvSlMhZ8tTLeWUA8km+dfi9wAGk8xfJ8qaVInn0 sjlfAJhIqKW9xyRSBVIjaYRkSff1EccyFczHJkZA1KHYFsw0LJSAnFi1YA92fGiiTSLr ANt5BMylXR3gYq88KdW9ymDBaCjbRZUcoQBcKnNGnv70mrK6XLLDW65PJd/4W2Q/r9BY SY+ir0KH1G7pAdik7+8gYMfOiADuDQFaaVSz291rF79onJOv4v12om5togBXkzjjzWad dn3UPDXiylO4jc2ADkg2RA/A64cOXY5BLYVLC6xiXPfFawNNky9Hxut2TVran2BkTr+c N75g== 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=N1Cw5ECHaCaF06TbZ6/mN+FA5B85KCw7bdG3vLv2Qkw=; b=o99/kWnZt8IVHf9bAdhVj2qDr3KfjRGN3XHNaF6QH0kSjbPQiBh4ClvbnOYFQcrq1O KIgfXXqFMrdZX0UOFdfD09Xtyt8XPRQ/XVSlUxa0w7OI05/MnkfHxi++2qTwB+Fej419 1WHYWgX5tfCgsvn7bg0b87hpaxL7f/y+XZ5RADmsnNGLC9mh9OSP/TPHamBSwjtaDbcR mSySm0fWe+NLbfBBctIN+GqaRBemiGR4E9e8/BHWXXdocSPvP2EBLPI1u7bBrdIkyre6 hlm3wmCHCy+DVJvEjwZuksOsVkznvhBXCxK73uUqDACM+2z/8Y1IZDgb333s/ksMUogV yZ0A== X-Gm-Message-State: ALQs6tApTFblQ4xd/WITosOq8YbmSP+1YFo9tsLhTo3nio0ejBQ4/boV /NMzJRDbcJSDr7uc/lNeKqU= X-Google-Smtp-Source: AIpwx4/MLi7G1GlYO9FUWrIc1y0fgwmfCXXE77X5J6hlPRAUx8Ia0zI08Qt4qAcDBwDzyLscVLMB+Q== X-Received: by 2002:a17:902:b903:: with SMTP id bf3-v6mr639963plb.37.1523431441946; Wed, 11 Apr 2018 00:24:01 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id o90sm1561898pfj.102.2018.04.11.00.23.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Apr 2018 00:24:01 -0700 (PDT) From: Jia He To: Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Andrew Morton , Michal Hocko Subject: [PATCH v8 5/6] arm: arm64: introduce pfn_valid_region() Date: Wed, 11 Apr 2018 00:21:56 -0700 Message-Id: <1523431317-30612-6-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523431317-30612-1-git-send-email-hejianet@gmail.com> References: <1523431317-30612-1-git-send-email-hejianet@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180411_002412_775450_14C8DCFE X-CRM114-Status: GOOD ( 13.92 ) 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. in early_pfn_valid(), we can record the last returned memblock region. If current pfn and last pfn are in the same memory region, we needn't do the unnecessary binary searches because memblock_is_nomap is the same result for whole memory region. Signed-off-by: Jia He --- include/linux/early_pfn.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/linux/early_pfn.h b/include/linux/early_pfn.h index f9e40c3..9609391 100644 --- a/include/linux/early_pfn.h +++ b/include/linux/early_pfn.h @@ -51,5 +51,29 @@ ulong __init_memblock memblock_next_valid_pfn(ulong pfn) return PHYS_PFN(regions[early_region_idx].base); } EXPORT_SYMBOL(memblock_next_valid_pfn); + +int pfn_valid_region(ulong pfn) +{ + ulong start_pfn, end_pfn; + struct memblock_type *type = &memblock.memory; + struct memblock_region *regions = type->regions; + + 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 !memblock_is_nomap( + ®ions[early_region_idx]); + } + + early_region_idx = memblock_search_pfn_regions(pfn); + if (early_region_idx == -1) + return false; + + return !memblock_is_nomap(®ions[early_region_idx]); +} +EXPORT_SYMBOL(pfn_valid_region); #endif /*CONFIG_HAVE_MEMBLOCK_PFN_VALID*/ #endif /*__EARLY_PFN_H*/