From patchwork Thu Apr 5 08:04:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 10323857 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 CE2776032A for ; Thu, 5 Apr 2018 08:15:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCDC4287D5 for ; Thu, 5 Apr 2018 08:15:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE32728852; Thu, 5 Apr 2018 08:15:19 +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=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 2952F287D5 for ; Thu, 5 Apr 2018 08:15:19 +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=V+2ViRwx+eX1PDZtazHE3tQEuW2WI1MidpSt2l0mDFg=; b=cf5yVUBXcG7R/lbVEsQSbQLAlX 0iRIrvHy/aD+rnzDphnfc+Y+QGYPzpX+1ELl9kcQCeKobt4WuvJKfEl5+3SNEhIajjiZq8dSXdLQ2 /zZ5S45tV1u/M0x8zHJQMlWbl+yPXLPl37NHqSdltHisQPxN1F1NfnOKIz6XMvMU5khcs53DQKCU6 7JQSmaMnvk7oiz0+Cwt6VL1ZdoT2UDAycsQ19FeL1B+wNEthb5WIn4HTu2xX54ndYQlqQ4jc6dt34 6atIR1laKLe7AxF4ipgQFQhIuDLrAqXemWtbi8kPvhIny3Q25iZyNy7e4YwIiGGxsyEIIjRdAJqdR XIwxzaGA==; 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 1f403C-0000O7-0T; Thu, 05 Apr 2018 08:15:18 +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 1f3zuC-0003p8-PU for linux-arm-kernel@lists.infradead.org; Thu, 05 Apr 2018 08:06:20 +0000 Received: by mail-pl0-x242.google.com with SMTP id c21-v6so14448282plz.10 for ; Thu, 05 Apr 2018 01:05:50 -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=QJXDDCrlH3e6N/V1L5PQV9swiVxzm05L4qgriULRyL0=; b=R0BcRXOo+2itK3FsIE+gOpcbCt+6htLuvSNu03LI6pXbXIuppBlIPObjAWbaAasITj lo0dn9v4jeXSLtADVKwdklROyo23L4881mOF9O02g7GilXu1DxFfMpeuFs0txjBzYax2 Cp3B8o5IALxm2YEUVpLoknqFBP8+bHU/f8XnD3d1syzDQ61QTGMcntJV9W7wMwQLfBAw 0ir4QaZ/v32TVnsjaTmQ1BDUMVnjELmooYm4KiR8kbWvKhgLC1xhXIbnkQgDfm+IpNEr jMClVxe02tjow5doOmCTjtLV/5Dpr/3OJzKL5qmKRuf9b2kaTHEeBiR7xNoVe2/zMvwM ro+g== 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=QJXDDCrlH3e6N/V1L5PQV9swiVxzm05L4qgriULRyL0=; b=Tg74vr+ogo7ScbcNKenEkPIujHLGch8wdFGB5HKmJcmprIIs83rk/zPGCsa9BQFaWa wHdjZDsS1exfUP3CbbW5/GGDZwaLYvfQKwULSCFjkYF5B68V8Rsmh7uYX0CokS7rta50 4kZCL9toTEC5bvOUPyCIepZy/WB+Y76S53yOnF4m3vBe021TN+i/GH3FtZpSOg7moX63 GiMKnVgP60wK+S+fZ3Se/Bt4gwWNozRqwkjQP8al+zPOCmV8HCtRa2ZWQcUs5p2t50D+ o+JMOP31/f3P+7gcX+ekzsA9f+d9ZskfRme6HyrV1Z5KxXZONBixPtWDfg0z7plMy1AR 5JBA== X-Gm-Message-State: AElRT7GroQHf9TCPjKrg49f1bePEqABrJTre1758S3drufleCM/nllh9 3D+k+JhVF1DfGMF9l0AY8fU= X-Google-Smtp-Source: AIpwx49doOW0U9jqEakBTlyXKq1m0mWBbKMhrUpfdBZ0DEQ7z9U+M95lLc8Sj/28NA1Knfooya8Orw== X-Received: by 2002:a17:902:7295:: with SMTP id d21-v6mr21460977pll.130.1522915549952; Thu, 05 Apr 2018 01:05:49 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id 2sm14983690pft.33.2018.04.05.01.05.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 05 Apr 2018 01:05:49 -0700 (PDT) From: Jia He To: Russell King , Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Andrew Morton , Michal Hocko Subject: [PATCH v7 4/5] arm: arm64: introduce pfn_valid_region() Date: Thu, 5 Apr 2018 01:04:37 -0700 Message-Id: <1522915478-5044-5-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_010600_925498_414E5A46 X-CRM114-Status: GOOD ( 14.76 ) 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/arm96_common.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/include/linux/arm96_common.h b/include/linux/arm96_common.h index 2f4dea4..bb86bd3 100644 --- a/include/linux/arm96_common.h +++ b/include/linux/arm96_common.h @@ -48,5 +48,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_ARCH_PFN_VALID*/ #endif /*__ARM96_COMMON_H*/