[PATCH v3 1/3] mm/memory-failure: set has_hwpoisoned flags on HugeTLB folio

Jiaqi Yan posted 3 patches 4 weeks ago
There is a newer version of this series
[PATCH v3 1/3] mm/memory-failure: set has_hwpoisoned flags on HugeTLB folio
Posted by Jiaqi Yan 4 weeks ago
When a free HWPoison HugeTLB folio is dissolved, it becomes
non-HugeTLB and is released to buddy allocator as a high-order
folio.

Set has_hwpoisoned flags on the high-order folio so that buddy
allocator can tell that it contains certain HWPoison page(s).
This is a prepare change for buddy allocator to handle only the
high-order HWPoison folio differently.

This cannot be done with hwpoison flag because users cannot tell
from the case that the page with hwpoison is hardware corrupted.

Signed-off-by: Jiaqi Yan <jiaqiyan@google.com>
---
 include/linux/page-flags.h | 2 +-
 mm/memory-failure.c        | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
index f7a0e4af0c734..d13835e265952 100644
--- a/include/linux/page-flags.h
+++ b/include/linux/page-flags.h
@@ -904,7 +904,7 @@ static inline int PageTransCompound(const struct page *page)
 TESTPAGEFLAG_FALSE(TransCompound, transcompound)
 #endif
 
-#if defined(CONFIG_MEMORY_FAILURE) && defined(CONFIG_TRANSPARENT_HUGEPAGE)
+#if defined(CONFIG_MEMORY_FAILURE) && (defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLB_PAGE))
 /*
  * PageHasHWPoisoned indicates that at least one subpage is hwpoisoned in the
  * compound page.
diff --git a/mm/memory-failure.c b/mm/memory-failure.c
index fbc5a01260c89..d204de6c9792a 100644
--- a/mm/memory-failure.c
+++ b/mm/memory-failure.c
@@ -1952,6 +1952,7 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio)
 	if (folio_test_hugetlb_vmemmap_optimized(folio))
 		return;
 	folio_clear_hwpoison(folio);
+	folio_set_has_hwpoisoned(folio);
 	folio_free_raw_hwp(folio, true);
 }
 
-- 
2.52.0.457.g6b5491de43-goog
Re: [PATCH v3 1/3] mm/memory-failure: set has_hwpoisoned flags on HugeTLB folio
Posted by Zi Yan 3 weeks, 6 days ago
On 11 Jan 2026, at 19:49, Jiaqi Yan wrote:

> When a free HWPoison HugeTLB folio is dissolved, it becomes
> non-HugeTLB and is released to buddy allocator as a high-order
> folio.
>
> Set has_hwpoisoned flags on the high-order folio so that buddy
> allocator can tell that it contains certain HWPoison page(s).
> This is a prepare change for buddy allocator to handle only the
> high-order HWPoison folio differently.
>
> This cannot be done with hwpoison flag because users cannot tell
> from the case that the page with hwpoison is hardware corrupted.
>
> Signed-off-by: Jiaqi Yan <jiaqiyan@google.com>
> ---
>  include/linux/page-flags.h | 2 +-
>  mm/memory-failure.c        | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> index f7a0e4af0c734..d13835e265952 100644
> --- a/include/linux/page-flags.h
> +++ b/include/linux/page-flags.h
> @@ -904,7 +904,7 @@ static inline int PageTransCompound(const struct page *page)
>  TESTPAGEFLAG_FALSE(TransCompound, transcompound)
>  #endif
>
> -#if defined(CONFIG_MEMORY_FAILURE) && defined(CONFIG_TRANSPARENT_HUGEPAGE)
> +#if defined(CONFIG_MEMORY_FAILURE) && (defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLB_PAGE))
>  /*
>   * PageHasHWPoisoned indicates that at least one subpage is hwpoisoned in the
>   * compound page.
> diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> index fbc5a01260c89..d204de6c9792a 100644
> --- a/mm/memory-failure.c
> +++ b/mm/memory-failure.c
> @@ -1952,6 +1952,7 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio)
>  	if (folio_test_hugetlb_vmemmap_optimized(folio))
>  		return;
>  	folio_clear_hwpoison(folio);
> +	folio_set_has_hwpoisoned(folio);
>  	folio_free_raw_hwp(folio, true);
>  }

Should this patch go after Patch 2 where has_hwpoisoned folio handling code
is added?

--
Best Regards,
Yan, Zi
Re: [PATCH v3 1/3] mm/memory-failure: set has_hwpoisoned flags on HugeTLB folio
Posted by Jiaqi Yan 3 weeks, 3 days ago
On Sun, Jan 11, 2026 at 6:50 PM Zi Yan <ziy@nvidia.com> wrote:
>
> On 11 Jan 2026, at 19:49, Jiaqi Yan wrote:
>
> > When a free HWPoison HugeTLB folio is dissolved, it becomes
> > non-HugeTLB and is released to buddy allocator as a high-order
> > folio.
> >
> > Set has_hwpoisoned flags on the high-order folio so that buddy
> > allocator can tell that it contains certain HWPoison page(s).
> > This is a prepare change for buddy allocator to handle only the
> > high-order HWPoison folio differently.
> >
> > This cannot be done with hwpoison flag because users cannot tell
> > from the case that the page with hwpoison is hardware corrupted.
> >
> > Signed-off-by: Jiaqi Yan <jiaqiyan@google.com>
> > ---
> >  include/linux/page-flags.h | 2 +-
> >  mm/memory-failure.c        | 1 +
> >  2 files changed, 2 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h
> > index f7a0e4af0c734..d13835e265952 100644
> > --- a/include/linux/page-flags.h
> > +++ b/include/linux/page-flags.h
> > @@ -904,7 +904,7 @@ static inline int PageTransCompound(const struct page *page)
> >  TESTPAGEFLAG_FALSE(TransCompound, transcompound)
> >  #endif
> >
> > -#if defined(CONFIG_MEMORY_FAILURE) && defined(CONFIG_TRANSPARENT_HUGEPAGE)
> > +#if defined(CONFIG_MEMORY_FAILURE) && (defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLB_PAGE))
> >  /*
> >   * PageHasHWPoisoned indicates that at least one subpage is hwpoisoned in the
> >   * compound page.
> > diff --git a/mm/memory-failure.c b/mm/memory-failure.c
> > index fbc5a01260c89..d204de6c9792a 100644
> > --- a/mm/memory-failure.c
> > +++ b/mm/memory-failure.c
> > @@ -1952,6 +1952,7 @@ void folio_clear_hugetlb_hwpoison(struct folio *folio)
> >       if (folio_test_hugetlb_vmemmap_optimized(folio))
> >               return;
> >       folio_clear_hwpoison(folio);
> > +     folio_set_has_hwpoisoned(folio);
> >       folio_free_raw_hwp(folio, true);
> >  }
>
> Should this patch go after Patch 2 where has_hwpoisoned folio handling code
> is added?

Hi Zi, thanks for the comment. Will reorder this one.

I initially thought this patch was for preparation. However, if I look
at patch 2 differently: it enables page_alloc to handle
PG_has_hwpoisoned folios generally, not only for HugeTLB, but also for
split-failed THP compound pages. Then this one can be just to make
HugeTLB start to use patch 2.

>
> --
> Best Regards,
> Yan, Zi