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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1168CF6495 for ; Sun, 29 Sep 2024 09:18:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3BB166B025C; Sun, 29 Sep 2024 05:18:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 31D5B6B0260; Sun, 29 Sep 2024 05:18:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1BDC76B0285; Sun, 29 Sep 2024 05:18:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id EE59D6B025C for ; Sun, 29 Sep 2024 05:18:21 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6CF2C1418FE for ; Sun, 29 Sep 2024 09:18:21 +0000 (UTC) X-FDA: 82617224802.07.D51F3DE Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf14.hostedemail.com (Postfix) with ESMTP id B640310000D for ; Sun, 29 Sep 2024 09:18:18 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pL7Ypfqy; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727601375; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kwMglk322FusEbs5YNOhLhD4txEEf2Ph5DZWBn71s8o=; b=u0NSVyWhDjSBSW1tFl60Ym5rSr9PsDYd1lowgjmufSlZlqkEgiqlO6dVRNdJYMkatyWgB0 Joj/z8vHix1BaN4XULGtLONsfG3FC24dlqW+kToI8Q0sG5LboICAHPpRDd8/WM7f5DQwo1 v4lHCLSNjRW+hTlglhJjexxCFbrFne0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727601375; a=rsa-sha256; cv=none; b=AEsnDp9KcGTNAIfJa2zHoIe8YzfZt3ecye1Q+j2EGyuc+3gBppyq6r+EpFtlfeGL5h6JFh ZfAg/qVc6POlHdmZ/5m4gb6Jj4rbacgPeUQsSBbgg4S+QSPnhWokGlLat8g0WcvZd7Js+t J05LzND8TbPLZt4XsoeNUd2PPA68h0A= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=pL7Ypfqy; spf=pass (imf14.hostedemail.com: domain of rppt@kernel.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=rppt@kernel.org; dmarc=pass (policy=quarantine) header.from=kernel.org Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 820255C2DF4; Sun, 29 Sep 2024 09:18:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE664C4CEC5; Sun, 29 Sep 2024 09:18:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1727601497; bh=vrFJDvLvXruD2pfE+p9bt0gIo4ESSyyo7ec0Oqtc7eI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pL7Ypfqy3y+BEQPyxLVxRR0kKhETeRJNEvrLbNWaPQ/Gc1Gl1qbpBDN4CBpjecWB3 I0jSEHf/oUPnYMzqXeLAxuKcwcQmFJIRu5auGHt58OQhqMmQPCHyj9+fChmoo5KTl/ jDEMGdaYg5rdyNppWRGIf8FWan7+BvY6cfcrALgaEhpVTHDMi8g7TB5FEpdUaGUSMm FJl0pyIg3tagTXnKdGZ3HRQa9cVDviED67ROtwD13gSRgxsdtCmjmCjHydrbWUbEuY iUcFkdWI8obmBxUhOm5J8m3dQf7F3o5Of0H3PkwfIBnJwSlrDel3a7/DRVdiBlPezj QQfr/qWmyS7qw== Date: Sun, 29 Sep 2024 12:15:02 +0300 From: Mike Rapoport To: suhua Cc: akpm@linux-foundation.org, muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, suhua Subject: Re: [PATCH v1] memblock: Initialized the memory of memblock.reserve to the MIGRATE_MOVABL Message-ID: References: <20240925110235.3157-1-suhua1@kingsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240925110235.3157-1-suhua1@kingsoft.com> X-Rspamd-Queue-Id: B640310000D X-Stat-Signature: d614ysh33oo6izzh41tka8xt9eb1zpck X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727601498-793918 X-HE-Meta: U2FsdGVkX18bCrS8C02z8yUS191lJtav7stPeRhNA5i5bDl/5AmOt+td7pX5cbjS7JaxUBSGTRPgBx3w0YK/f1/s19A8MmG4yQEtL43Venb9+FoJ2QCUh0IWpw7F56Yj9Okx6TqL8RQy1tgezMDtFcdfhVIIdk37SlBIy9qpnKEI9fYmjrhXUqQnmbErsaDG5XkZAuWeRx1oIc5/Prnnl+kW2ypr/il0sxBlsFs8DUPTnOmxLMAXLZWJUssK7SOBT+4Xcy4uhFgTkGt0DBg6gpvNtbTRVniTRAElWk9Es5q2JJnqwyGv1VtB61Pb/KDC67Euz7S53oS4P2vaa0t7M1UM+OIswJwowivI5Hrs3BbMMUTg5hNx/gfBHSbuj6UeE4fp+kJ00aAelgUvaWFsbp7Fjci0jZ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.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Sep 25, 2024 at 07:02:35PM +0800, suhua wrote: > After sparse_init function requests memory for struct page in memblock and > adds it to memblock.reserved, this memory area is present in both > memblock.memory and memblock.reserved. > > When CONFIG_DEFERRED_STRUCT_PAGE_INIT is not set. The memmap_init function > is called during the initialization of the free area of the zone, this > function calls for_each_mem_pfn_range to initialize all memblock.memory, > excluding memory that is also placed in memblock.reserved, such as the > struct page metadata that describes the page, 1TB memory is about 16GB, > and generally this part of reserved memory occupies more than 90% of the > total reserved memory of the system. So all memory in memblock.memory is > set to MIGRATE_MOVABLE according to the alignment of pageblock_nr_pages. > For example, if hugetlb_optimize_vmemmap=1, huge pages are allocated, the > freed pages are placed on buddy's MIGRATE_MOVABL list for use. Please make sure you spell MIGRATE_MOVABLE and MIGRATE_UNMOVABLE correctly. > When CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only the first_deferred_pfn range > is initialized in memmap_init. The subsequent free_low_memory_core_early > initializes all memblock.reserved memory but not MIGRATE_MOVABL. All > memblock.memory is set to MIGRATE_MOVABL when it is placed in buddy via > free_low_memory_core_early and deferred_init_memmap. As a result, when > hugetlb_optimize_vmemmap=1 and huge pages are allocated, the freed pages > will be placed on buddy's MIGRATE_UNMOVABL list (For example, on machines > with 1TB of memory, alloc 2MB huge page size of 1000GB frees up about 15GB > to MIGRATE_UNMOVABL). Since the huge page alloc requires a MIGRATE_MOVABL > page, a fallback is performed to alloc memory from MIGRATE_UNMOVABL for > MIGRATE_MOVABL. > > Large amount of UNMOVABL memory is not conducive to defragmentation, so > the reserved memory is also set to MIGRATE_MOVABLE in the > free_low_memory_core_early phase following the alignment of > pageblock_nr_pages. > > Eg: > echo 500000 > /proc/sys/vm/nr_hugepages > cat /proc/pagetypeinfo > > before: > Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10 > … > Node 0, zone Normal, type Unmovable 51 2 1 28 53 35 35 43 40 69 3852 > Node 0, zone Normal, type Movable 6485 4610 666 202 200 185 208 87 54 2 240 > Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 > Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 > Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0 > Unmovable ≈ 15GB > > after: > Free pages count per migrate type at order 0 1 2 3 4 5 6 7 8 9 10 > … > Node 0, zone Normal, type Unmovable 0 1 1 0 0 0 0 1 1 1 0 > Node 0, zone Normal, type Movable 1563 4107 1119 189 256 368 286 132 109 4 3841 > Node 0, zone Normal, type Reclaimable 2 2 1 23 13 1 2 1 0 1 0 > Node 0, zone Normal, type HighAtomic 0 0 0 0 0 0 0 0 0 0 0 > Node 0, zone Normal, type Isolate 0 0 0 0 0 0 0 0 0 0 0 > > Signed-off-by: suhua > --- > mm/mm_init.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/mm/mm_init.c b/mm/mm_init.c > index 4ba5607aaf19..e0190e3f8f26 100644 > --- a/mm/mm_init.c > +++ b/mm/mm_init.c > @@ -722,6 +722,12 @@ static void __meminit init_reserved_page(unsigned long pfn, int nid) > if (zone_spans_pfn(zone, pfn)) > break; > } > + > + if (pageblock_aligned(pfn)) { > + set_pageblock_migratetype(pfn_to_page(pfn), MIGRATE_MOVABLE); > + cond_resched(); > + } If you are trying to make initialization of pageblock migrate type consistent with or without CONFIG_DEFERRED_STRUCT_PAGE_INIT, move setting of migrate type from deferred_free_pages() to deferred_init_pages(). > + > __init_single_page(pfn_to_page(pfn), pfn, zid, nid); > } > #else > -- > 2.34.1 > -- Sincerely yours, Mike.