Received: by 10.213.65.68 with SMTP id h4csp974319imn; Sun, 25 Mar 2018 20:04:16 -0700 (PDT) X-Google-Smtp-Source: AG47ELusqyQpK++9xekr6sJeQLAAgEz02qo0itL0SX4YII9QMfbJUcnEuyAU75I9c2PXOpChXsUg X-Received: by 10.99.122.28 with SMTP id v28mr27671419pgc.128.1522033456240; Sun, 25 Mar 2018 20:04:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522033456; cv=none; d=google.com; s=arc-20160816; b=l4YTiijWzz/76q4NAV1SAlmg8jlPNYs0HsTw6089Tt+C1e6GawnLU3CSYlOQNJo+Bc n48yVjxm/PlkdiJoLnbqqlDc8BHdY1KzaP+SuBVaqBI1Xy7RGWGjmCfiychGAfYPe51N 0CUpEQbBS6X7Y+efoY+Oyn86C3oVPvIZViFN9nqBMUVaoPrSMA9n9c5h6exKNjw16hUh OEEcMXW0yedspb/TtLGlkFWFWu/n9l8jPs3xn+Mo71Wap+vtPRtwZ+j8e+fVhVCQVB4e vYslA+lKE4av6prDWKb7jwUqOq9hs16BzjG9DvtoIABafNbSyCO+XgNgG/IFFULkicAP sYAg== 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=zPjYOchOIUoUOg+AeshAkXKjILJ9DfOv2dGhtrvsThM=; b=QikA6/3dU1ewlfkQx5x99UghvdiEIJVOhBpkMwUusYYVqUr3hZcjuhv8JrvqbHUcjm ng71zA8PGoPd4aWLpOA4I/UN2CoD1n2GmfuwEMA3EzTQFOkBdCoqvzUkWl7fxKILLwRK Ri9A/eA/PMqxhTGmAjCr7Ta5OKgQDBVnWaz5oGp2AiroGtrw8cnAQ1raCsrZpBHhBkaA u4nQHB9aAKsZI/gX32Zl/DhS9/yP6aN3Y5WP4LROZyqMLA5+lGgmCaCIJscUpf3tbSfx tqi5j+ioQR1kqJPJi9PK8Mx+qD6TAvP0QvFW9G0VwiBTEbya9opYbyK3dhN1tuTfPAd3 qwSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=DF3CzckQ; 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 c1-v6si13912501pla.34.2018.03.25.20.04.01; Sun, 25 Mar 2018 20:04:16 -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=DF3CzckQ; 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 S1752069AbeCZDDD (ORCPT + 99 others); Sun, 25 Mar 2018 23:03:03 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:37754 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750981AbeCZDDA (ORCPT ); Sun, 25 Mar 2018 23:03:00 -0400 Received: by mail-pg0-f67.google.com with SMTP id n11so6768048pgp.4 for ; Sun, 25 Mar 2018 20:03:00 -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=zPjYOchOIUoUOg+AeshAkXKjILJ9DfOv2dGhtrvsThM=; b=DF3CzckQDaIWZAJctPhNLOSoLcU98Az0f7kEPbnxNiBjNXiu7cpWakb/zHPZNeCeYK FLazAwIhOMKz4IFG6+wWO+9utiIvDsqtg7TIrKK9J5e9PSaLDYKECUSxDrECvwOmwEwV jwMcHxzgJwbMaU/FkG+fBHCBNNdK3K0auqhTYPLScSon++LNZqZzHxju/Fis/vFdkhAG CQMdCKSM3kLOOUT3b3uhJd7n9fZa2d6UA7sxZI8B715AyXFNPaGHODD78tONclqNMts5 DUUsdzX6EK/hCNp5X4oI3OcXdKkyYfiOC/w3OvP68CZcUN1AFoaGNA5L4UwVrSjKgsUb 8jHw== 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=zPjYOchOIUoUOg+AeshAkXKjILJ9DfOv2dGhtrvsThM=; b=WgnlhrgmAWP4Sfgs9uSjiHfYOp8p4xKIu7d0X9ycctQGTU4INH3+9KO/osfBpMR703 VLclurQt24uMriFsZrHZpgXwDGUkoZWzKp21JlDFlYiOBE0cm6Qw3myPl5jfu7YknAGN qnd+J9Vdh8ewkc9bI6hU+qGtEBVUcH2c2aPEsCdvcg0qU5yXk4lwqwrgmL3jLLXuKYSL 27gBm+KkGGC0+olvj1Oo8QN+Suxsb8iMbyo6PuqNhea6mqcFu7n3nb0wOmFRm5Yoh4mw qgoSEbY0GNNv7mbwPDZuUTDedSVfGTIg/l/IV3MYcb6bGwHOZR5q76pOJ/6EQtray0vC twBA== X-Gm-Message-State: AElRT7GPW2ChJNysHqwdXPqEIEjmwWFWu9sIhJsOzX/IzyfOHjkNR/fY hv4yp/PtlUH2xDjzQMop9L4= X-Received: by 10.98.102.79 with SMTP id a76mr11870378pfc.162.1522033379736; Sun, 25 Mar 2018 20:02:59 -0700 (PDT) Received: from localhost.localdomain ([38.106.11.25]) by smtp.gmail.com with ESMTPSA id f19sm1634989pgv.39.2018.03.25.20.02.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 25 Mar 2018 20:02:59 -0700 (PDT) From: Jia He To: Andrew Morton , Michal Hocko , Catalin Marinas , Mel Gorman , Will Deacon , Mark Rutland , Ard Biesheuvel , 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 , 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 v3 1/5] mm: page_alloc: remain memblock_next_valid_pfn() when CONFIG_HAVE_ARCH_PFN_VALID is enable Date: Sun, 25 Mar 2018 20:02:15 -0700 Message-Id: <1522033340-6575-2-git-send-email-hejianet@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1522033340-6575-1-git-send-email-hejianet@gmail.com> References: <1522033340-6575-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 enable. 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