Received: by 10.192.165.156 with SMTP id m28csp395345imm; Wed, 11 Apr 2018 00:28:06 -0700 (PDT) X-Google-Smtp-Source: AIpwx49sV8eORWFiTOLo/jrSghtAno5hMfjISrdcDpiU48wfLs+4AM/vDmdi+XkGoDw9w0rSK0a9 X-Received: by 2002:a17:902:a609:: with SMTP id u9-v6mr3835894plq.56.1523431686787; Wed, 11 Apr 2018 00:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523431686; cv=none; d=google.com; s=arc-20160816; b=zpJxzAuDIn4dq/4Ijd0la1ioae+TzBdRZaTaUXsPBZnBMh45bD1dQ+s2RXzBO6A2rs 0U8LjcaugKMyop81M9QamEPWkaRk3DlsTy1yK0Lkbb8BcVa1mXggMojHGWckvKivgqKj hSrOR3mtHNMdJUonDwAF4HDeOOo0n5XnZ9v7D1CRMNRWrTS1VZrxB3Xj9myKhw3wRYH6 kpoAlVUrqWkSaJT5EK0p7DhxZaB0oAsIi0YyrFj0Tr2Nl9uxzSPNKFqKh9ot9nOYz2ZO dNF67ELlJnf9ncFLqwGfKOABv+CsMZtiWH1wFnsyE3NKzEJrA/WZ0nDgmpnvHWlCUsSo izDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=N1Cw5ECHaCaF06TbZ6/mN+FA5B85KCw7bdG3vLv2Qkw=; b=h963gs+2yC+84fKCNplI5Dylk6DNDOgGLXTp3bbAj3e7Zc69lbpBfVFuKaQUh53D3J 5XqFRdccbA15NJtLJVw9GF5yGTdiNBQF3OZpnV0bHl/0yICfzmkPrp7WSooDOTR+fDC4 9qovlKDazCK1dyGTUEan7EeuY7AF7CfqMza/ROh/JIcigIJIt4GadEaVyXEiQMmibu18 xyU3KglMld/Ty3vDObS/ceHqzgAt6nW/b991tnvk1gcanmAO26DYbQ8y53kAnk6gx5TG 37U5aa2+j131mx447ZrB7TWfz8F77HmtGnVp80RrxRMM65xarQgRPKbfTSrwYJvD2IqL KhOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KHmDsiT1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e15si370562pgu.656.2018.04.11.00.27.29; Wed, 11 Apr 2018 00:28:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=KHmDsiT1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752724AbeDKHYD (ORCPT + 99 others); Wed, 11 Apr 2018 03:24:03 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:34666 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751861AbeDKHYC (ORCPT ); Wed, 11 Apr 2018 03:24:02 -0400 Received: by mail-pl0-f66.google.com with SMTP id y12-v6so743332plt.1 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=Oq+0vGuCsr2T2BOEn9bt7lklLDaRpjyf1IL8y3TyaUvOqtNObgYkJQudZ1uWInqotJ gPsT6mBg1UdT5+MD6B0H0EWSPxLF8YRFtPvLnu6oXyxiNHdEnhPtikxuX7dmLsxtp0mE HkgSSfTLtNR5YS14FS+huwejM9gNuviiZSMR2+D5rC9VjPhEDjX/oyBYmrrgBupG8ubi BTFclwAbf/Sku2+ZE8/77dmEUyN/9cpo9H1Z4Fa2/heKehoEkrB/aUirK0lEIHp29id0 XXi3sV1PAHcZMEevu0+UiNSBSlKUZXijly2WwDJ8g5sYPk1sXxmEP735zOENGf9nevla afeg== X-Gm-Message-State: ALQs6tDbrBeLMGHNjmwdrFGSJdCH71mJVwbP3D+GdfunbG3PcS/6Uhzm 5i9w5VRVutNMVpkNhVFMT6A= 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 Cc: Wei Yang , Kees Cook , Laura Abbott , Vladimir Murzin , Philip Derrin , AKASHI Takahiro , James Morse , Steve Capper , Pavel Tatashin , Gioh Kim , Vlastimil Babka , Mel Gorman , Johannes Weiner , Kemi Wang , Petr Tesarik , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov , Daniel Jordan , Daniel Vacek , Eugeniu Rosca , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Jia He , Jia He 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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*/ -- 2.7.4