From patchwork Mon Jan 27 23:21:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank van der Linden X-Patchwork-Id: 13951853 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 EF256C0218C for ; Mon, 27 Jan 2025 23:23:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D90D02801B8; Mon, 27 Jan 2025 18:22:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D3C8128013A; Mon, 27 Jan 2025 18:22:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BB4D12801B8; Mon, 27 Jan 2025 18:22:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 9867828013A for ; Mon, 27 Jan 2025 18:22:46 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 53C9280899 for ; Mon, 27 Jan 2025 23:22:46 +0000 (UTC) X-FDA: 83054808732.11.F275A1B Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) by imf14.hostedemail.com (Postfix) with ESMTP id 5E86A100014 for ; Mon, 27 Jan 2025 23:22:44 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=NrnTfdsm; spf=pass (imf14.hostedemail.com: domain of 3QxWYZwQKCBIxDv3y66y3w.u64305CF-442Dsu2.69y@flex--fvdl.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3QxWYZwQKCBIxDv3y66y3w.u64305CF-442Dsu2.69y@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1738020164; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ahGehxe7VKaUNIFIiK0DUduVLM+snH5y4prr1K+tq+0=; b=7yaQIR2/a61bd0EMSd67sQoT1Zh1cnfYvoHmsgTpq9IiJHymLJzerl9dZ9vkI/fuhNYaE8 RGsVRl5FJWDewC/Q/xt9Va0j6iJ/wQwIfNR9pCKtXZ1SiEJPpzuFE17qToFrjHScw62WiG zDptCNT0Nfz80TKW4XFkyRHNhUClwAU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738020164; a=rsa-sha256; cv=none; b=nl3gVTsYs1BAl2hchqNB1Zk5RMRM3psccdou7zKELaHP5YxjHwVQB4IfY1vxaKsRACuryX tlp3EIswoKTy3qAKoucDsQWcqOS8F38ORJE7j7tqzfr4XlBHx+eLI4NxzoC8elMIZBnh4k djxrF4V7XdYvT3f00nEbdZChJ4G7Jlg= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=NrnTfdsm; spf=pass (imf14.hostedemail.com: domain of 3QxWYZwQKCBIxDv3y66y3w.u64305CF-442Dsu2.69y@flex--fvdl.bounces.google.com designates 209.85.216.73 as permitted sender) smtp.mailfrom=3QxWYZwQKCBIxDv3y66y3w.u64305CF-442Dsu2.69y@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2efa74481fdso10055552a91.1 for ; Mon, 27 Jan 2025 15:22:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738020163; x=1738624963; darn=kvack.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=ahGehxe7VKaUNIFIiK0DUduVLM+snH5y4prr1K+tq+0=; b=NrnTfdsmGIhVXZomVAmJfIiEcNOrRJObZI3cyfOA44oT+HlmZBbZlbFXoUWz6G8rXS 399lUiT/CGDcLJpedDP3etryFNvXFiB1qKYTwCHqxTJ8uWhUWuf72KQ/hDNYED9JoeJd PkksLMzrW5JsFx17qvaW+CP+zWuxACbG4MQTk3kHsUyGc6aEG7iHF2ovB/pdW3SXL/km 7beNLAz4gp2jbIw6Gb2bTXdELplLzPTFQ7MlNkT2EipNaxbdHYyjpKznHqJsi2Ov0K0N xElhmr5tdVd1IV4WOSqlZuQ3A/662VSIa9mnwOkZPIMpNEwI+bwVDIR3omMQiV7WAQy/ 8r1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738020163; x=1738624963; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=ahGehxe7VKaUNIFIiK0DUduVLM+snH5y4prr1K+tq+0=; b=KZzCKxCbdDfc5VLvrR0nxru/v5bzJJF/TWAiYB4DTEWMYRIPjQLlPRmBuFlts+1S/P Sox098MeQnD2j0rD4ks2TuLqhyYct8Zzf+COGwKaQ93NoThnNopky1Nd8CNlNR3Y3GGp l+YarOC6pJ49K7DB7HCGBMER2YLMOQCJXgLi9lWbi+9pw/Q0Bi6Oud5uqGh8J2pZrmLo PkkLLPMQW6GeIMMUkxqy2U4qN6igkZyxNN0VKkbAcPV0u/vw3WLhbDkOAn2HPGmcbs18 BYJwlUGp1cej4N/FVRHM66kD1PtzXGL7N4eCVERvNawvX/2LZTqgkor80PyHpUb0JmnP gsVQ== X-Forwarded-Encrypted: i=1; AJvYcCVm5TJ1IWPwt0zI6jlyEbWA2vGmU52msKfLh1nka3W0iPzkp1zQa9ybkncPax2iSD3O8GdqTjrA9A==@kvack.org X-Gm-Message-State: AOJu0YyO0LaImPoamvy8qMVQGdUaJwlWDGPjE8kYvnx3wOYbdSfHBpLt gdlg0gf8R1FrSMtln9NZeoHIVUQl3cOqq61WPss4s7VEAmWBg0eVvXZl4NurCSg0UYdoVw== X-Google-Smtp-Source: AGHT+IGFs3VKcM0qeDQDow0P008CgDVW9Bc9HLj1xsHRZgddaRUVV0k4+E5fjCd5lGcKYV5Gkvrp4cQ/ X-Received: from pfbeg15.prod.google.com ([2002:a05:6a00:800f:b0:725:c72a:a28a]) (user=fvdl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:181f:b0:727:3cd0:1167 with SMTP id d2e1a72fcca58-72dafba0247mr63641686b3a.21.1738020163186; Mon, 27 Jan 2025 15:22:43 -0800 (PST) Date: Mon, 27 Jan 2025 23:21:52 +0000 In-Reply-To: <20250127232207.3888640-1-fvdl@google.com> Mime-Version: 1.0 References: <20250127232207.3888640-1-fvdl@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250127232207.3888640-13-fvdl@google.com> Subject: [PATCH 12/27] mm/hugetlb: set migratetype for bootmem folios From: Frank van der Linden To: akpm@linux-foundation.org, muchun.song@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: yuzhao@google.com, usama.arif@bytedance.com, joao.m.martins@oracle.com, roman.gushchin@linux.dev, Frank van der Linden X-Stat-Signature: b8cqfxbzotg3yfb6m4k1xezsw9879m9d X-Rspamd-Queue-Id: 5E86A100014 X-Rspam-User: X-Rspamd-Server: rspam06 X-HE-Tag: 1738020164-973156 X-HE-Meta: U2FsdGVkX18lfsqaI6Bc0bg9w+YfvFY2DxhiUOUlhEspRg14vhi4TbhppUyN5Yd4KE6LGvXbl5kg3XPpUef5g2VY7CnPtxpJUDY0kIQcUrCmmboNYk405gzVpWWUk/anNGdJvO9rOYXnMIxGU5QQOyozBvLeewfKqzkfS9ioh9Hotpberef9sO3TO9A0jgCqkr31EM/Fkje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RY2KXV7AZ8ulHUQiUPmtPIPjyi+kiRaIgDxumaCWOAqhjpUSnwXGcdeqqdg3oxEfw6bpds21OAzt6JMlfCPrlYka0EhJt0q1PCfgcpZYA1dOx2Gw/5N96Am/El5ruMQwOq0JKN7LrwgWnkjRBiMxNfZH51dEnCmeHPxRrbgrpcqlsn7TPPUDSe1xHL0lop4JwLVLgzWXE6cNeSaFhU8+9ye0mTlJgm6JyF4xZaVYCdsRBtXHLbNW7JAtbDD7xwhaKKw== 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: List-Subscribe: List-Unsubscribe: The pageblocks that back memblock allocated hugetlb folios might not have the migrate type set, in the CONFIG_DEFERRED_STRUCT_PAGE_INIT case. memblock allocated hugetlb folios might be given to the buddy allocator eventually (if nr_hugepages is lowered), so make sure that the migrate type for the pageblocks contained in them is set when initializing them. Set it to the default that memmap init also uses (MIGRATE_MOVABLE). Signed-off-by: Frank van der Linden --- mm/hugetlb.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a95ab44d5545..9969717b7dd8 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include @@ -3258,6 +3259,26 @@ static void __init hugetlb_folio_init_vmemmap(struct folio *folio, prep_compound_head((struct page *)folio, huge_page_order(h)); } +/* + * memblock-allocated pageblocks might not have the migrate type set + * if marked with the 'noinit' flag. Set it to the default (MIGRATE_MOVABLE) + * here. + * + * Note that this will not write the page struct, it is ok (and necessary) + * to do this on vmemmap optimized folios. + */ +static void __init hugetlb_bootmem_init_migratetype(struct folio *folio, + struct hstate *h) +{ + unsigned long nr_pages = pages_per_huge_page(h), i; + + WARN_ON_ONCE(!pageblock_aligned(folio_pfn(folio))); + + for (i = 0; i < nr_pages; i += pageblock_nr_pages) + set_pageblock_migratetype(folio_page(folio, i), + MIGRATE_MOVABLE); +} + static void __init prep_and_add_bootmem_folios(struct hstate *h, struct list_head *folio_list) { @@ -3279,6 +3300,7 @@ static void __init prep_and_add_bootmem_folios(struct hstate *h, HUGETLB_VMEMMAP_RESERVE_PAGES, pages_per_huge_page(h)); } + hugetlb_bootmem_init_migratetype(folio, h); /* Subdivide locks to achieve better parallel performance */ spin_lock_irqsave(&hugetlb_lock, flags); __prep_account_new_huge_page(h, folio_nid(folio));