FAILED: patch "[PATCH] mm: hugetlb: return -ENOSPC on memcg charge failure" failed to apply to 6.18-stable tree
Subsystems (3)
Sasha Levin
maintainerThe patch below does not apply to the 6.18-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.18.y
git checkout FETCH_HEAD
git cherry-pick -x 956aeff185e7e16b989202bde0bb29859adba99d
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 6.18.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From 956aeff185e7e16b989202bde0bb29859adba99d Mon Sep 17 00:00:00 2001
From: Ackerley Tng <[email protected]>
Date: Wed, 9 Sep 2026 10:11:00 -0700
Subject: [PATCH] mm: hugetlb: return -ENOSPC on memcg charge failure
Patch series "Fix bugs in HugeTLB allocation whenmem_cgroup_charge_hugetlb() fails", v2.
In hugetlb_alloc_folio(), when mem_cgroup_charge_hugetlb() fails, there are 2 issues:
1. free_huge_folio() expects a non-refcounted folio and will VM_BUG_ON_FOLIO().
2. -ENOMEM is returned, causing an infinite loop retrying the fault.
This patch (of 2):
When mem_cgroup_charge_hugetlb() fails with -ENOMEM, alloc_hugetlb_folio() currently propagates this error. This results in the page fault handler returning VM_FAULT_OOM.
Because HugeTLB allocations are high-order and use __GFP_RETRY_MAYFAIL, they bypass the OOM killer. Returning VM_FAULT_OOM to the #PF handler without triggering the OOM killer (or having it make progress) leads to an infinite loop of retrying the fault.
Avoid this loop by returning -ENOSPC when charging fails, which maps to VM_FAULT_SIGBUS, terminating the process cleanly.
Make mem_cgroup_charge_hugetlb() fault handling use a common error handling path, the same handling used for hugetlb_cgroup_uncharge_cgroup{,_rsvd}(), which also don't trigger the OOM killer and hence opt to terminate the process with a SIGBUS.
--- mm/hugetlb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
mm/hugetlb.c +5 -2
@@ -2851,7 +2851,6 @@ void wait_for_freed_hugetlb_folios(void)* * Return: A pointer to the allocated folio, or an ERR_PTR on failure. * -ENOSPC if cgroup charging fails or no folio is available. -* -ENOMEM if mem cgroup charging fails. */ struct folio *hugetlb_alloc_folio (struct hstate *h,struct mempolicy_interpreted *mpoli,u8 alloc_flags)
@@ -2924,7 +2923,11 @@ struct folio *hugetlb_alloc_folio(struct hstate *h,* were committed to the folio and freeing the folio * would have cleared those up. */ -return ERR_PTR (ret); +/* +* Return -ENOSPC, since retrying the fault is futile: +* the OOM killer is not triggered for HugeTLB. +*/ +return ERR_PTR (-ENOSPC ); }return folio;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 mm: hugetlb: return -ENOSPC on memcg charge failure
From: Ackerley Tng <[email protected]>
[ Upstream commit 956aeff185e7e16b989202bde0bb29859adba99d ]
Patch series "Fix bugs in HugeTLB allocation whenmem_cgroup_charge_hugetlb() fails", v2.
In hugetlb_alloc_folio(), when mem_cgroup_charge_hugetlb() fails, there are 2 issues:
1. free_huge_folio() expects a non-refcounted folio and will VM_BUG_ON_FOLIO().
2. -ENOMEM is returned, causing an infinite loop retrying the fault.
This patch (of 2):
When mem_cgroup_charge_hugetlb() fails with -ENOMEM, alloc_hugetlb_folio() currently propagates this error. This results in the page fault handler returning VM_FAULT_OOM.
Because HugeTLB allocations are high-order and use __GFP_RETRY_MAYFAIL, they bypass the OOM killer. Returning VM_FAULT_OOM to the #PF handler without triggering the OOM killer (or having it make progress) leads to an infinite loop of retrying the fault.
Avoid this loop by returning -ENOSPC when charging fails, which maps to VM_FAULT_SIGBUS, terminating the process cleanly.
Make mem_cgroup_charge_hugetlb() fault handling use a common error handling path, the same handling used for hugetlb_cgroup_uncharge_cgroup{,_rsvd}(), which also don't trigger the OOM killer and hence opt to terminate the process with a SIGBUS.
--- mm/hugetlb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
mm/hugetlb.c +5 -1
@@ -3134,7 +3134,11 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,if (ret == -ENOMEM ) {free_huge_folio (folio); -return ERR_PTR (-ENOMEM ); +/* +* Return -ENOSPC, since retrying the fault is futile: +* the OOM killer is not triggered for HugeTLB. +*/ +return ERR_PTR (-ENOSPC ); }return folio;
Signature · 1 line
2.53.0