Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=44.246.1.125 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1793862295; b=0p3aN3ZZaKo95BwnICnva+H0RlmfMcS2V32L7LixRTfpxvwRrRUgvVim3aoad1YW0hhZ kWANU0zxMhmyOjW/PS3mZ0gNYbkydutWZpLmhR2g7rfnM/k8lgTO6BwR6+1T3X7qdqzJ+ 43Bv4TZjY3q3oIpDg7QuuzEqYJSyJ5GxtLgyfrzT4r2jpUaylbM87pmJhf6JkmIMQ4eMI +lLT8AhlTk0X12uZek4zaKEzGbGva9Gm4RkqGFmVQGvm35fDVBVd2QfXxzCMHeh3YNsoA b5EKJDKkrRXajtgIhcUV1B8JUa3ZMLkGgYTyKS2ZX0dGlU7D9sanlM9p32l3sV4OgJw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1793862295; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:Received:Received:X-Farcaster-Flow-ID:Received:Received: From:To:CC:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:Content-Type:X-Originating-IP: X-ClientProxiedBy; bh=4l44b+AwhAEl7Y2yYU1zn4HtQwsLDMpz34p1PtYCmP8=; b=4Zym9BDrfH7JGjS1s1e6r7W8qCIto5yBSZXLH1Kq0/HeAxb90yJZS9q9gywJTorP2Oc6 eC3k1MYV+ZLfSE4Ul5hojd44nJeaJXl3rYOj1ZzZuJi3AZqogC4QyPCEIZu9ezWCy5hG0 5c+cV3MfCcN31xiO3GXZIZ7ADLSqN5y4Gc4DjoneeCtwqr2bbF4yiwya2wNfM8uNqndyO r2/zXPwb3clhiQalRp4FSB9cut7b1009zSA0MEBew8fjsOp5tEy+e/8rVKT6fVLub/9nq FSx5Srs+gp80IOev/qqoBwKCuXRvu7K7U7uFUNmH8tmSe+vRuwuIiIxfIuNkwHEGHJA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=amazon.com; spf=pass smtp.mailfrom=amazon.com; dkim=pass header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazoncorp2 header.b=Sz5nEFKI; arc=none smtp.remote-ip=44.246.1.125 Received: from pdx-out-002.esa.us-west-2.outbound.mail-perimeter.amazon.com (pdx-out-002.esa.us-west-2.outbound.mail-perimeter.amazon.com [44.246.1.125]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 15AF4606A31B for ; Thu, 5 Nov 2026 07:04:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 15AF4606A31B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amazon.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=amazon.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=amazon.com header.i=@amazon.com header.a=rsa-sha256 header.s=amazoncorp2 header.b=Sz5nEFKI DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazoncorp2; t=1793862295; x=1825398295; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=4l44b+AwhAEl7Y2yYU1zn4HtQwsLDMpz34p1PtYCmP8=; b=Sz5nEFKIBDejuv/2WNEMQweEdn9KibmPK2KQWpuuYNNl+J80yx/gCKl9 Lvgs1z/8AMY4YLtH8xnZ5uo72anmgulJLMXnwwj5YFaLrYgYyoiNDNOB5 ECPJGVyJ9sWrqdVd7orv5Q83SZIjJoGP0eL/B3/vhCl3z5q6Gd/h0hEug eKV0i1LytCdzkxQ5GJeK11v7PBzOGa1SAJYeJAbRD3s680tjuAqefopsS TWsTlcEWvKItqgGCuwvQ7sApx7w6xBbBF58AxHf7VPeGQYUkGRtJh/LF/ y2FfZLyxDyacPUelVX0qG3Are/UtCxX3I2ty8rq4Fcp+0B5Vbn6YkLsrF Q==; X-CSE-ConnectionGUID: JwTQVVBvTEuV0LKc2KPDLw== X-CSE-MsgGUID: SXXMfe1cQbW+BPEL5CX4oA== X-IronPort-AV: E=Sophos;i="6.27,196,1787011200"; d="scan'208";a="33172376" Received: from ip-10-5-6-203.us-west-2.compute.internal (HELO smtpout.naws.us-west-2.prod.farcaster.email.amazon.dev) ([10.5.6.203]) by internal-pdx-out-002.esa.us-west-2.outbound.mail-perimeter.amazon.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Nov 2026 07:04:54 +0000 Received: from EX19MTAUWC001.ant.amazon.com [205.251.233.53:23408] by smtpin.naws.us-west-2.prod.farcaster.email.amazon.dev [10.0.15.208:2525] with esmtp (Farcaster) id e60c700b-b0ba-4d1a-b314-1637a485e3b6; Thu, 5 Nov 2026 07:04:54 +0000 (UTC) X-Farcaster-Flow-ID: e60c700b-b0ba-4d1a-b314-1637a485e3b6 Received: from EX19D001UWA001.ant.amazon.com (10.13.138.214) by EX19MTAUWC001.ant.amazon.com (10.250.64.174) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.56; Thu, 5 Nov 2026 07:04:54 +0000 Received: from dev-dsk-mkbund-2b-9ea2efba.us-west-2.amazon.com (10.2.100.138) by EX19D001UWA001.ant.amazon.com (10.13.138.214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA) id 15.2.2562.56; Thu, 5 Nov 2026 07:04:54 +0000 From: Mark Bundschuh To: CC: , , yangge , Baolin Wang , Barry Song <21cnbao@gmail.com>, David Hildenbrand , SeongJae Park , "Andrew Morton" , Mark Bundschuh Subject: [PATCH 6.12] mm: replace free hugepage folios after migration Date: Thu, 5 Nov 2026 07:04:42 +0000 Message-ID: <20261105070442.3101877-1-mkbund@amazon.com> X-Mailer: git-send-email 2.50.1 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: EX19D031UWA003.ant.amazon.com (10.13.139.47) To EX19D001UWA001.ant.amazon.com (10.13.138.214) From: yangge [ Upstream commit 04f13d241b8b146b23038bffd907cb8278391d07 ] My machine has 4 NUMA nodes, each equipped with 32GB of memory. I have configured each NUMA node with 16GB of CMA and 16GB of in-use hugetlb pages. The allocation of contiguous memory via cma_alloc() can fail probabilistically. When there are free hugetlb folios in the hugetlb pool, during the migration of in-use hugetlb folios, new folios are allocated from the free hugetlb pool. After the migration is completed, the old folios are released back to the free hugetlb pool instead of being returned to the buddy system. This can cause test_pages_isolated() check to fail, ultimately leading to the failure of cma_alloc(). Call trace: cma_alloc() __alloc_contig_migrate_range() // migrate in-use hugepage test_pages_isolated() __test_page_isolated_in_pageblock() PageBuddy(page) // check if the page is in buddy To address this issue, we introduce a function named replace_free_hugepage_folios(). This function will replace the hugepage in the free hugepage pool with a new one and release the old one to the buddy system. After the migration of in-use hugetlb pages is completed, we will invoke replace_free_hugepage_folios() to ensure that these hugepages are properly released to the buddy system. Following this step, when test_pages_isolated() is executed for inspection, it will successfully pass. Additionally, when alloc_contig_range() is used to migrate multiple in-use hugetlb pages, it can result in some in-use hugetlb pages being released back to the free hugetlb pool and subsequently being reallocated and used again. For example: [huge 0] [huge 1] To migrate huge 0, we obtain huge x from the pool. After the migration is completed, we return the now-freed huge 0 back to the pool. When it's time to migrate huge 1, we can simply reuse the now-freed huge 0 from the pool. As a result, when replace_free_hugepage_folios() is executed, it cannot release huge 0 back to the buddy system. To address this issue, we should prevent the reuse of isolated free hugepages during the migration process. Link: https://lkml.kernel.org/r/1734503588-16254-1-git-send-email-yangge1116@126.com Link: https://lkml.kernel.org/r/1736582300-11364-1-git-send-email-yangge1116@126.com Signed-off-by: yangge Cc: Baolin Wang Cc: Barry Song <21cnbao@gmail.com> Cc: David Hildenbrand Cc: SeongJae Park Signed-off-by: Andrew Morton [ 6.12: Take only the dequeue_hugetlb_folio_node_exact() hunk, so memory offline stops migrating huge pages back into the isolated range. ] Signed-off-by: Mark Bundschuh --- Without this, offlining a memory block holding mapped huge pages keeps migrating them back into the block until the offline is interrupted. Reproduced on arm64 on 5.10 and 6.12 (stock AL2023 6.12.113): the offline was still migrating after 60 s. With this patch on 5.10 it completes in 0.15 s with the data intact. Also sent for 5.10, 5.15, 6.1, 6.6 and 6.12. mm/hugetlb.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 68e0cc0748ca..b4c6c926a71e 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -48,6 +48,7 @@ #include #include "internal.h" #include "hugetlb_vmemmap.h" +#include int hugetlb_max_hstate __read_mostly; unsigned int default_hstate_idx; @@ -1350,6 +1351,9 @@ static struct folio *dequeue_hugetlb_folio_node_exact(struct hstate *h, if (folio_test_hwpoison(folio)) continue; + if (is_migrate_isolate_page(&folio->page)) + continue; + list_move(&folio->lru, &h->hugepage_activelist); folio_ref_unfreeze(folio, 1); folio_clear_hugetlb_freed(folio); -- 2.50.1