Received: by 10.213.65.68 with SMTP id h4csp454519imn; Fri, 16 Mar 2018 08:15:29 -0700 (PDT) X-Google-Smtp-Source: AG47ELuoH59lRPs6KaRIhYLaEF8qehLmD3TjAfdQ/z61hOPQG35ijBHGdfo58G6Ho/uqnqUyoaJP X-Received: by 2002:a17:902:a713:: with SMTP id w19-v6mr2484421plq.246.1521213329807; Fri, 16 Mar 2018 08:15:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521213329; cv=none; d=google.com; s=arc-20160816; b=I2JFzwoUrzRhscxA3kbrKQFt/6FmCBmErw4umjvGxrpUjB5FmajG4iLB6A8Z8FYRO1 EXV2aVMdlauXbROuDOUHrK4iC5UNiK/8WG7NJmMZu5A2vITJ8Gq+1O3WRH1flX2Aijvc PLO7PYockNyIRWdTilx2tUJ98YGfMt1HeeCqZc/Kkp7qpfKo/2oLR/pPFJyMJwIHsdi4 ZuIXSESPkMQcNyk0sEeOo1wTNC/juxVUkrf6eZzrl34ClT0r/X/TZNuDnMJeAPCXIHcN 4Y/WTkok+CNROoNHBw+XKzNATW71Y5pcSyOMUc59jfDp1uX1Fnehu8PGa3OiW3BKoNTS OMAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:arc-authentication-results; bh=WR+ppwuYFT14J53Z14jL92SOjd9FAg5uzDgt6ZLjXV4=; b=mata6MLtZi2ZOjJe8ygzv3qf6Je249YB0ttM6MkMmbZcTwrK/iRTllTzN2pF9pIZ4E xbVqC+ep2KxuzqP61rcROaUP6vIlx8dNSqeNP5bUHh45LZts5bAIPxwy3Hq54iisVCOT CNdTdB8eBc+J1kQ1CBKZsXNVnfMrLosNWh27kMU75JLhaTCyi/cWF/GZSI+BcrTyPMLm 3hruF3bbwU/chx3xBjhip/ZXSzumcpjt+jPi6GGUBxOFY3oT6PG8okcEwD9PaUNUFosD jXhxvv+VMLSj/jFgbdFaF2o2IBLaO+rYLApKZZQ8PHjOLs7ZLr9cMcLA5H4tkzQVSqck AJNw== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u70si5116701pgd.354.2018.03.16.08.15.15; Fri, 16 Mar 2018 08:15:29 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752678AbeCPPNu (ORCPT + 99 others); Fri, 16 Mar 2018 11:13:50 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:37043 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751468AbeCPPNs (ORCPT ); Fri, 16 Mar 2018 11:13:48 -0400 Received: by mail-oi0-f65.google.com with SMTP id f186so8889750oig.4 for ; Fri, 16 Mar 2018 08:13:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=WR+ppwuYFT14J53Z14jL92SOjd9FAg5uzDgt6ZLjXV4=; b=PFJdCjhctB+TIu9bV73YqbznYMrCo/FSo6fB7rfrB1ybjediRtHI9YsIHTF3Wexlxf Kb6ghbbGHV01mgitao77f76PajQoSw8fFShfTH732AkhbhU8b9KIDXUjfFiG/X651Og/ Ygeekydllx0nxCsTjQxE9cF67Z7xZXT+pubUYpNf6GBM5fFYB5JQvnycnum/H8m3rquj jOzphl7NScfbgnIngV+k692pesFCJxjSIEBbss5uV0AfrFqnYe6sxc0eJfoSJchm5gJX zWiihtw1pJZxD2mna5s1eZuX5e8s7P5VwOGR27LO0U3yTTJ2OfRo7QYVXKxG0vja4vc/ JEmg== X-Gm-Message-State: AElRT7FoAMkCq1g1ooPbp1E4c1YVqqTjGC4GytdH6b4brTYs6P8TduaK 44wtsNB2Zb6U6OcMsIPeCAtt1B+MEk3BlblSZcWgjtQj670= X-Received: by 10.202.104.165 with SMTP id o37mr1282400oik.296.1521213227907; Fri, 16 Mar 2018 08:13:47 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:39f6:0:0:0:0:0 with HTTP; Fri, 16 Mar 2018 08:13:47 -0700 (PDT) In-Reply-To: <20180316143855.29838-1-neelx@redhat.com> References: <20180316143855.29838-1-neelx@redhat.com> From: Daniel Vacek Date: Fri, 16 Mar 2018 16:13:47 +0100 Message-ID: Subject: Re: [PATCH] Revert "mm: page_alloc: skip over regions of invalid pfns where possible" To: open list , linux-mm@kvack.org Cc: Ard Biesheuvel , Daniel Vacek , Andrew Morton , Michal Hocko , Vlastimil Babka , Mel Gorman , Pavel Tatashin , Paul Burton , stable Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Sorry I forgot to Cc: Paul Burton --nX On Fri, Mar 16, 2018 at 3:38 PM, Daniel Vacek wrote: > This reverts commit b92df1de5d289c0b5d653e72414bf0850b8511e0. The commit > is meant to be a boot init speed up skipping the loop in memmap_init_zone() > for invalid pfns. But given some specific memory mapping on x86_64 (or more > generally theoretically anywhere but on arm with CONFIG_HAVE_ARCH_PFN_VALID) > the implementation also skips valid pfns which is plain wrong and causes > 'kernel BUG at mm/page_alloc.c:1389!' > > crash> log | grep -e BUG -e RIP -e Call.Trace -e move_freepages_block -e rmqueue -e freelist -A1 > kernel BUG at mm/page_alloc.c:1389! > invalid opcode: 0000 [#1] SMP > -- > RIP: 0010:[] [] move_freepages+0x15e/0x160 > RSP: 0018:ffff88054d727688 EFLAGS: 00010087 > -- > Call Trace: > [] move_freepages_block+0x73/0x80 > [] __rmqueue+0x263/0x460 > [] get_page_from_freelist+0x7e1/0x9e0 > [] __alloc_pages_nodemask+0x176/0x420 > -- > RIP [] move_freepages+0x15e/0x160 > RSP > > crash> page_init_bug -v | grep RAM > 1000 - 9bfff System RAM (620.00 KiB) > 100000 - 430bffff System RAM ( 1.05 GiB = 1071.75 MiB = 1097472.00 KiB) > 4b0c8000 - 4bf9cfff System RAM ( 14.83 MiB = 15188.00 KiB) > 4bfac000 - 646b1fff System RAM (391.02 MiB = 400408.00 KiB) > 7b788000 - 7b7fffff System RAM (480.00 KiB) > 100000000 - 67fffffff System RAM ( 22.00 GiB) > > crash> page_init_bug | head -6 > 7b788000 - 7b7fffff System RAM (480.00 KiB) > 1fffff00000000 0 1 DMA32 4096 1048575 > 505736 505344 505855 > 0 0 0 DMA 1 4095 > 1fffff00000400 0 1 DMA32 4096 1048575 > BUG, zones differ! > > crash> kmem -p 77fff000 78000000 7b5ff000 7b600000 7b787000 7b788000 > PAGE PHYSICAL MAPPING INDEX CNT FLAGS > ffffea0001e00000 78000000 0 0 0 0 > ffffea0001ed7fc0 7b5ff000 0 0 0 0 > ffffea0001ed8000 7b600000 0 0 0 0 <<<< > ffffea0001ede1c0 7b787000 0 0 0 0 > ffffea0001ede200 7b788000 0 0 1 1fffff00000000 > > Fixes: b92df1de5d28 ("mm: page_alloc: skip over regions of invalid pfns where possible") > Signed-off-by: Daniel Vacek > Acked-by: Ard Biesheuvel > Cc: Andrew Morton > Cc: Michal Hocko > Cc: Vlastimil Babka > Cc: Mel Gorman > Cc: Pavel Tatashin > Cc: Paul Burton > Cc: stable@vger.kernel.org > --- > include/linux/memblock.h | 1 - > mm/memblock.c | 28 ---------------------------- > mm/page_alloc.c | 11 +---------- > 3 files changed, 1 insertion(+), 39 deletions(-) > > diff --git a/include/linux/memblock.h b/include/linux/memblock.h > index 8be5077efb5f..f92ea7783652 100644 > --- a/include/linux/memblock.h > +++ b/include/linux/memblock.h > @@ -187,7 +187,6 @@ int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn, > unsigned long *end_pfn); > void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, > unsigned long *out_end_pfn, int *out_nid); > -unsigned long memblock_next_valid_pfn(unsigned long pfn, unsigned long max_pfn); > > /** > * for_each_mem_pfn_range - early memory pfn range iterator > diff --git a/mm/memblock.c b/mm/memblock.c > index b6ba6b7adadc..48376bd33274 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -1101,34 +1101,6 @@ void __init_memblock __next_mem_pfn_range(int *idx, int nid, > *out_nid = r->nid; > } > > -unsigned long __init_memblock memblock_next_valid_pfn(unsigned long pfn, > - unsigned long max_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); > -} > - > /** > * 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 635d7dd29d7f..e4566a3f8083 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5356,17 +5356,8 @@ 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)) { > -#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP > - /* > - * 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, end_pfn) - 1; > -#endif > + if (!early_pfn_valid(pfn)) > continue; > - } > if (!early_pfn_in_nid(pfn, nid)) > continue; > if (!update_defer_init(pgdat, pfn, end_pfn, &nr_initialised)) > -- > 2.16.2 >