From patchwork Wed Jan 29 22:41:41 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: 13954209 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 CE756C02193 for ; Wed, 29 Jan 2025 22:43:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CBCF928009D; Wed, 29 Jan 2025 17:42:39 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C6B6B28008C; Wed, 29 Jan 2025 17:42:39 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9FABD28009D; Wed, 29 Jan 2025 17:42:39 -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 7B26628008C for ; Wed, 29 Jan 2025 17:42:39 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 36A601C7029 for ; Wed, 29 Jan 2025 22:42:39 +0000 (UTC) X-FDA: 83061965238.09.996D197 Received: from mail-pl1-f201.google.com (mail-pl1-f201.google.com [209.85.214.201]) by imf24.hostedemail.com (Postfix) with ESMTP id 6C6AE180002 for ; Wed, 29 Jan 2025 22:42:37 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MESzq7Oy; spf=pass (imf24.hostedemail.com: domain of 33K6aZwQKCOcOeMUPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--fvdl.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=33K6aZwQKCOcOeMUPXXPUN.LXVURWdg-VVTeJLT.XaP@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=1738190557; 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=tk6hF6rqBW9AusrfDePvQanEIhsmPpyv3aYoz52NJE8=; b=OaB+FQwEyHJtkY4mDeSJOBGaGKq9e/TWCiRSE5PE9n1N+RScNICCi/hIiWGY5xDu1wU8nT RF4CDB7IYJVWBuDNsKxY8hkrpMUbMTutMdsfcWnppW8X9m7MNkx9fQghlu4sIfDmUS8rEj IxrGVvRE8kqLwk9+oSh+W68gTpQpJUQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=MESzq7Oy; spf=pass (imf24.hostedemail.com: domain of 33K6aZwQKCOcOeMUPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--fvdl.bounces.google.com designates 209.85.214.201 as permitted sender) smtp.mailfrom=33K6aZwQKCOcOeMUPXXPUN.LXVURWdg-VVTeJLT.XaP@flex--fvdl.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1738190557; a=rsa-sha256; cv=none; b=2Xr7a36AlyNsQKHSO1iB0iWv7hIh24WENYXCRBV0D7qowcE5w46Eis6JpbiIwl57SGt520 hGEcPjZ6BcSjCEfaHqC3URnkSL8fv/IJzYQnsh/Oa7ySLlgdtHcSuOu20R8fakVr7CvMeO QMJXbZWeTe5oHEvFDh/l2bwG8aPXWY8= Received: by mail-pl1-f201.google.com with SMTP id d9443c01a7336-2166f9f52fbso3843935ad.2 for ; Wed, 29 Jan 2025 14:42:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1738190556; x=1738795356; 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=tk6hF6rqBW9AusrfDePvQanEIhsmPpyv3aYoz52NJE8=; b=MESzq7Oy+JFHEmmusxhcMIBf3OqE8lwCT9Z+N0nZ+fDAF8ELcEwcc+rcRRwWGcS/MT E05YhXi05ve//29IXE7v7UB7v9MdTa+AxQldanQkoublJ1tteFZ4UyEdHoBmCgUrTw5M HrhaZMxw/yAaPH5wmhpu+YAPQqORNbuyKul5ENA+kqSA7FIq0AUJm09luL8xdA3EBjG9 NXNVKw6A5euQZ5kMfrFmnWcigxlUAd/af/1lnYFIw0wiotlVWCie8kJ3vtjFEzkniRpM 5iHqqpZKowWmLTJedxTxg7PFl1mYGxWs6XV7Z8ILJVQd1m+XSYREVbWJnYEs7s6Oo2Bm jN3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738190556; x=1738795356; 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=tk6hF6rqBW9AusrfDePvQanEIhsmPpyv3aYoz52NJE8=; b=gy3Yjm1s7HnNM3r0l2lJa98qGOql8ZQGBNjkZDuiW2lJY2WFcINogomXha6/5JnMNn ZyJcMyfqvfUiYi+6BBInryvrDrEa55ftiOrEySjhF09D9Q5lAd9mzMk8rN9I4YvYXKga 48Ajvh9uI5HedXFHWsXwF5BEdvG753zg1AX1anh9W/Hrk/nlPTb+09VTM5KpzdA2tlE8 xCfwXf/76AobwtJyoEVtmxOqRWnsb4Yq2gT6jw4pB/zoEUeG3Q7Mm+YXNZTmzG76mbXN 3OC2TaUqHKtAuzH5OHMag9YojyGj2Ee52cOZlTZCvq3uqo0Cv7nm0KvIRUNj6/lI4zQz ovIQ== X-Forwarded-Encrypted: i=1; AJvYcCXOvwYM8Hmg8Nc/fKFNsx4o7W1qgXbShOk+V2eDr3Am8zJNrR5j7l8A8kmwuQwHv/4gBVrEVT0JNQ==@kvack.org X-Gm-Message-State: AOJu0YysqInuOpnKOuxTHJDs9H5f0sdLdz4rgLxu6JVI/S+wZHXrH5zu 8L2t7udDq0CCGSbKBOYvBcXHiTAe74eGPvtQ3PbRQtK8rnSgtP37bCF24a0/4Z0WaDI31w== X-Google-Smtp-Source: AGHT+IEqjJb+x+dhP5rhHYNRAeOuV6o2kqh55KQZeq8wjY02yXG128DZoAUhFzB6wXoeeE68EWhcrrD9 X-Received: from pfbay42.prod.google.com ([2002:a05:6a00:302a:b0:729:9f1:663e]) (user=fvdl job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:c91b:b0:1eb:3623:59fd with SMTP id adf61e73a8af0-1ed7a48c425mr8653488637.4.1738190556311; Wed, 29 Jan 2025 14:42:36 -0800 (PST) Date: Wed, 29 Jan 2025 22:41:41 +0000 In-Reply-To: <20250129224157.2046079-1-fvdl@google.com> Mime-Version: 1.0 References: <20250129224157.2046079-1-fvdl@google.com> X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: <20250129224157.2046079-13-fvdl@google.com> Subject: [PATCH v2 12/28] 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, usamaarif642@gmail.com, joao.m.martins@oracle.com, roman.gushchin@linux.dev, Frank van der Linden X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 6C6AE180002 X-Stat-Signature: dkjopkjhuxe4ifjc78p5osrzetbh7sc1 X-Rspam-User: X-HE-Tag: 1738190557-518493 X-HE-Meta: U2FsdGVkX1+2cmTHg/tJOTVuYTI18S8KW+h9kiKUqT+CmgeqqSDaFHyKwq4p1RIOzU6JKTg3WQWjY7VzjcnjnGBuy0s6jkHAlvHhd2DkqFtIpez6ExHN/Lh4SvgVwq3PY/rrOh0RUVfDrROjtwVLPy6g5ZVYSCGX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+fxoU0BJkhUASXoBUgTALFl7ngxljqVCEXGV32qdBoaEguHeJUfnHwkZnrVE4ZP1GAymLSlOINH3MAqRb4Ic3KKYVXKHV4Yn1PA/y+OGz45WgH3N677Igj5QSzxjFjM5xoT9PgE8Dn8p5N//46+o5urxsuRu1NAdGzewG8QQl3p18AbrFiEzq9Z1nXssVTI3fzFiQG0dXVe4EtFc52if48406j2/w9ZMk2C/NhT1MwEn/u6Sjb3GCuctz//unGyDrx9oaMWG7FBsR3zLQ9Ik9rypg== 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 c16ed9790022..e5ca5cf2c6fd 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));