Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp129992rwb; Wed, 21 Sep 2022 18:54:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ILxoh6K+StLFvK8f87HE3Goo/fSU9POnXUTG7KjkUGhCKUde4MdjyHVoQ33xlobw1oVSC X-Received: by 2002:a05:6402:27d1:b0:44f:2c17:1a44 with SMTP id c17-20020a05640227d100b0044f2c171a44mr960700ede.18.1663811693962; Wed, 21 Sep 2022 18:54:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663811693; cv=none; d=google.com; s=arc-20160816; b=DCy8ip4M7RfO+IkEtxyhtumoqL1lnegIs4/OsvFNAP0g9b12xvX7zsRmS0MYujpS0j cX/JZSgigB/ig+Xvj/Ne2yURLJOqWNS/aRKjEc40do4UONifC/DAztC+d+D1WcvZ4sT/ 4JmW1ex0YNAHheSi/DCjjMJBcqPWfXov8NZacz+XDHAP35q0eVAVAbqLcgoO3A0QEalx s1BAEL7ebNUZ/7F+G9cnrAVKMLrppVDId7QkOmA5llr2dNhdMTBel9R4hm4AkkJnlu/5 VCsssnoCJcJDnexhI7+N1Y1NbNPbSGdtJJ31s16d/OonVgDEY2Cyno8gpIi+0HKEazbP lbew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:reply-to :references:in-reply-to:message-id:date:subject:cc:to:from :feedback-id:dkim-signature:dkim-signature; bh=6hIod5Xb/n6/GvZSv988w0dL7EymQUiDUpxAypFJV3A=; b=eCxK+Ayly3owv7KdaoOjhcE6B9bF1jhBTCTfLkCpkHfijMkFHr9iztRMr6HCy4Cqe1 x6BNk8YYO4apzJ1d2+2nFr2qRFi4HR5ix1XV1puTopML5+OI4BLjOfTrzHZFv1dkoU+8 ToDfK26tazuJHs8RqJ5pciy6AxehTIxY7gMBzMCNm7ALVEVbI2/Xat4xYgwkByOvMvkk 9jl+rSA9S4cRkpDbnpe7M7lFNA7eERiyU6IT1C5P3ftaPaQfQP+XtJ0Ncp1b2jF1gXHL nMkFI70zTszcm0/pkTjx+M/pYDFGyO7dx+TASbQseaBKOjqcA+IqlA2PKIAZgylXAgqy lHEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sent.com header.s=fm2 header.b=g7Hl4GZk; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=jir8dylm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hv22-20020a17090760d600b0078239e3f846si1399104ejc.1.2022.09.21.18.54.27; Wed, 21 Sep 2022 18:54:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@sent.com header.s=fm2 header.b=g7Hl4GZk; dkim=pass header.i=@messagingengine.com header.s=fm2 header.b=jir8dylm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sent.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230102AbiIVBNL (ORCPT + 99 others); Wed, 21 Sep 2022 21:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbiIVBNB (ORCPT ); Wed, 21 Sep 2022 21:13:01 -0400 Received: from out2-smtp.messagingengine.com (out2-smtp.messagingengine.com [66.111.4.26]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCAAFAA35A for ; Wed, 21 Sep 2022 18:12:57 -0700 (PDT) Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 304E25C0145; Wed, 21 Sep 2022 21:12:57 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Wed, 21 Sep 2022 21:12:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sent.com; h=cc :cc:content-transfer-encoding:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to :reply-to:sender:subject:subject:to:to; s=fm2; t=1663809177; x= 1663895577; bh=6hIod5Xb/n6/GvZSv988w0dL7EymQUiDUpxAypFJV3A=; b=g 7Hl4GZksfYJYKHux7Fd2YpcCSHO5mS3JUXy8fcKHPvVkPPkMdEFdlKech0GjtrB+ UhoHax5scLMYKxjoQjNyqgxYR5evq969VB9S7g4xUjel5JH4IdmH6vcQJmGOvfIi /NW23afwZnlfVDU0e7j34U46msX8vWSUgJk95CwULeN98Bk0yhDApxEcf7KX3li7 LI/qOg/pd5s3Zmz+swiy52pcxwZ5Fb+Ca1I8H9ezHpclUBml9qzVDM7VoTU4tEGm BPQVvDajtHKjXyVb8qvfrF/rMLEsde+1RM82aL3cAFGlXVVHUoCNMEilyIdIuK45 rDsiqIIxWmtvxIj1ncp7w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:reply-to:sender :subject:subject:to:to:x-me-proxy:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1663809177; x=1663895577; bh=6 hIod5Xb/n6/GvZSv988w0dL7EymQUiDUpxAypFJV3A=; b=jir8dylmgmGv34mmu SolLmqh5uuUvUyXUnTyb/4bjKXRPIfoO/LQZEzdMK8rcIsZyTmcqSUvYJ9UntiGP yhy6z/dg3fE5bBOKBi9nRhimkBUn02kL1TKHQxDdtEH/L5YULjTkbF+uEQR/x064 zNvwRuwGrP5rncAL/BsEgq7YAi7kkEXb2MHYlXVgkSEW3ZUeCFr2MT2eyw8tAfem S42tvNOj9sbTJE9ch5pMcG8LlQdfqVg/VIP97JCRPx9Sg1Mo+uhXFWaghZSfYal+ EkN8T9GI03YGdGu+fwL0hsmTL5mm0J7hHNeWQ4W6RS4gzyeNL14uMobvF731IuBF mLtXw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrfeefvddggeefucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhhrggfgsedtqhertdertddtnecuhfhrohhmpegkihcu jggrnhcuoeiiihdrhigrnhesshgvnhhtrdgtohhmqeenucggtffrrghtthgvrhhnpeegge ehudfgudduvdelheehteegledtteeiveeuhfffveekhfevueefieeijeegvdenucevlhhu shhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpeiiihdrhigrnhessh gvnhhtrdgtohhm X-ME-Proxy: Feedback-ID: iccd040f4:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 21 Sep 2022 21:12:56 -0400 (EDT) From: Zi Yan To: linux-mm@kvack.org Cc: Zi Yan , David Hildenbrand , Matthew Wilcox , Vlastimil Babka , "Kirill A . Shutemov" , Mike Kravetz , John Hubbard , Yang Shi , David Rientjes , James Houghton , Mike Rapoport , Muchun Song , Andrew Morton , linux-kernel@vger.kernel.org Subject: [PATCH v1 03/12] mm: adapt deferred struct page init to new MAX_ORDER. Date: Wed, 21 Sep 2022 21:12:43 -0400 Message-Id: <20220922011252.2266780-4-zi.yan@sent.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220922011252.2266780-1-zi.yan@sent.com> References: <20220922011252.2266780-1-zi.yan@sent.com> Reply-To: Zi Yan MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zi Yan deferred_init only initializes first section of a zone and defers the rest and the rest of the zone will be initialized in size of a section. When MAX_ORDER grows beyond a section size, early_page_uninitialised() did not prevent pages beyond first section from initialization, since it only checked the starting pfn and assumes MAX_ORDER is smaller than a section size. In addition, deferred_init_maxorder() uses MAX_ORDER_NR_PAGES as the initialization unit, which can cause the initialized chunk of memory overlapping with other initialization jobs. For the first issue, make early_page_uninitialised() decrease the order for non-deferred memory initialization when it is bigger than first section. For the second issue, when adjust pfn alignment in deferred_init_maxorder(), make sure the alignment is not bigger than a section size. Signed-off-by: Zi Yan --- mm/internal.h | 2 +- mm/memblock.c | 6 ++++-- mm/page_alloc.c | 28 ++++++++++++++++++++-------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 22fb1e6e3541..d688c0320cda 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -361,7 +361,7 @@ extern int __isolate_free_page(struct page *page, unsig= ned int order); extern void __putback_isolated_page(struct page *page, unsigned int order, int mt); extern void memblock_free_pages(struct page *page, unsigned long pfn, - unsigned int order); + unsigned int *order); extern void __free_pages_core(struct page *page, unsigned int order); extern void prep_compound_page(struct page *page, unsigned int order); extern void post_alloc_hook(struct page *page, unsigned int order, diff --git a/mm/memblock.c b/mm/memblock.c index acbc77367faf..b957c12a93e7 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1640,7 +1640,9 @@ void __init memblock_free_late(phys_addr_t base, phys= _addr_t size) end =3D PFN_DOWN(base + size); =20 for (; cursor < end; cursor++) { - memblock_free_pages(pfn_to_page(cursor), cursor, 0); + unsigned int order =3D 0; + + memblock_free_pages(pfn_to_page(cursor), cursor, &order); totalram_pages_inc(); } } @@ -2035,7 +2037,7 @@ static void __init __free_pages_memory(unsigned long = start, unsigned long end) while (start + (1UL << order) > end) order--; =20 - memblock_free_pages(pfn_to_page(start), start, order); + memblock_free_pages(pfn_to_page(start), start, &order); =20 start +=3D (1UL << order); } diff --git a/mm/page_alloc.c b/mm/page_alloc.c index b3dd5248e63d..e3af87d89ebf 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -464,13 +464,19 @@ static inline bool deferred_pages_enabled(void) } =20 /* Returns true if the struct page for the pfn is uninitialised */ -static inline bool __meminit early_page_uninitialised(unsigned long pfn) +static inline bool __meminit early_page_uninitialised(unsigned long pfn, u= nsigned int *order) { int nid =3D early_pfn_to_nid(pfn); =20 if (node_online(nid) && pfn >=3D NODE_DATA(nid)->first_deferred_pfn) return true; =20 + /* clamp down order to not exceed first_deferred_pfn */ + if (order) + *order =3D min_t(unsigned int, + *order, + ilog2(NODE_DATA(nid)->first_deferred_pfn - pfn)); + return false; } =20 @@ -518,7 +524,7 @@ static inline bool deferred_pages_enabled(void) return false; } =20 -static inline bool early_page_uninitialised(unsigned long pfn) +static inline bool early_page_uninitialised(unsigned long pfn, unsigned in= t *order) { return false; } @@ -1653,7 +1659,7 @@ static void __meminit init_reserved_page(unsigned lon= g pfn) pg_data_t *pgdat; int nid, zid; =20 - if (!early_page_uninitialised(pfn)) + if (!early_page_uninitialised(pfn, NULL)) return; =20 nid =3D early_pfn_to_nid(pfn); @@ -1809,15 +1815,15 @@ int __meminit early_pfn_to_nid(unsigned long pfn) #endif /* CONFIG_NUMA */ =20 void __init memblock_free_pages(struct page *page, unsigned long pfn, - unsigned int order) + unsigned int *order) { - if (early_page_uninitialised(pfn)) + if (early_page_uninitialised(pfn, order)) return; - if (!kmsan_memblock_free_pages(page, order)) { + if (!kmsan_memblock_free_pages(page, *order)) { /* KMSAN will take care of these pages. */ return; } - __free_pages_core(page, order); + __free_pages_core(page, *order); } =20 /* @@ -2036,7 +2042,13 @@ static unsigned long __init deferred_init_maxorder(u64 *i, struct zone *zone, unsigned long *start_pfn, unsigned long *end_pfn) { - unsigned long mo_pfn =3D ALIGN(*start_pfn + 1, MAX_ORDER_NR_PAGES); + /* + * deferred_init_memmap_chunk gives out jobs with max size to + * PAGES_PER_SECTION. Do not align mo_pfn beyond that. + */ + unsigned long align =3D min_t(unsigned long, + MAX_ORDER_NR_PAGES, PAGES_PER_SECTION); + unsigned long mo_pfn =3D ALIGN(*start_pfn + 1, align); unsigned long spfn =3D *start_pfn, epfn =3D *end_pfn; unsigned long nr_pages =3D 0; u64 j =3D *i; --=20 2.35.1