From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D39D940DFCF for ; Sat, 25 Apr 2026 09:01:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777107711; cv=none; b=uKvxh5QQGBCdqUL+22QPI3zlh7AIntdVFBkbE+ZK4ncEKA8+SPbi9QS44oU0vxUmOcJdxOWk1vqFDomBpCMmSFSB8Q36L+N0hu99E7jrALmIo2OqskwHPkfeS/Qia5zGYJuOkb0f1ijl0DkO//eltsZ1NqXIcYSHN1OLV4GYZ8o= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777107711; c=relaxed/simple; bh=5yiqehpqcmPkZRD49hIB6BWbV7/+EwrK/ftgYf7l+DQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sVAruAvyugm6Zq1k0QqsnNt0MqVtv9s6Nm5kWDf7P3Mn9TBLz19t4v5btj227mSfO4fDHaA805AoJei/8Ci0ktSFe8/r2lSDSVlBBR2+mAp7BB3fRqstP+9NfoCDJZFx/XjZ2gZB7YPUwzGGHrscgsK5D2Q82mICJgN5b5KSqok= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HkEwOF2Q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="HkEwOF2Q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BBE36C2BCB0; Sat, 25 Apr 2026 09:01:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777107711; bh=5yiqehpqcmPkZRD49hIB6BWbV7/+EwrK/ftgYf7l+DQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HkEwOF2Q88ie3HEjo2W0sQPgQBUwFPH3UABPKNCMZxk89hJ/hoG1QNte2jcu7qPNt 0iC6DHxQQz6286/vynT2oO1mnHMVZTtCr0YQrFgCQwHTKMxqy1JdyTl8D7JtVw8MXK Nu02SNOk0hJ3g6AmFtIf4/Ym2ZuE0tMmRfcgjOLj1w0tUsu7jzIZ5Pz+OUo5RUnojn 2RO6M2UgD23XBi/LtUUQhg/EmG2Re69HC11go8o4qrA5Auj33TUJiE2hlsM8i5zTjG 5BVDS+bjr2sHHGfxXgfUwf6INOwWaOPQhuHG4LgUaxUv25RPvcY0LsxmoTg5Z8G/Kd fGYQF9TDHO2gQ== Date: Sat, 25 Apr 2026 11:01:42 +0200 From: Mike Rapoport To: Yuan Liu Cc: David Hildenbrand , Oscar Salvador , Wei Yang , linux-mm@kvack.org, Yong Hu , Nanhai Zou , Tim Chen , Qiuxu Zhuo , Yu C Chen , Pan Deng , Tianyou Li , Chen Zhang , linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 1/2] mm: move overlap memory map init check to memmap_init() Message-ID: References: <20260421125508.2317429-1-yuan1.liu@intel.com> <20260421125508.2317429-2-yuan1.liu@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260421125508.2317429-2-yuan1.liu@intel.com> Hi, On Tue, Apr 21, 2026 at 08:55:07AM -0400, Yuan Liu wrote: > Move the overlap memmap init check from memmap_init_range() into > memmap_init(). > > When mirrored kernelcore is enabled, avoid memory map initialization > for overlap regions. There are two cases that may overlap: a mirror > memory region assigned to movable zone, or a non-mirror memory region > assigned to a non-movable zone but falling within the movable zone > range. > > Signed-off-by: Yuan Liu > --- > mm/mm_init.c | 37 +++++++++++++------------------------ > 1 file changed, 13 insertions(+), 24 deletions(-) > > diff --git a/mm/mm_init.c b/mm/mm_init.c > index df34797691bd..2b5233060504 100644 > --- a/mm/mm_init.c > +++ b/mm/mm_init.c > @@ -797,28 +797,6 @@ void __meminit reserve_bootmem_region(phys_addr_t start, > } > } > > -/* If zone is ZONE_MOVABLE but memory is mirrored, it is an overlapped init */ > -static bool __meminit > -overlap_memmap_init(unsigned long zone, unsigned long *pfn) > -{ > - static struct memblock_region *r; > - > - if (mirrored_kernelcore && zone == ZONE_MOVABLE) { > - if (!r || *pfn >= memblock_region_memory_end_pfn(r)) { > - for_each_mem_region(r) { > - if (*pfn < memblock_region_memory_end_pfn(r)) > - break; > - } > - } > - if (*pfn >= memblock_region_memory_base_pfn(r) && > - memblock_is_mirror(r)) { > - *pfn = memblock_region_memory_end_pfn(r); > - return true; > - } > - } > - return false; > -} > - > /* > * Only struct pages that correspond to ranges defined by memblock.memory > * are zeroed and initialized by going through __init_single_page() during > @@ -905,8 +883,6 @@ void __meminit memmap_init_range(unsigned long size, int nid, unsigned long zone > * function. They do not exist on hotplugged memory. > */ > if (context == MEMINIT_EARLY) { > - if (overlap_memmap_init(zone, &pfn)) > - continue; > if (defer_init(nid, pfn, zone_end_pfn)) { > deferred_struct_pages = true; > break; > @@ -971,6 +947,7 @@ static void __init memmap_init(void) > > for_each_mem_pfn_range(i, MAX_NUMNODES, &start_pfn, &end_pfn, &nid) { > struct pglist_data *node = NODE_DATA(nid); > + struct memblock_region *r = &memblock.memory.regions[i]; Please move this declaration above struct pglist_data, let's keep reverse xmas tree where possible. > > for (j = 0; j < MAX_NR_ZONES; j++) { > struct zone *zone = node->node_zones + j; > @@ -978,6 +955,18 @@ static void __init memmap_init(void) > if (!populated_zone(zone)) > continue; > > + if (mirrored_kernelcore) { > + const bool is_mirror = memblock_is_mirror(r); > + const bool is_movable_zone = (j == ZONE_MOVABLE); > + > + if (is_mirror && is_movable_zone) > + continue; > + > + if (!is_mirror && !is_movable_zone && > + start_pfn >= zone_movable_pfn[nid]) > + continue; > + } > + I think this: if (mirrored_kernelcore && j == ZONE_MOVABLE && memblock_is_mirror(r)) continue; would be enough to remove overlap_memmap_init() and keep the existing logic. I wouldn't deal the theoretical cases Wei mentioned in this thread for now and prefer to keep the things simple. The assumptions that mirrored memory spans a contiguous range below some limit and that mirrored memory is not removable existed for years and I don't see why we should change the logic now and complicate the code for exotic theoretical memory layouts. > memmap_init_zone_range(zone, start_pfn, end_pfn, > &hole_pfn); > zone_id = j; > -- > 2.47.3 > -- Sincerely yours, Mike.