Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp428465imm; Thu, 28 Jun 2018 23:44:05 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfqn9OTUNalUyt7dOEgOTijW71X1YpqBEtoVD1qpbLkuZyENxmJ5ABoi1vVEICqNRZsjHcT X-Received: by 2002:a62:d98f:: with SMTP id b15-v6mr9545122pfl.1.1530254645354; Thu, 28 Jun 2018 23:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1530254645; cv=none; d=google.com; s=arc-20160816; b=k00rcaDr6iaoph6z2TnUVQjf0YbxoqNsY6HqSc/Ok/IMGvnpGzOWHmySdWugnYHMpK D7pGku/nGJvBSCoZXIS0OKor/vhPpQ7M2uMzkFimuclGH54aKQWql22LfKZR8Pyfub0t s7CjvGCIKDLMb3Hod/B+vhcpocbQLtwEVPVkSN8lnNKDEiQQvnnrmHeOaa/gw8fidggK 37SLRJ3yi/dHUW5abOHdGOedyXeqW0qfBsfwSbZi0yjB4noogG6xdM/6qTaVSbIM9pjt Uwkakib/2VyKAY5713NmT5NrgnB8txELIZ1t3EwXWYt6ylr4ho/GPKtkLLNIyPbdh/Yz 6Rqw== 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=djDu+PIa1upI/bAjFRM2i263LjHkgnzhYw9JJWjbmtY=; b=PYfGV7SCzzkACEBmsG+/cTR3FUiAON3oTp0IVTRsyllAR0dqrAZgyP3M6+dX/cE0hE iWs0NI/gu7F6/0N6CP5650h0AwtE9Wz6Qpp5buO7zQKdndNgqt1g0KwXexUD81v4e840 yJihgg8S/P4ycLAPoEXvnftPhqWKEX1CSn6tMPjaqfeGUvjPvcD2LWyE3sczits5p0Ns nVQYAQI8cvmupXvKbBzTJ4LysoQfzv/j6qeE9R942/IlamF+tLbf4JSL9QgdivcfAEG8 cq/SquNQaXNo1moi/Xidty1Eo1na3EkxcdBe4BIaeGOIG67Ye0OQGmCkv5lpVhXNYxM4 p2Hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=k9w8Uoas; 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 a22-v6si8172498pfn.19.2018.06.28.23.43.51; Thu, 28 Jun 2018 23:44:05 -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=k9w8Uoas; 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 S1030512AbeF2CbC (ORCPT + 99 others); Thu, 28 Jun 2018 22:31:02 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:35547 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933679AbeF2Ca7 (ORCPT ); Thu, 28 Jun 2018 22:30:59 -0400 Received: by mail-qk0-f194.google.com with SMTP id u21-v6so4187454qku.2 for ; Thu, 28 Jun 2018 19:30:59 -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=djDu+PIa1upI/bAjFRM2i263LjHkgnzhYw9JJWjbmtY=; b=k9w8Uoas56o/7k1a6DbvlCedX3G0Nf50HUQpQwtKHxqTFO3HXjEVRKSiwKhGpA3pTo 0HJylj0h00QYT8cdQffYKC+1hdjPILfFYkvysBet1CefgKoD7RBvWczxEmF4hpjnLPMp l0jVQzOG3XGn9sCN2It8XP0gVWG1CL3sgOug4BQgELk1/4CZLW4wkZ4rw+Rd9nBGeXlm zEQ9ATXJt+3HRwGMlBScdCzBLdeEZZdCkHC7gxs7ZtTyxu6DTW5NL7hHlmIGmK0Q1R3J uWPtt0pX/2f68HDbOvtRcTgbZEG22fOet7kCeqrmGcBzTVI+Ekwty2cq2X3cCdEDX2EW sPYA== 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=djDu+PIa1upI/bAjFRM2i263LjHkgnzhYw9JJWjbmtY=; b=r5CiHdcdzNhLJ6OKzLMT9wHhqa21V9dxBQ9Z6kTrTN6TJvZAiilOL7IWpCEXVFMv6f sfDgpMvIVgUhYaKkvZWbENhu/rDAQpGRVITrt7aaxucEZGCUKHksBvKDW8ay0N0zC2NN WjLsRMS9opwsdwDs3YQR9Ia/Hi/1UL2MaLRrKj3RbTFJHKUo4dn7oPZqAz4EQdqUJWl6 01F1cTQOI1hGce8P5Ks9iscQJWCheWdTPHvKpELvwWtrkHY+xs6jCfCQcYimVGBf79Q8 0x/f6QvgAQc5+APiiVthhe774i1gWXghDe/7nJ7Q8ecQKBvLQqxGoo65yQzJQrIRWqFG mqIg== X-Gm-Message-State: APt69E0v8qTphuMnMLUC9XA0FtddMkOl8bGzDNtkqzMUp/ZrrsdvWICy c8zC6yFtJ39idFx+WAVvtSQ= X-Received: by 2002:a37:13e6:: with SMTP id 99-v6mr11106848qkt.252.1530239459275; Thu, 28 Jun 2018 19:30:59 -0700 (PDT) Received: from ct7host.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id y25-v6sm6390186qtc.48.2018.06.28.19.30.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 19:30:58 -0700 (PDT) From: Jia He To: Russell King , Andrew Morton , Michal Hocko , Catalin Marinas , Mel Gorman , Will Deacon , Mark Rutland , "H. Peter Anvin" Cc: Pavel Tatashin , Daniel Jordan , AKASHI Takahiro , Gioh Kim , Steven Sistare , Daniel Vacek , Eugeniu Rosca , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org, James Morse , Ard Biesheuvel , Steve Capper , Thomas Gleixner , Ingo Molnar , Greg Kroah-Hartman , Kate Stewart , Philippe Ombredanne , Johannes Weiner , Kemi Wang , Petr Tesarik , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov , richard.weiyang@gmail.com, Jia He , Jia He Subject: [PATCH v9 5/6] arm: arm64: introduce pfn_valid_region() Date: Fri, 29 Jun 2018 10:29:22 +0800 Message-Id: <1530239363-2356-6-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530239363-2356-1-git-send-email-hejianet@gmail.com> References: <1530239363-2356-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*/ -- 1.8.3.1