From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 457C0C282DD for ; Wed, 8 Jan 2020 14:40:49 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 146302070E for ; Wed, 8 Jan 2020 14:40:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 146302070E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id A2ED48E000F; Wed, 8 Jan 2020 09:40:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9DFAD8E0001; Wed, 8 Jan 2020 09:40:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F44E8E000F; Wed, 8 Jan 2020 09:40:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0251.hostedemail.com [216.40.44.251]) by kanga.kvack.org (Postfix) with ESMTP id 7985A8E0001 for ; Wed, 8 Jan 2020 09:40:48 -0500 (EST) Received: from smtpin25.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with SMTP id 10C69181AEF00 for ; Wed, 8 Jan 2020 14:40:48 +0000 (UTC) X-FDA: 76354728576.25.teeth48_4120171855648 X-HE-Tag: teeth48_4120171855648 X-Filterd-Recvd-Size: 6576 Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Wed, 8 Jan 2020 14:40:47 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id c14so3631280wrn.7 for ; Wed, 08 Jan 2020 06:40:47 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=kj3sdKsTZaeIbGwmm89PcRIOcawKHePAIrmjBLLY4Uw=; b=aNPqFD8BUxOaM5+PghidHu1iS0tW+6t/LunnUZi9k9/EqOVpmQYeOQWFX9+nDfAb6f 2v7Eic9vdTLt0yVRbLOu40ijnHgC3lsO5bFWz5VK2hmNOOsp7y7AS2QrcP79m+x96ieR BjmhZLieg32rrkYzaVfGVXJUYm0s2v+NRl53s0Jv5eevzhU3uqgHUhl/hv5qxSAxC92C 7TVXLpnOcnXs04vro1rAMKcnLFbNa5MN5vpuwTCX7vi1B1VGRmGxtZ3bpK7o3aIm5On7 /+7M/kIrQLYSY4wxp3lq2xKPLKsGOhG+ady4mycI2Sn6FTaN6pM1IsnLMGwp7Kkw5MJg bl7w== X-Gm-Message-State: APjAAAXNGZkcSpMJpdo+zdnvFoCqbegL84xTEOtU5nlmIpxu/QV/PQ9x cpLlMGRZHdBsjgXiKIY/MH0= X-Google-Smtp-Source: APXvYqz4mHG7mUJHfog9TrthVEXEGMiJMAUt0zcWnEcdnAdrTfaZ5UARWF/oHyOf5XJSPt7w0+vigQ== X-Received: by 2002:a5d:6886:: with SMTP id h6mr4958200wru.154.1578494446291; Wed, 08 Jan 2020 06:40:46 -0800 (PST) Received: from localhost (prg-ext-pat.suse.com. [213.151.95.130]) by smtp.gmail.com with ESMTPSA id a1sm3971016wmj.40.2020.01.08.06.40.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jan 2020 06:40:44 -0800 (PST) Date: Wed, 8 Jan 2020 15:40:44 +0100 From: Michal Hocko To: "Kirill A. Shutemov" Cc: Andrew Morton , Dan Williams , Vlastimil Babka , Mel Gorman , "Jin, Zhi" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: Re: [PATCH] mm/page_alloc: Skip non present sections on zone initialization Message-ID: <20200108144044.GB30379@dhcp22.suse.cz> References: <20191230093828.24613-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191230093828.24613-1-kirill.shutemov@linux.intel.com> User-Agent: Mutt/1.12.2 (2019-09-21) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Mon 30-12-19 12:38:28, Kirill A. Shutemov wrote: > memmap_init_zone() can be called on the ranges with holes during the > boot. It will skip any non-valid PFNs one-by-one. It works fine as long > as holes are not too big. > > But huge holes in the memory map causes a problem. It takes over 20 > seconds to walk 32TiB hole. x86-64 with 5-level paging allows for much > larger holes in the memory map which would practically hang the system. > > Deferred struct page init doesn't help here. It only works on the > present ranges. > > Skipping non-present sections would fix the issue. Makes sense to me. > Signed-off-by: Kirill A. Shutemov That pfn inc back and forth is quite ugly TBH but whatever. Acked-by: Michal Hocko > --- > > The situation can be emulated using the following QEMU patch: > > diff --git a/hw/i386/pc.c b/hw/i386/pc.c > index ac08e6360437..f5f2258092e1 100644 > --- a/hw/i386/pc.c > +++ b/hw/i386/pc.c > @@ -1159,13 +1159,14 @@ void pc_memory_init(PCMachineState *pcms, > memory_region_add_subregion(system_memory, 0, ram_below_4g); > e820_add_entry(0, x86ms->below_4g_mem_size, E820_RAM); > if (x86ms->above_4g_mem_size > 0) { > + int shift = 45; > ram_above_4g = g_malloc(sizeof(*ram_above_4g)); > memory_region_init_alias(ram_above_4g, NULL, "ram-above-4g", ram, > x86ms->below_4g_mem_size, > x86ms->above_4g_mem_size); > - memory_region_add_subregion(system_memory, 0x100000000ULL, > + memory_region_add_subregion(system_memory, 1ULL << shift, > ram_above_4g); > - e820_add_entry(0x100000000ULL, x86ms->above_4g_mem_size, E820_RAM); > + e820_add_entry(1ULL << shift, x86ms->above_4g_mem_size, E820_RAM); > } > > if (!pcmc->has_reserved_memory && > diff --git a/target/i386/cpu.h b/target/i386/cpu.h > index cde2a16b941a..694c26947bf6 100644 > --- a/target/i386/cpu.h > +++ b/target/i386/cpu.h > @@ -1928,7 +1928,7 @@ uint64_t cpu_get_tsc(CPUX86State *env); > /* XXX: This value should match the one returned by CPUID > * and in exec.c */ > # if defined(TARGET_X86_64) > -# define TCG_PHYS_ADDR_BITS 40 > +# define TCG_PHYS_ADDR_BITS 52 > # else > # define TCG_PHYS_ADDR_BITS 36 > # endif > > --- > mm/page_alloc.c | 28 +++++++++++++++++++++++++++- > 1 file changed, 27 insertions(+), 1 deletion(-) > > diff --git a/mm/page_alloc.c b/mm/page_alloc.c > index df62a49cd09e..442dc0244bb4 100644 > --- a/mm/page_alloc.c > +++ b/mm/page_alloc.c > @@ -5873,6 +5873,30 @@ overlap_memmap_init(unsigned long zone, unsigned long *pfn) > return false; > } > > +#ifdef CONFIG_SPARSEMEM > +/* Skip PFNs that belong to non-present sections */ > +static inline __meminit unsigned long next_pfn(unsigned long pfn) > +{ > + unsigned long section_nr; > + > + section_nr = pfn_to_section_nr(++pfn); > + if (present_section_nr(section_nr)) > + return pfn; > + > + while (++section_nr <= __highest_present_section_nr) { > + if (present_section_nr(section_nr)) > + return section_nr_to_pfn(section_nr); > + } > + > + return -1; > +} > +#else > +static inline __meminit unsigned long next_pfn(unsigned long pfn) > +{ > + return pfn++; > +} > +#endif > + > /* > * Initially all pages are reserved - free ones are freed > * up by memblock_free_all() once the early boot process is > @@ -5912,8 +5936,10 @@ void __meminit memmap_init_zone(unsigned long size, int nid, unsigned long zone, > * function. They do not exist on hotplugged memory. > */ > if (context == MEMMAP_EARLY) { > - if (!early_pfn_valid(pfn)) > + if (!early_pfn_valid(pfn)) { > + pfn = next_pfn(pfn) - 1; > continue; > + } > if (!early_pfn_in_nid(pfn, nid)) > continue; > if (overlap_memmap_init(zone, &pfn)) > -- > 2.24.1 > -- Michal Hocko SUSE Labs