Re: [PATCH v7 2/3] mm/page_alloc: only free healthy pages in high-order folio

From: David Hildenbrand (Arm)

Date: Wed Dec 02 2026 - 11:54:11 EST


On 11/10/26 06:33, Jiaqi Yan wrote:
> At the end of dissolve_free_hugetlb_folio(), a free HugeTLB folio
> becomes non-HugeTLB, and it is released to buddy allocator as a
> high-order folio, e.g. a folio that contains 262144 pages if the
> folio was a 1G HugeTLB hugepage.
>
> This is problematic if the HugeTLB hugepage contained HWPoison
> subpages. In that case, since buddy allocator does not check
> HWPoison for non-zero-order folio, the raw HWPoison page can be
> given out with its buddy page and be re-used by either kernel or
> userspace.
>
> Memory failure recovery (MFR) in kernel does attempt to take raw
> HWPoison page off buddy allocator after
> dissolve_free_hugetlb_folio(). However, there is always a time
> window between dissolve_free_hugetlb_folio() frees a HWPoison
> high-order folio to buddy allocator and MFR takes HWPoison raw page
> off buddy allocator. Worse, a free HWPoison HugeTLB folio can also
> be dissolved outside of MFR, e.g. when shrinking the HugeTLB pool,
> and then nobody takes its HWPoison pages off buddy allocator.
>
> Another similar situation is when a transparent huge page (THP)
> runs into memory failure but splitting failed. Such THP will
> eventually be released to buddy allocator when owning userspace
> processes are gone, but with certain subpages having HWPoison.
>
> One obvious way to avoid these problems is to always check
> PageHWPoison() when allocating pages, which check_new_pages() only
> does if page sanity checks are enabled. However, it is against the
> past efforts to reduce sanity check overhead [1,2,3].
>
> Instead, keep HWPoison pages out of buddy allocator when freeing a
> high-order folio. __free_pages_prepare() already walks through all
> tail pages of a high-order folio to check and clear their flags, so
> counting PageHWPoison() pages in that loop is cheap, as pointed out
> by David Hildenbrand [4]. Unlike PG_has_hwpoisoned, which is only
> maintained for THP, this catches HWPoison pages in any high-order
> folio, including dissolved HugeTLB folios.

So thinking about this again (and hating the diffstat with passion) I think a
better temporary approach (until we sort this all out properly, eventually, ...
:) ) would be to set PG_has_hwpoisoned also for hugetlb.

I think your previous patches did that for dissolved hugetlb folios ...

Didn't Willy have some patches to do it properly for hugetlb? Yes indeed:

https://lore.kernel.org/all/20260805210557.1118966-9-willy@xxxxxxxxxxxxx/

Likely we could do it more minimally for the purpose of this stuff here by just
setting the flag?

Then, as a quick, less intrusive fix, exclude the entire thing from the buddy.
Don't free individual pages. Just stop that memory from reuse for now.

Of course, we might also be able to do that with PageHWPoison, but
PG_has_hwpoisoned would be a lot cleaner.

I don't think we want all that complicated "free parts of a broken folio" in a
commit that actually fixes something real (using hugetlb folios and handing them
back out again).

--
Cheers,

David