Received: by 10.213.65.68 with SMTP id h4csp1171142imn; Sat, 24 Mar 2018 05:26:38 -0700 (PDT) X-Google-Smtp-Source: AG47ELsT8NS5gFMqTUPZ8lxYTcmv/AIxpYNYlXJ1dWlKKeNfypjq9pGRR41D5smg2XhxikO8hGHc X-Received: by 10.99.170.9 with SMTP id e9mr11553028pgf.331.1521894398648; Sat, 24 Mar 2018 05:26:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521894398; cv=none; d=google.com; s=arc-20160816; b=hrfr+789U+WF2yjvPZ3+UVvEbP5huTENdFF+XPIIQ3ec3RtXuXISNIFNwl7EpltiXX VJ1I+vlYIabG42zzrjM+rHKlu9QJPvtjxU7/zj8QnLcNncEnPXNDBqHbqpgpJ7htA+ib I3QE3l308cwuER1jiIrbliOrv/jAiGVLqGNOrYiReGX+I61oD/5st4nHROgo1gQfVbqz qhUcL+woa3+Cz33N0P0hxSZnxWdnh8xkyzj7isKXeGI0W8kbudWuXM1jV99x9d34c3dd FxTn3MLN6tIROj3FuMENhTNn+k4bBOhnD6XBlk8bBSNKOpFlSCCNz1/WCCpcRSQeguGA X0CQ== 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=u98/yESuMVbaXeRtVPwvqpbKxJR0f1kfq2ivtvjaEg4=; b=PdU5gEbea76i+Hvta49iEtVkHVOiwwpAUOL2nt678iJFbpjyElx0bYbkVMTyl2nnMB LTXL1qQ8nhEzjgukS7gDdvwFBCvnI70WKu5qem6dSC8WBFjmLSXM91B05YFDgZNmyTAN 2+GPlm94So9LdhJg0FSbZeW1TcTORNrxhF3XmeArFg1PflUd4PjlTDW/iv6+T13hlDRA 5cvKRvHiWqa5vVW3Bat7JkALaDUuIFuVT7z2J0v8veacy2EFE9wyY88Ja0NrpCaUaWzA yVCbeT/M//BCCQoYRop5GZnjQu7cgOBCRH3+teP7xTDGb4Ykzc+Fi1Qp73xyGy7XcY5V NMkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=FJzpQT50; 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 x13si8267558pfm.281.2018.03.24.05.26.24; Sat, 24 Mar 2018 05:26:38 -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=FJzpQT50; 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 S1752031AbeCXMZV (ORCPT + 99 others); Sat, 24 Mar 2018 08:25:21 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34890 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751879AbeCXMZT (ORCPT ); Sat, 24 Mar 2018 08:25:19 -0400 Received: by mail-pg0-f66.google.com with SMTP id d1so5571380pgv.2 for ; Sat, 24 Mar 2018 05:25:18 -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=u98/yESuMVbaXeRtVPwvqpbKxJR0f1kfq2ivtvjaEg4=; b=FJzpQT50P61qsGKRSnrin5reLcwrO3jRCN6ugdDNWU+B2tJu3EtKIocp7L7cMGrXzS HupcjsdtKYCRpHtQyHejW7efZ13ju4oaXV7g2YaEhVqoF4BoIfs7ZCvtvMiApnEBI5aR qm7rtdOdTdHdmhpgCjFGi5gRTgGSSv+RcP35uV+BEdg9cjy4yKIqXcw5YkEY3PxasOYE VlinaVilus7n7MDAV5V2POqG3yLwG0BQNsO2dFXKTTwgU1PUwYQdYJs041FRVkw3S3uM Q0tTvT9dErrCDTrDlUU2hz/PPG2GwZUErM6KW5mUbFEHgFKUiWs58Bt+UrYIr7KdQSz8 TXRA== 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=u98/yESuMVbaXeRtVPwvqpbKxJR0f1kfq2ivtvjaEg4=; b=Wlav008HkF7wpszD9+3Kh7wNvTMUBpV2tmmqrgPPtkho3gomb2g7A/uGtrhfmimYA7 g3WyEuStUBGbwSwUlOr4qxuaOWFgyp2Y0RBG9jGE3NpMQAqP6IIi+iGENF3jBUL5+nvJ 8MUgvYjCSYpdzQAfghhVc4y/f62/R3RjzL6zr/V/40xJbtsJViHjc9zSmlpsn7tyPHML 99WFl6LHqsII4/C2zapgffbaxKreNz1iJfszybg1cj+9XKtCvokzIM/5GdGvHi73jrQD vnOMjPOIsvxgMdg4ZT43ZZrDR7+C69jMwKtyPkgp3eqdp/0aNVv+Xasmo8mQ/6l9tjHa AFOA== X-Gm-Message-State: AElRT7HG9qdwUREKgLYwJDC2aJvrtvIvmyxKA984QcF/XrTFdhTti8wf 7d714zbkm/fUTAKv+dyzR1U= X-Received: by 10.98.24.11 with SMTP id 11mr14593605pfy.5.1521894318579; Sat, 24 Mar 2018 05:25:18 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id b6sm23152371pfm.160.2018.03.24.05.25.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 24 Mar 2018 05:25:18 -0700 (PDT) From: Jia He To: Andrew Morton , Michal Hocko , Catalin Marinas , Mel Gorman , Will Deacon , Mark Rutland , Thomas Gleixner , Ingo Molnar , "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 , x86@kernel.org, Greg Kroah-Hartman , Kate Stewart , Philippe Ombredanne , Johannes Weiner , Kemi Wang , Petr Tesarik , YASUAKI ISHIMATSU , Andrey Ryabinin , Nikolay Borisov , Jia He , Jia He Subject: [PATCH v2 1/5] mm: page_alloc: remain memblock_next_valid_pfn() when CONFIG_HAVE_ARCH_PFN_VALID is enable Date: Sat, 24 Mar 2018 05:24:38 -0700 Message-Id: <1521894282-6454-2-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521894282-6454-1-git-send-email-hejianet@gmail.com> References: <1521894282-6454-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 it causes possible panic bug. So Daniel Vacek reverted it later. But memblock_next_valid_pfn is valid when CONFIG_HAVE_ARCH_PFN_VALID is enabled. And as verified by Eugeniu Rosca, arm can benifit from this commit. So remain the memblock_next_valid_pfn. Signed-off-by: Jia He --- include/linux/memblock.h | 4 ++++ mm/memblock.c | 29 +++++++++++++++++++++++++++++ mm/page_alloc.c | 11 ++++++++++- 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 0257aee..efbbe4b 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -203,6 +203,10 @@ void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, i >= 0; __next_mem_pfn_range(&i, nid, p_start, p_end, p_nid)) #endif /* CONFIG_HAVE_MEMBLOCK_NODE_MAP */ +#ifdef CONFIG_HAVE_ARCH_PFN_VALID +unsigned long memblock_next_valid_pfn(unsigned long pfn); +#endif + /** * for_each_free_mem_range - iterate through free memblock areas * @i: u64 used as loop variable diff --git a/mm/memblock.c b/mm/memblock.c index ba7c878..bea5a9c 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1102,6 +1102,35 @@ void __init_memblock __next_mem_pfn_range(int *idx, int nid, *out_nid = r->nid; } +#ifdef CONFIG_HAVE_ARCH_PFN_VALID +unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn) +{ + struct memblock_type *type = &memblock.memory; + unsigned int right = type->cnt; + unsigned int mid, left = 0; + phys_addr_t addr = PFN_PHYS(++pfn); + + do { + mid = (right + left) / 2; + + if (addr < type->regions[mid].base) + right = mid; + else if (addr >= (type->regions[mid].base + + type->regions[mid].size)) + left = mid + 1; + else { + /* addr is within the region, so pfn is valid */ + return pfn; + } + } while (left < right); + + if (right == type->cnt) + return -1UL; + else + return PHYS_PFN(type->regions[right].base); +} +#endif /*CONFIG_HAVE_ARCH_PFN_VALID*/ + /** * memblock_set_node - set node ID on memblock regions * @base: base of area to set node ID for diff --git a/mm/page_alloc.c b/mm/page_alloc.c index c19f5ac..2a967f7 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -5483,8 +5483,17 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, if (context != MEMMAP_EARLY) goto not_early; - if (!early_pfn_valid(pfn)) + if (!early_pfn_valid(pfn)) { +#if (defined CONFIG_HAVE_MEMBLOCK) && (defined CONFIG_HAVE_ARCH_PFN_VALID) + /* + * Skip to the pfn preceding the next valid one (or + * end_pfn), such that we hit a valid pfn (or end_pfn) + * on our next iteration of the loop. + */ + pfn = memblock_next_valid_pfn(pfn) - 1; +#endif continue; + } if (!early_pfn_in_nid(pfn, nid)) continue; if (!update_defer_init(pgdat, pfn, end_pfn, &nr_initialised)) -- 2.7.4