Only free healthy pages in high-order folio
Subsystems (6)
v7 cover Only free healthy pages in high-order folio
At the end of dissolve_free_hugetlb_folio(), a free HugeTLB folio becomes non-HugeTLB and 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) code (mm/memory-failure.c) 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) is handled by MFR but splitting failed. Such THP will eventually be released to buddy allocator when owning userspace processes are gone, but with certain subpages having HWPoison [9].
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]. As discussed in v6 [13], how HWPoison pages should be handled by page allocator in general deserves a bigger rework; this patchset only addresses the freeing side.
__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 suggested by David Hildenbrand [14]. If any HWPoison page is found, after all checks and preparations in __free_pages_prepare() succeed, the newly introduced free_has_hwpoisoned() only frees the healthy pages and excludes the HWPoison ones in the high-order folio. Unlike PG_has_hwpoisoned, which v6 relied on but is only maintained for THP, this catches HWPoison pages in any high-order folio.
free_has_hwpoisoned() iterates through the sub-pages of the folio to identify contiguous ranges of healthy pages. Instead of freeing pages one by one, free_has_hwpoisoned() then re-uses free_prepared_contig_range() [11] to decompose healthy ranges into the largest possible chunks of different orders. Every chunk is sanitized and then freed via __free_frozen_pages(). It stops scanning once all HWPoison pages counted by __free_pages_prepare() are found. Each excluded HWPoison page is marked HWPoisonTakenOff with a refcount of 1, just like a page that memory_failure() takes off buddy allocator, so that unpoison_memory() can put it back.
free_has_hwpoisoned() has linear time complexity wrt the number of pages in the folio. While the power-of-two decomposition ensures that the number of calls to the buddy allocator is logarithmic for each contiguous healthy range, the mandatory linear scan of pages to identify PageHWPoison() defines the overall time complexity.
I tested with some test-only kernel code [4] and hugetlb-mfr [5], and validated that HWPoison pages are excluded by free_has_hwpoisoned() after dissolve_free_hugetlb_folio() a free 2M or 1G HugeTLB page that contains 1~8 HWPoison raw pages.
To illustrate the latency free_has_hwpoisoned() adds to the memory freeing path, I measured it on a 1G HugeTLB folio with 8 HWPoison pages with instrument code [4, 5] for 20 sample runs, on a kernel without KASAN and CONFIG_DEBUG_VM, and compared it with free_one_page() of a healthy 1G folio:
- Last HWPoison page at the end of the folio (worst case):
mean=767us, median=757us, stdev=29us (20 runs)
- free_one_page() of a healthy 1G folio:
mean=50us, median=50us, stdev=3us
free_has_hwpoisoned() is in worst case around 15x the baseline. Its cost is nontrivial, but still far from triggering soft lockup, and fair for handling exceptional hardware memory errors.
Now that free_has_hwpoisoned() ensures HWPoison pages never make it into buddy allocator, MFR doesn't need to take_page_off_buddy() anymore after dissolving HWPoison hugepages. So the same patch replaces __page_handle_poison() with new __hugepage_handle_poison() at HugeTLB specific call sites. The two changes are in one patch because neither works without the other. This patchset doesn't affect the soft offline behavior in MFR, because soft offline marks a page HWPoison only after taking it off buddy allocator.
To provide test coverage for the new __hugepage_handle_poison() in me_huge_page(), the last commit adds a MADV_HARD test variant for anonymous HugeTLB pages. It also covers the code path that frees a HugeTLB page that contains 1 raw HWPoison page.
The commit message of patch 2 and this cover letter were reworded with an AI assistant, which was also used to review the code; the code changes are my own.
Based on commit 0ea6dc8c4a21 ("fs/proc/task_mmu: fix lost maps entries above 2^63")
Changelog
v6 [13] -> v7
- Rebase to recent akpm/mm-unstable.
- Patch 1: modify free_prepared_contig_range() to take fpi_t instead of adding a __free_prepared_contig_range() wrapper (Matthew Wilcox).
- Patch 2: count PageHWPoison() pages in the tail page loop of __free_pages_prepare() instead of relying on PG_has_hwpoisoned (David Hildenbrand [14]). Drop v6 patch 3/5 "mm/memory-failure:
set has_hwpoisoned flags on dissolved HugeTLB folio" as it is no longer needed.
- Patch 2: pass the number of HWPoison pages to free_has_hwpoisoned(), which stops scanning once all of them are found.
- Patch 2: mark excluded HWPoison pages HWPoisonTakenOff with a refcount of 1, so that unpoison_memory() puts them back to buddy allocator instead of leaking them (Sashiko AI review).
- Patch 2: remove pr_info() in free_has_hwpoisoned() (Vlastimil Babka), and fix comments (Miaohe Lin).
- Fold v6 patch 4/5 "mm/memory-failure: skip take_page_off_buddy after dissolving HWPoison HugeTLB page" into patch 2, so that memory_failure() doesn't fail to recover HugeTLB folios between the two patches. Since free_has_hwpoisoned() already holds a refcount on the isolated page, callers of __hugepage_handle_poison() no longer page_ref_inc() it.
- Patch 2: __hugepage_handle_poison() no longer tests HugeTLB flags (e.g. raw_hwp_unreliable), because the folio may already be freed by folio_put() in me_huge_page() or by a concurrent dissolve. Instead, it tells success by whether the raw HWPoison page is HWPoisonTakenOff after dissolving. Since commit a363c62a653c ("mm/hugetlb: do not dissolve gigantic pages without runtime support"), dissolve_free_hugetlb_folio() also fails properly on gigantic folios without runtime support (Miaohe Lin).
- Patch 3: use HUGETLB_SETUP_DEFAULT_PAGES() so that HugeTLB settings are restored after the test (Sashiko AI review).
- Re-measure the performance cost of free_has_hwpoisoned() in v7.
- Drop Reviewed-by from Miaohe Lin and Vlastimil Babka on patch 2 due to the substantial changes above.
v5 [12] -> v6
- Rebase to recent akpm/mm-unstable and address comments from Zi Yan, Miaohe Lin, Vlastimil Babka.
- Extract free_pages_sanitize() to avoid touching HWPoison page(s) at the end of __free_pages_prepare().
- Introduce FPI_SANITIZE and add a fpi_t argument to the freeing path free_has_hwpoisoned() -> __free_prepared_contig_range(), so that healthy page blocks are sanitized before __free_frozen_pages().
- Make free_has_hwpoisoned() be compatible with order==0.
- Repeat the previous test done on both X86 and ARM64 machines. CONFIG_KASAN + CONFIG_KASAN_SW_TAGS + kasan.fault=report are enabled on the ARM64 machine.
v4 [10] -> v5
- Rebase to very recent akpm/mm-unstable.
- Re-use free_prepared_contig_range() introduced by [11], and remove free_contiguous_pages() in v4.
- Instead of using struct page pointer, iterate over pfn in free_has_hwpoison().
- Re-tested and re-evaluated free_has_hwpoison()'s time cost.
- Add memory failure recovery test for anonymous 1G HugeTLB page to gain test coverage for __hugepage_handle_poison() and for freeing 1G HugeTLB page that has 1 HWPoison page.
v3 [8] -> v4
- Address comments from Zi Yan, Miaohe Lin, Harry Yoo.
- Set has_hwpoisoned flag after introducing free_has_hwpoisoned().
- Unwrap free_pages_prepare_has_hwpoisoned() into free_pages_prepare().
- If folio has HWPoison, its healthy pages will be freed with FPI_NONE right in free_pages_prepare(), who returns false to indicate caller should not proceeding its own freeing action.
- Rework the commit on __page_handle_poison. Only change the handling for HWPoison HugeTLB page, leaving free buddy page and soft offline handling alone.
v2 [7] -> v3:
- Address comments from Mathew Wilcox, Harry Hoo, Miaohe Lin.
- Let free_has_hwpoisoned() happen after free_pages_prepare(), which help to deal with decomposing the original compound page, and with page metadata like alloc tag and page owner.
- Tested with "page_owner=on" and CONFIG_MEM_ALLOC_PROFILING*=y.
- Wrap checking PG_has_hwpoisoned and free_has_hwpoisoned() into free_pages_prepare_has_hwpoisoned(), which replaces free_pages_prepare() calls in free_frozen_pages().
- Rename free_has_hwpoison_page() to free_has_hwpoisoned().
- Measure latency added by free_has_hwpoisoned().
- Ensure struct page *end is only used for pointer arithmetic, instead of accessed as page.
- Refactor page_handl_poison instead of just __page_handle_poison().
v1 [6] -> v2:
- Total reimplementation based on discussions with Mathew Wilcox, Harry Hoo, Zi Yan etc
- hugetlb_free_hwpoison_folio() => free_has_hwpoison_pages().
- Utilize has_hwpoisoned flag to tell buddy allocator a high-order folio contains HWPoison.
- Simplify __page_handle_poison() given that the HWPoison page(s) won't be freed within high-order folio.
[1] https://lore.kernel.org/linux-mm/[email protected]
[2] https://lore.kernel.org/linux-mm/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://drive.google.com/file/d/1CzJn1Cc4wCCm183Y77h244fyZIkTLzCt/view?usp=sharing
[5] https://lore.kernel.org/linux-mm/[email protected]
[6] https://lore.kernel.org/linux-mm/[email protected]
[7] https://lore.kernel.org/linux-mm/[email protected]
[8] https://lore.kernel.org/linux-mm/[email protected]
[9] https://lore.kernel.org/linux-mm/[email protected]
[10] https://lore.kernel.org/linux-mm/[email protected]
[11] https://lore.kernel.org/all/[email protected]
[12] https://lore.kernel.org/linux-mm/[email protected]
[13] https://lore.kernel.org/linux-mm/[email protected]
[14] https://lore.kernel.org/linux-mm/[email protected]
Jiaqi Yan (3):
mm/page_alloc: free_prepared_contig_range() takes fpi_t mm/page_alloc: only free healthy pages in high-order folio selftests/mm: add hard memory failure anonymous HugeTLB test
mm/internal.h | 3 + mm/memory-failure.c | 52 ++++-- mm/page_alloc.c | 180 ++++++++++++++++---- tools/testing/selftests/mm/memory-failure.c | 67 +++++++- 4 files changed, 252 insertions(+), 50 deletions(-)
Signature · 1 line
2.56.0.506.g506a7eabc5-goog
PATCH v7 1/3 mm/page_alloc: free_prepared_contig_range() takes fpi_t
A future commit introducing free_has_hwpoisoned() to be called within __free_pages_prepare() will need to pass specific fpi_t flags when freeing a contiguous range of pages. Currently, free_prepared_contig_range() hardcodes the FPI_PREPARED flag and does not accept any caller-provided flags.
Refactor free_prepared_contig_range() to accept an fpi_t argument. It bitwise ORs the new argument with FPI_PREPARED when calling into __free_frozen_pages(). Update all current invocation sites in __free_contig_range_common() to pass FPI_NONE.
This is a preparatory commit with no functional changes.
--- mm/page_alloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
mm/page_alloc.c +5 -5
@@ -7043,7 +7043,7 @@ void __init page_alloc_sysctl_init(void) }static void free_prepared_contig_range (struct page *page, -unsigned long nr_pages) +unsigned long nr_pages,fpi_t fpi_flags) {unsigned long pfn =page_to_pfn (page);
@@ -7060,7 +7060,7 @@ static void free_prepared_contig_range(struct page *page,* Free the chunk as a single block. Our caller has already * called free_pages_prepare() for each order-0 page. */ -__free_frozen_pages (page, order,FPI_PREPARED ); +__free_frozen_pages (page, order, fpi_flags |FPI_PREPARED ); pfn +=1UL << order; page +=1UL << order;
@@ -7097,14 +7097,14 @@ static void __free_contig_range_common(unsigned long pfn, unsigned long nr_pagesif (!can_free) {if (start) { -free_prepared_contig_range (start, i - nr_start); +free_prepared_contig_range (start, i - nr_start,FPI_NONE ); start =NULL ; }continue ; }if (start &&memdesc_section (&page->flags) != start_sec) { -free_prepared_contig_range (start, i - nr_start); +free_prepared_contig_range (start, i - nr_start,FPI_NONE ); start = page; nr_start = i; start_sec =memdesc_section (&page->flags);
@@ -7116,7 +7116,7 @@ static void __free_contig_range_common(unsigned long pfn, unsigned long nr_pages }if (start) -free_prepared_contig_range (start, nr_pages - nr_start); +free_prepared_contig_range (start, nr_pages - nr_start,FPI_NONE ); }/**
Signature · 1 line
2.56.0.506.g506a7eabc5-goog
PATCH v7 2/3 mm/page_alloc: only free healthy pages in high-order folio
In reply to Jiaqi YanAt 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.
If any HWPoison page is found, then after all checks and preparations in __free_pages_prepare() succeed, take a shortcut to the newly introduced free_has_hwpoisoned(), which only frees the healthy pages and excludes the HWPoison ones. __free_pages_prepare() then returns false so that its callers don't free the folio again.
free_has_hwpoisoned() iterates through the pages of the folio to identify contiguous ranges of healthy pages. It uses free_prepared_contig_range() to decompose each healthy range into the largest possible chunks of different orders, which are then freed via __free_frozen_pages(). Knowing the number of HWPoison pages from __free_pages_prepare(), it stops scanning once all of them are found, and frees the remaining pages without scanning them.
Sanitizing pages at free time (e.g. page poisoning and init_on_free) may write to page contents, which must be avoided for HWPoison pages. So factor it out of __free_pages_prepare() into free_pages_sanitize(), and skip it for a folio that has HWPoison pages. Instead, free_has_hwpoisoned() passes the new FPI_SANITIZE flag to free_prepared_contig_range(), which then sanitizes each healthy chunk right before freeing it.
Each excluded HWPoison page is treated like a page that memory_failure() takes off buddy allocator: it is marked PageHWPoisonTakenOff and holds a refcount of 1. Its alloc tag reference is also cleared, as is done for an order-0 HWPoison page in __free_pages_prepare(). This allows unpoison_memory() to put it back to buddy allocator via put_page_back_buddy() instead of leaking it.
As a result, memory_failure() no longer needs to take HWPoison pages off buddy allocator after dissolving a HugeTLB folio. For a free HugeTLB folio, or an anonymous one that becomes free after being unmapped, try_memory_failure_hugetlb() and me_huge_page() call __page_handle_poison(), which disables pcplists, dissolves the folio and then calls take_page_off_buddy(). Since the raw HWPoison page never reaches buddy allocator now, take_page_off_buddy() would fail, and memory_failure() would report MF_FAILED.
So add __hugepage_handle_poison() for these two callers. It dissolves the folio and then checks whether the raw HWPoison page has been isolated, i.e. is HWPoisonTakenOff. It doesn't test any HugeTLB flags, because the folio may have already been freed, e.g. by folio_put() in me_huge_page() if it was a surplus folio, or by a concurrent dissolve. If the folio's raw_hwp_list is unreliable, __update_and_free_hugetlb_folio() leaks the folio and the raw HWPoison page is not isolated, so memory_failure() still reports MF_FAILED. As free_has_hwpoisoned() already holds a refcount on each isolated page, the callers no longer page_ref_inc() it. Soft offline keeps using __page_handle_poison(), because it marks a page HWPoison only after taking it off buddy allocator.
free_has_hwpoisoned() has linear time complexity wrt the number of pages in the folio; the worst case is when the last page of the folio is HWPoison. While the power-of-two decomposition keeps the number of calls to buddy allocator small, the linear scan of pages to identify PageHWPoison() defines the overall time complexity. For a 1G hugepage having 8 HWPoison pages and if the last page is HWPoison, free_has_hwpoisoned() takes in worst case 15x the time free_one_page() takes for a healthy 1G hugepage, measured on a system having 56 Intel Skylake physical cores. The cost is nontrivial but far from triggering soft lockup, and fair for handling exceptional hardware memory errors.
This commit message text was reworded with an AI assistant, then reviewed and edited by me. The code changes are my own, but they are reviewed by the AI assistant.
[1] https://lore.kernel.org/linux-mm/[email protected]
[2] https://lore.kernel.org/linux-mm/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://lore.kernel.org/linux-mm/[email protected]
--- mm/internal.h | 3 + mm/memory-failure.c | 52 +++++++++----- mm/page_alloc.c | 170 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 183 insertions(+), 42 deletions(-)
mm/internal.h +4 -0
@@ -1195,6 +1195,9 @@ static inline int unmap_poisoned_folio(struct folio *folio, unsigned long pfn, b {return -EBUSY ; } + +static inline void SetPageHWPoisonTakenOff (struct page *page) +{ +}#endif
extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long,
mm/memory-failure.c +35 -17
77 lines not on this page · raw message
mm/page_alloc.c +145 -25
236 lines not on this page · raw message
Signature · 1 line
2.56.0.506.g506a7eabc5-goog
Miaohe Lin
maintainerRe: [PATCH v7 2/3] mm/page_alloc: only free healthy pages in high-order folio
Quoted 105 lines · Jiaqi Yan
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 betweendissolve_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, whichcheck_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 countingPageHWPoison()pages in that loop is cheap, as pointed out by David Hildenbrand [4]. UnlikePG_has_hwpoisoned, which is only maintained for THP, this catches HWPoison pages in any high-order folio, including dissolved HugeTLB folios.If any HWPoison page is found, then after all checks and preparations in
__free_pages_prepare()succeed, take a shortcut to the newly introducedfree_has_hwpoisoned(), which only frees the healthy pages and excludes the HWPoison ones.__free_pages_prepare()then returns false so that its callers don't free the folio again.
free_has_hwpoisoned()iterates through the pages of the folio to identify contiguous ranges of healthy pages. It usesfree_prepared_contig_range()to decompose each healthy range into the largest possible chunks of different orders, which are then freed via__free_frozen_pages(). Knowing the number of HWPoison pages from__free_pages_prepare(), it stops scanning once all of them are found, and frees the remaining pages without scanning them.Sanitizing pages at free time (e.g. page poisoning and
init_on_free) may write to page contents, which must be avoided for HWPoison pages. So factor it out of__free_pages_prepare()intofree_pages_sanitize(), and skip it for a folio that has HWPoison pages. Instead,free_has_hwpoisoned()passes the newFPI_SANITIZEflag tofree_prepared_contig_range(), which then sanitizes each healthy chunk right before freeing it.Each excluded HWPoison page is treated like a page that
memory_failure()takes off buddy allocator: it is marked PageHWPoisonTakenOff and holds a refcount of 1. Its alloc tag reference is also cleared, as is done for an order-0 HWPoison page in__free_pages_prepare(). This allowsunpoison_memory()to put it back to buddy allocator viaput_page_back_buddy()instead of leaking it.As a result,
memory_failure()no longer needs to take HWPoison pages off buddy allocator after dissolving a HugeTLB folio. For a free HugeTLB folio, or an anonymous one that becomes free after being unmapped,try_memory_failure_hugetlb()andme_huge_page()call__page_handle_poison(), which disables pcplists, dissolves the folio and then callstake_page_off_buddy(). Since the raw HWPoison page never reaches buddy allocator now,take_page_off_buddy()would fail, andmemory_failure()would reportMF_FAILED.So add
__hugepage_handle_poison()for these two callers. It dissolves the folio and then checks whether the raw HWPoison page has been isolated, i.e. is HWPoisonTakenOff. It doesn't test any HugeTLB flags, because the folio may have already been freed, e.g. byfolio_put()inme_huge_page()if it was a surplus folio, or by a concurrent dissolve. If the folio'sraw_hwp_listis unreliable,__update_and_free_hugetlb_folio()leaks the folio and the raw HWPoison page is not isolated, somemory_failure()still reportsMF_FAILED. Asfree_has_hwpoisoned()already holds a refcount on each isolated page, the callers no longerpage_ref_inc()it. Soft offline keeps using__page_handle_poison(), because it marks a page HWPoison only after taking it off buddy allocator.
free_has_hwpoisoned()has linear time complexity wrt the number of pages in the folio; the worst case is when the last page of the folio is HWPoison. While the power-of-two decomposition keeps the number of calls to buddy allocator small, the linear scan of pages to identifyPageHWPoison()defines the overall time complexity. For a 1G hugepage having 8 HWPoison pages and if the last page is HWPoison,free_has_hwpoisoned()takes in worst case 15x the timefree_one_page()takes for a healthy 1G hugepage, measured on a system having 56 Intel Skylake physical cores. The cost is nontrivial but far from triggering soft lockup, and fair for handling exceptional hardware memory errors.This commit message text was reworded with an AI assistant, then reviewed and edited by me. The code changes are my own, but they are reviewed by the AI assistant.
Quoted 7 lines
[1] https://lore.kernel.org/linux-mm/[email protected]
[2] https://lore.kernel.org/linux-mm/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://lore.kernel.org/linux-mm/[email protected]Assisted-by Antigravity:claude-opus-5-5Signed-off-by Jiaqi Yan <[email protected]>
Thanks for update. Some questions below.
Quoted 36 lines
--- mm/internal.h | 3 + mm/memory-failure.c | 52 +++++++++----- mm/page_alloc.c | 170 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 183 insertions(+), 42 deletions(-)mm/internal.h +4
-0@@ -1195,6 +1195,9 @@ static inline int unmap_poisoned_folio(struct folio *folio, unsigned long pfn, b {return -EBUSY ; } + +static inline void SetPageHWPoisonTakenOff (struct page *page) +{ +}#endif extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long,mm/memory-failure.c +7
-0@@ -214,7 +214,40 @@ static struct rb_root_cached pfn_space_itree = RB_ROOT_CACHED;static DEFINE_MUTEX (pfn_space_lock); +static inline bool PageHWPoisonTakenOff (struct page *page) +{ +return PageHWPoison (page) &&page_private (page) ==MAGIC_HWPOISON ; +} + +/* +* Only for a HugeTLB page being handled by memory_failure().
mm/memory-failure.c static struct rb_root_cached pfn_space_itree = RB_ROOT_CACHED; · line 233
Quoted 10 lines
mm/memory-failure.c +10
-0+* Unlike soft_offline_page(), no HWPoison subpage makes it into +* buddy allocator when the folio is freed, so take_page_off_buddy() +* is unnecessary. +* +* Return values: +* 1: the folio is dissolved and the page is isolated with +* HWPoisonTakenOff and refcount=1. Caller must not take +* another refcount. +* 0: the folio is dissolved but the page is not isolated, +* e.g. the folio's raw_hwp_list is unreliable.
If folio's raw_hwp_list is unreliable, I think it cannot be dissolved. So above comment confused me.
Quoted 3 lines
mm/memory-failure.c +3
-0+* < 0: failed to dissolve folio. +*/ +static int __hugepage_handle_poison (struct page *page)
...
Quoted 54 lines
mm/memory-failure.c +15
-9+/* +* Returns +* - true: checks and preparations all good, caller can proceed freeing. +* - false: do not proceed freeing for one of the following reasons: +* 1. Some check failed so it is not safe to proceed freeing. +* 2. A compound page has some HWPoison pages. The healthy pages +* are already safely freed, and the HWPoison ones isolated. +*/ static __always_inline bool __free_pages_prepare(struct page *page,unsigned int order,fpi_t fpi_flags) {int bad =0 ; -bool skip_kasan_poison =should_skip_kasan_poison (page); -bool init =want_init_on_free ();bool compound =PageCompound (page);struct folio *folio =page_folio (page); +unsigned int num_hwpoisoned =0 ;if (fpi_flags &FPI_PREPARED )return true;@@ -1376,6 +1437,7 @@ static __always_inline bool __free_pages_prepare(struct page *page, folio->_nr_pages =0 ;#endif } + num_hwpoisoned +=PageHWPoison (page);for (i =1 ; i < (1 << order); i++) {struct page *tail_page = page + i;@@ -1394,6 +1456,7 @@ static __always_inline bool __free_pages_prepare(struct page *page, } } tail_page->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP ; + num_hwpoisoned +=PageHWPoison (tail_page); } }if (folio_test_anon (folio)) {@@ -1425,34 +1488,20 @@ static __always_inline bool __free_pages_prepare(struct page *page, PAGE_SIZE << order); } -kernel_poison_pages (page,1 << order); -/* -* As memory initialization might be integrated into KASAN, -* KASAN poisoning and memory initialization code must be -* kept together to avoid discrepancies in behavior. +* After breaking down compound page and dealing with page metadata +* (e.g. page owner and page alloc tags), take a shortcut if this +* was a compound page containing certain HWPoison subpages. * -* With hardware tag-based KASAN, memory tags must be set before the -* page becomes unavailable via debug_pagealloc or arch_free_page. +* Pass FPI_SANITIZE to only free_pages_sanitize() healthy pages. */
mm/memory-failure.c static __always_inline bool __free_pages_prepare(struct page *page, · line 1501
Quoted 10 lines
mm/memory-failure.c +4
-6-if (!skip_kasan_poison) { -kasan_poison_pages (page, order, init); - -/* Memory is already initialized if KASAN did it internally. */ -if (kasan_has_integrated_init ()) - init = false; +if (unlikely (num_hwpoisoned)) { +free_has_hwpoisoned (page, order, num_hwpoisoned, + fpi_flags |FPI_SANITIZE ); +return false;
There is free_page_is_bad check above this:
if (is_check_pages_enabled()) {
if (free_page_is_bad(page))
bad++;
if (bad)
return false;
}It can return early if bad is true. In this case, free_has_hwpoisoned cannot handle the hwpoisoned subpages. Is this expected behavior?
Quoted 43 lines
mm/memory-failure.c +16
-10} -if (init) -clear_highpages_kasan_tagged (page,1 << order); - -/* -* arch_free_page() can make the page's contents inaccessible. s390 -* does this. So nothing which can access the page's contents should -* happen after this. -*/ -arch_free_page (page, order); -debug_pagealloc_unmap_pages (page,1 << order); +free_pages_sanitize (page, order);return true; }@@ -7059,7 +7108,14 @@ static void free_prepared_contig_range(struct page *page,/* * Free the chunk as a single block. Our caller has already * called free_pages_prepare() for each order-0 page. +* +* If the original compound page has HWPoison page, +* free_pages_prepare() has to skip sanitize at that time, +* but now it is good time to do that. */ +if (fpi_flags &FPI_SANITIZE ) +free_pages_sanitize (page, order); +__free_frozen_pages (page, order, fpi_flags |FPI_PREPARED ); pfn +=1UL << order;@@ -7141,6 +7197,69 @@ void __free_contig_range(unsigned long pfn, unsigned long nr_pages)__free_contig_range_common (pfn, nr_pages,/* is_frozen= */ false); } +/* +* Given some contiguous pages that have num_hwpoisoned HWPoison page(s), +* free only the healthy ones. +* +* Used at the end of __free_pages_prepare(). Even if having HWPoison pages, +* breaking down compound page and clearing metadata (e.g. page owner, alloc +* tag) can be done together during __free_pages_prepare(), which simplifies +* the splitting here: unlike __split_unmapped_folio(), there is no need to
mm/memory-failure.c void __free_contig_range(unsigned long pfn, unsigned long nr_pages) · line 7217
Quoted 10 lines
mm/memory-failure.c +10
-0+* turn split pages into a compound page or to carry metadata. +* +* It scans every raw page of the compound page and causes nontrivial overhead. +* So only use this when the compound page contains HWPoison page(s). +* +* This implementation needs rework in memdesc world. +*/ +static void free_has_hwpoisoned (struct page *page,unsigned int order, +unsigned int num_hwpoisoned, +fpi_t fpi_flags)
There are codes for order = 0 in __free_pages_prepare:
if (unlikely(PageHWPoison(page)) && !order) {
/* Do not let hwpoison pages hit pcplists/buddy */
reset_page_owner(page, order);
page_table_check_free(page, order);
pgalloc_tag_sub(page, 1 << order);
/*
* The page is isolated and accounted for.
* Mark the codetag as empty to avoid accounting error
* when the page is freed by unpoison_memory().
*/
clear_page_tag_ref(page);
return false;
}Can free_has_hwpoisoned also handle order=0 pages? This way, the hwpoison-related handling code can be centralized here.
Quoted 9 lines
mm/memory-failure.c +9
-0+{ +unsigned long curr =page_to_pfn (page); +unsigned long end_pfn = curr + (1UL << order); +unsigned long next; +struct page *hwpoisoned; + +while (curr < end_pfn) { +if (!num_hwpoisoned) { +/* No more HWPoison page in [curr, end_pfn) */
mm/memory-failure.c void __free_contig_range(unsigned long pfn, unsigned long nr_pages) · line 7236
Quoted 10 lines
mm/memory-failure.c +10
-0+free_prepared_contig_range (pfn_to_page (curr), + end_pfn - curr, fpi_flags); +break ; + } + + next = curr; +while (next < end_pfn && !PageHWPoison (pfn_to_page (next))) + ++next; + +if (next != end_pfn) {
We reach here with num_hwpoisoned != 0. So next can not be equal to end_pfn?
Quoted 10 lines
mm/memory-failure.c +10
-0+ hwpoisoned =pfn_to_page (next); +/* +* Avoid accounting error when the page is freed +* by unpoison_memory(). +*/ +clear_page_tag_ref (hwpoisoned); +/* +* unpoison_memory() will put_page_back_buddy() +* for HWPoisonTakenOff pages. Increment refcount +* to avoid VM_BUG() from put_page_testzero().
mm/memory-failure.c void __free_contig_range(unsigned long pfn, unsigned long nr_pages) · line 7256
Quoted 10 lines
mm/memory-failure.c +10
-0+*/ +page_ref_inc (hwpoisoned); +SetPageHWPoisonTakenOff (hwpoisoned); + --num_hwpoisoned; + } + +free_prepared_contig_range (pfn_to_page (curr), next - curr, + fpi_flags); + +if (next == end_pfn)
Ditto.
Thanks.
.
Re: [PATCH v7 2/3] mm/page_alloc: only free healthy pages in high-order folio
Quoted 112 lines · Miaohe Lin
Quoted 110 lines · Jiaqi Yan
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 betweendissolve_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, whichcheck_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 countingPageHWPoison()pages in that loop is cheap, as pointed out by David Hildenbrand [4]. UnlikePG_has_hwpoisoned, which is only maintained for THP, this catches HWPoison pages in any high-order folio, including dissolved HugeTLB folios.If any HWPoison page is found, then after all checks and preparations in
__free_pages_prepare()succeed, take a shortcut to the newly introducedfree_has_hwpoisoned(), which only frees the healthy pages and excludes the HWPoison ones.__free_pages_prepare()then returns false so that its callers don't free the folio again.
free_has_hwpoisoned()iterates through the pages of the folio to identify contiguous ranges of healthy pages. It usesfree_prepared_contig_range()to decompose each healthy range into the largest possible chunks of different orders, which are then freed via__free_frozen_pages(). Knowing the number of HWPoison pages from__free_pages_prepare(), it stops scanning once all of them are found, and frees the remaining pages without scanning them.Sanitizing pages at free time (e.g. page poisoning and
init_on_free) may write to page contents, which must be avoided for HWPoison pages. So factor it out of__free_pages_prepare()intofree_pages_sanitize(), and skip it for a folio that has HWPoison pages. Instead,free_has_hwpoisoned()passes the newFPI_SANITIZEflag tofree_prepared_contig_range(), which then sanitizes each healthy chunk right before freeing it.Each excluded HWPoison page is treated like a page that
memory_failure()takes off buddy allocator: it is marked PageHWPoisonTakenOff and holds a refcount of 1. Its alloc tag reference is also cleared, as is done for an order-0 HWPoison page in__free_pages_prepare(). This allowsunpoison_memory()to put it back to buddy allocator viaput_page_back_buddy()instead of leaking it.As a result,
memory_failure()no longer needs to take HWPoison pages off buddy allocator after dissolving a HugeTLB folio. For a free HugeTLB folio, or an anonymous one that becomes free after being unmapped,try_memory_failure_hugetlb()andme_huge_page()call__page_handle_poison(), which disables pcplists, dissolves the folio and then callstake_page_off_buddy(). Since the raw HWPoison page never reaches buddy allocator now,take_page_off_buddy()would fail, andmemory_failure()would reportMF_FAILED.So add
__hugepage_handle_poison()for these two callers. It dissolves the folio and then checks whether the raw HWPoison page has been isolated, i.e. is HWPoisonTakenOff. It doesn't test any HugeTLB flags, because the folio may have already been freed, e.g. byfolio_put()inme_huge_page()if it was a surplus folio, or by a concurrent dissolve. If the folio'sraw_hwp_listis unreliable,__update_and_free_hugetlb_folio()leaks the folio and the raw HWPoison page is not isolated, somemory_failure()still reportsMF_FAILED. Asfree_has_hwpoisoned()already holds a refcount on each isolated page, the callers no longerpage_ref_inc()it. Soft offline keeps using__page_handle_poison(), because it marks a page HWPoison only after taking it off buddy allocator.
free_has_hwpoisoned()has linear time complexity wrt the number of pages in the folio; the worst case is when the last page of the folio is HWPoison. While the power-of-two decomposition keeps the number of calls to buddy allocator small, the linear scan of pages to identifyPageHWPoison()defines the overall time complexity. For a 1G hugepage having 8 HWPoison pages and if the last page is HWPoison,free_has_hwpoisoned()takes in worst case 15x the timefree_one_page()takes for a healthy 1G hugepage, measured on a system having 56 Intel Skylake physical cores. The cost is nontrivial but far from triggering soft lockup, and fair for handling exceptional hardware memory errors.This commit message text was reworded with an AI assistant, then reviewed and edited by me. The code changes are my own, but they are reviewed by the AI assistant.
[1] https://lore.kernel.org/linux-mm/[email protected]
[2] https://lore.kernel.org/linux-mm/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://lore.kernel.org/linux-mm/[email protected]
Quoted 4 lines
Quoted 2 lines
Assisted-by Antigravity:claude-opus-5-5Signed-off-by Jiaqi Yan <[email protected]>Thanks for update. Some questions below.
Thanks for your review, Miaohe!
Quoted 42 lines
Quoted 42 lines
--- mm/internal.h | 3 + mm/memory-failure.c | 52 +++++++++----- mm/page_alloc.c | 170 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 183 insertions(+), 42 deletions(-)mm/internal.h +4
-0@@ -1195,6 +1195,9 @@ static inline int unmap_poisoned_folio(struct folio *folio, unsigned long pfn, b {return -EBUSY ; } + +static inline void SetPageHWPoisonTakenOff (struct page *page) +{ +}#endif extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long,mm/memory-failure.c +12
-0@@ -214,7 +214,40 @@ static struct rb_root_cached pfn_space_itree = RB_ROOT_CACHED;static DEFINE_MUTEX (pfn_space_lock); +static inline bool PageHWPoisonTakenOff (struct page *page) +{ +return PageHWPoison (page) &&page_private (page) ==MAGIC_HWPOISON ; +} + +/* +* Only for a HugeTLB page being handled by memory_failure(). +* Unlike soft_offline_page(), no HWPoison subpage makes it into +* buddy allocator when the folio is freed, so take_page_off_buddy() +* is unnecessary. +* +* Return values:
Quoted 8 lines
mm/memory-failure.c static struct rb_root_cached pfn_space_itree = RB_ROOT_CACHED; · line 233
Quoted 5 lines
mm/memory-failure.c +5
-0+* 1: the folio is dissolved and the page is isolated with +* HWPoisonTakenOff and refcount=1. Caller must not take +* another refcount. +* 0: the folio is dissolved but the page is not isolated, +* e.g. the folio's raw_hwp_list is unreliable. If folio's
raw_hwp_listis unreliable, I think it cannot be dissolved. So above comment confused me.
Ah I think "dissolve" is ambiguous and confusing here. For raw_hwp_unreliable folio, dissolve_free_hugetlb_folio() does return 0 and deemed "success"; however, nothing went to buddy due to raw_hwp_unreliable. How about I say: "the folio has left the HugeTLB pool but the page is not isolated."
BTW, I am working on a change to free_huge_folio(), which can remove __hugepage_handle_poison() entirely. See
https://lore.kernel.org/linux-mm/CACw3F53Q-h0jHH_JChMqojp6R_Zwx4DuD_Mte3Ve5CWc=01Z8A@mail.gmail.com.
Quoted 80 lines
Quoted 4 lines
mm/memory-failure.c +3
-0+* < 0: failed to dissolve folio. +*/ +static int __hugepage_handle_poison (struct page *page)...
Quoted 54 lines
mm/memory-failure.c +15
-9+/* +* Returns +* - true: checks and preparations all good, caller can proceed freeing. +* - false: do not proceed freeing for one of the following reasons: +* 1. Some check failed so it is not safe to proceed freeing. +* 2. A compound page has some HWPoison pages. The healthy pages +* are already safely freed, and the HWPoison ones isolated. +*/ static __always_inline bool __free_pages_prepare(struct page *page,unsigned int order,fpi_t fpi_flags) {int bad =0 ; -bool skip_kasan_poison =should_skip_kasan_poison (page); -bool init =want_init_on_free ();bool compound =PageCompound (page);struct folio *folio =page_folio (page); +unsigned int num_hwpoisoned =0 ;if (fpi_flags &FPI_PREPARED )return true;@@ -1376,6 +1437,7 @@ static __always_inline bool __free_pages_prepare(struct page *page, folio->_nr_pages =0 ;#endif } + num_hwpoisoned +=PageHWPoison (page);for (i =1 ; i < (1 << order); i++) {struct page *tail_page = page + i;@@ -1394,6 +1456,7 @@ static __always_inline bool __free_pages_prepare(struct page *page, } } tail_page->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP ; + num_hwpoisoned +=PageHWPoison (tail_page); } }if (folio_test_anon (folio)) {@@ -1425,34 +1488,20 @@ static __always_inline bool __free_pages_prepare(struct page *page, PAGE_SIZE << order); } -kernel_poison_pages (page,1 << order); -/* -* As memory initialization might be integrated into KASAN, -* KASAN poisoning and memory initialization code must be -* kept together to avoid discrepancies in behavior. +* After breaking down compound page and dealing with page metadata +* (e.g. page owner and page alloc tags), take a shortcut if this +* was a compound page containing certain HWPoison subpages. * -* With hardware tag-based KASAN, memory tags must be set before the -* page becomes unavailable via debug_pagealloc or arch_free_page. +* Pass FPI_SANITIZE to only free_pages_sanitize() healthy pages. */ mm/memory-failure.c static __always_inline bool __free_pages_prepare(struct page *page, · line 1501
Quoted 10 lines
mm/memory-failure.c +4
-6-if (!skip_kasan_poison) { -kasan_poison_pages (page, order, init); - -/* Memory is already initialized if KASAN did it internally. */ -if (kasan_has_integrated_init ()) - init = false; +if (unlikely (num_hwpoisoned)) { +free_has_hwpoisoned (page, order, num_hwpoisoned, + fpi_flags |FPI_SANITIZE ); +return false;There is
free_page_is_badcheck above this:if (is_check_pages_enabled()) { if (free_page_is_bad(page)) bad++; if (bad) return false; }
Quoted 2 lines
It can return early if bad is true. In this case,
free_has_hwpoisonedcannot handle the hwpoisoned subpages. Is this expected behavior?
Yes, that is expected and safe: the whole folio is leaked if any bad check fails; neither healthy nor HWPoison page reaches buddy.
Quoted 72 lines
Quoted 44 lines
mm/memory-failure.c +16
-10} -if (init) -clear_highpages_kasan_tagged (page,1 << order); - -/* -* arch_free_page() can make the page's contents inaccessible. s390 -* does this. So nothing which can access the page's contents should -* happen after this. -*/ -arch_free_page (page, order); -debug_pagealloc_unmap_pages (page,1 << order); +free_pages_sanitize (page, order);return true; }@@ -7059,7 +7108,14 @@ static void free_prepared_contig_range(struct page *page,/* * Free the chunk as a single block. Our caller has already * called free_pages_prepare() for each order-0 page. +* +* If the original compound page has HWPoison page, +* free_pages_prepare() has to skip sanitize at that time, +* but now it is good time to do that. */ +if (fpi_flags &FPI_SANITIZE ) +free_pages_sanitize (page, order); +__free_frozen_pages (page, order, fpi_flags |FPI_PREPARED ); pfn +=1UL << order;@@ -7141,6 +7197,69 @@ void __free_contig_range(unsigned long pfn, unsigned long nr_pages)__free_contig_range_common (pfn, nr_pages,/* is_frozen= */ false); } +/* +* Given some contiguous pages that have num_hwpoisoned HWPoison page(s), +* free only the healthy ones. +* +* Used at the end of __free_pages_prepare(). Even if having HWPoison pages, +* breaking down compound page and clearing metadata (e.g. page owner, alloc +* tag) can be done together during __free_pages_prepare(), which simplifies +* the splitting here: unlike __split_unmapped_folio(), there is no need to mm/memory-failure.c void __free_contig_range(unsigned long pfn, unsigned long nr_pages) · line 7217
Quoted 10 lines
mm/memory-failure.c +10
-0+* turn split pages into a compound page or to carry metadata. +* +* It scans every raw page of the compound page and causes nontrivial overhead. +* So only use this when the compound page contains HWPoison page(s). +* +* This implementation needs rework in memdesc world. +*/ +static void free_has_hwpoisoned (struct page *page,unsigned int order, +unsigned int num_hwpoisoned, +fpi_t fpi_flags)There are codes for order = 0 in
__free_pages_prepare:if (unlikely(PageHWPoison(page)) && !order) { /* Do not let hwpoison pages hit pcplists/buddy */ reset_page_owner(page, order); page_table_check_free(page, order); pgalloc_tag_sub(page, 1 << order); /* * The page is isolated and accounted for. * Mark the codetag as empty to avoid accounting error * when the page is freed by unpoison_memory(). */ clear_page_tag_ref(page); return false; }
Quoted 2 lines
Can
free_has_hwpoisonedalso handle order=0 pages? This way, the hwpoison-related handling code can be centralized here.
Yes, free_has_hwpoisoned() can handle a 0-order page. I can do this in a separate commit, not folded into this commit, because once we leave free_has_hwpoisoned() to handle the 0-order page, its end state will be refcount==1 and HWPoisonTakenOff. This is a behavior change from today's: refcount==0 and no HWPoisonTakenOff.
The end state matters to unpoison_memory(). Today unpoison_memory() only calls folio_test_clear_hwpoison() as the page's refcount is 0. So after unpoison the page is not freed to buddy. In comparison I think the new end state is better: after handled by free_has_hwpoisoned(), __get_unpoison_page() sees PageHWPoisonTakenOff so unpoison_memory() calls put_page_back_buddy() to free it to buddy.
Quoted 14 lines
Quoted 14 lines
mm/memory-failure.c +13
-0+{ +unsigned long curr =page_to_pfn (page); +unsigned long end_pfn = curr + (1UL << order); +unsigned long next; +struct page *hwpoisoned; + +while (curr < end_pfn) { +if (!num_hwpoisoned) { +/* No more HWPoison page in [curr, end_pfn) */ +free_prepared_contig_range (pfn_to_page (curr), + end_pfn - curr, fpi_flags); +break ; + }
Quoted 8 lines
mm/memory-failure.c void __free_contig_range(unsigned long pfn, unsigned long nr_pages) · line 7236
Quoted 6 lines
mm/memory-failure.c +6
-0+ + next = curr; +while (next < end_pfn && !PageHWPoison (pfn_to_page (next))) + ++next; + +if (next != end_pfn) {We reach here with
num_hwpoisoned!= 0. So next can not be equal toend_pfn?
Yes, we can take the block out of "if (next != end_pfn)" and remove "if (next == end_pfn) break" too.
One thing I want to add: unpoison_memory() on a page whose refcount is 0 (its ghp == 0 path) does TestClearPageHWPoison() without any lock the free path holds. If that races with the free, the scan runs to end_pfn. So I'd like to make it visible by:
if (WARN_ON_ONCE(next == end_pfn))
break;Quoted 26 lines
Quoted 11 lines
mm/memory-failure.c +10
-0+ hwpoisoned =pfn_to_page (next); +/* +* Avoid accounting error when the page is freed +* by unpoison_memory(). +*/ +clear_page_tag_ref (hwpoisoned); +/* +* unpoison_memory() will put_page_back_buddy() +* for HWPoisonTakenOff pages. Increment refcount +* to avoid VM_BUG() from put_page_testzero(). mm/memory-failure.c void __free_contig_range(unsigned long pfn, unsigned long nr_pages) · line 7256
Quoted 10 lines
mm/memory-failure.c +10
-0+*/ +page_ref_inc (hwpoisoned); +SetPageHWPoisonTakenOff (hwpoisoned); + --num_hwpoisoned; + } + +free_prepared_contig_range (pfn_to_page (curr), next - curr, + fpi_flags); + +if (next == end_pfn)Ditto.
Thanks.
.
Miaohe Lin
maintainerRe: [PATCH v7 2/3] mm/page_alloc: only free healthy pages in high-order folio
Quoted 171 lines · Jiaqi Yan
Quoted 112 lines · Miaohe Lin
Quoted 110 lines · Jiaqi Yan
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 betweendissolve_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, whichcheck_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 countingPageHWPoison()pages in that loop is cheap, as pointed out by David Hildenbrand [4]. UnlikePG_has_hwpoisoned, which is only maintained for THP, this catches HWPoison pages in any high-order folio, including dissolved HugeTLB folios.If any HWPoison page is found, then after all checks and preparations in
__free_pages_prepare()succeed, take a shortcut to the newly introducedfree_has_hwpoisoned(), which only frees the healthy pages and excludes the HWPoison ones.__free_pages_prepare()then returns false so that its callers don't free the folio again.
free_has_hwpoisoned()iterates through the pages of the folio to identify contiguous ranges of healthy pages. It usesfree_prepared_contig_range()to decompose each healthy range into the largest possible chunks of different orders, which are then freed via__free_frozen_pages(). Knowing the number of HWPoison pages from__free_pages_prepare(), it stops scanning once all of them are found, and frees the remaining pages without scanning them.Sanitizing pages at free time (e.g. page poisoning and
init_on_free) may write to page contents, which must be avoided for HWPoison pages. So factor it out of__free_pages_prepare()intofree_pages_sanitize(), and skip it for a folio that has HWPoison pages. Instead,free_has_hwpoisoned()passes the newFPI_SANITIZEflag tofree_prepared_contig_range(), which then sanitizes each healthy chunk right before freeing it.Each excluded HWPoison page is treated like a page that
memory_failure()takes off buddy allocator: it is marked PageHWPoisonTakenOff and holds a refcount of 1. Its alloc tag reference is also cleared, as is done for an order-0 HWPoison page in__free_pages_prepare(). This allowsunpoison_memory()to put it back to buddy allocator viaput_page_back_buddy()instead of leaking it.As a result,
memory_failure()no longer needs to take HWPoison pages off buddy allocator after dissolving a HugeTLB folio. For a free HugeTLB folio, or an anonymous one that becomes free after being unmapped,try_memory_failure_hugetlb()andme_huge_page()call__page_handle_poison(), which disables pcplists, dissolves the folio and then callstake_page_off_buddy(). Since the raw HWPoison page never reaches buddy allocator now,take_page_off_buddy()would fail, andmemory_failure()would reportMF_FAILED.So add
__hugepage_handle_poison()for these two callers. It dissolves the folio and then checks whether the raw HWPoison page has been isolated, i.e. is HWPoisonTakenOff. It doesn't test any HugeTLB flags, because the folio may have already been freed, e.g. byfolio_put()inme_huge_page()if it was a surplus folio, or by a concurrent dissolve. If the folio'sraw_hwp_listis unreliable,__update_and_free_hugetlb_folio()leaks the folio and the raw HWPoison page is not isolated, somemory_failure()still reportsMF_FAILED. Asfree_has_hwpoisoned()already holds a refcount on each isolated page, the callers no longerpage_ref_inc()it. Soft offline keeps using__page_handle_poison(), because it marks a page HWPoison only after taking it off buddy allocator.
free_has_hwpoisoned()has linear time complexity wrt the number of pages in the folio; the worst case is when the last page of the folio is HWPoison. While the power-of-two decomposition keeps the number of calls to buddy allocator small, the linear scan of pages to identifyPageHWPoison()defines the overall time complexity. For a 1G hugepage having 8 HWPoison pages and if the last page is HWPoison,free_has_hwpoisoned()takes in worst case 15x the timefree_one_page()takes for a healthy 1G hugepage, measured on a system having 56 Intel Skylake physical cores. The cost is nontrivial but far from triggering soft lockup, and fair for handling exceptional hardware memory errors.This commit message text was reworded with an AI assistant, then reviewed and edited by me. The code changes are my own, but they are reviewed by the AI assistant.
[1] https://lore.kernel.org/linux-mm/[email protected]
[2] https://lore.kernel.org/linux-mm/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://lore.kernel.org/linux-mm/[email protected]Quoted 4 lines
Quoted 2 lines
Assisted-by Antigravity:claude-opus-5-5Signed-off-by Jiaqi Yan <[email protected]>Thanks for update. Some questions below.
Thanks for your review, Miaohe!
Quoted 42 lines
Quoted 42 lines
--- mm/internal.h | 3 + mm/memory-failure.c | 52 +++++++++----- mm/page_alloc.c | 170 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 183 insertions(+), 42 deletions(-)mm/internal.h +4
-0@@ -1195,6 +1195,9 @@ static inline int unmap_poisoned_folio(struct folio *folio, unsigned long pfn, b {return -EBUSY ; } + +static inline void SetPageHWPoisonTakenOff (struct page *page) +{ +}#endif extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long,mm/memory-failure.c +12
-0@@ -214,7 +214,40 @@ static struct rb_root_cached pfn_space_itree = RB_ROOT_CACHED;static DEFINE_MUTEX (pfn_space_lock); +static inline bool PageHWPoisonTakenOff (struct page *page) +{ +return PageHWPoison (page) &&page_private (page) ==MAGIC_HWPOISON ; +} + +/* +* Only for a HugeTLB page being handled by memory_failure(). +* Unlike soft_offline_page(), no HWPoison subpage makes it into +* buddy allocator when the folio is freed, so take_page_off_buddy() +* is unnecessary. +* +* Return values: Quoted 8 lines
mm/memory-failure.c static struct rb_root_cached pfn_space_itree = RB_ROOT_CACHED; · line 233
Quoted 5 lines
mm/memory-failure.c +5
-0+* 1: the folio is dissolved and the page is isolated with +* HWPoisonTakenOff and refcount=1. Caller must not take +* another refcount. +* 0: the folio is dissolved but the page is not isolated, +* e.g. the folio's raw_hwp_list is unreliable. If folio's
raw_hwp_listis unreliable, I think it cannot be dissolved. So above comment confused me.
Quoted 5 lines
Ah I think "dissolve" is ambiguous and confusing here. For
raw_hwp_unreliablefolio,dissolve_free_hugetlb_folio()does return 0 and deemed "success"; however, nothing went to buddy due toraw_hwp_unreliable. How about I say: "the folio has left the HugeTLB pool but the page is not isolated."
Makes sense to me. However, this does not always hold: when hugetlb_vmemmap_restore_folio() fails, the raw_hwp_unreliable hugetlb page is added back to the hugetlb pool.
Quoted 4 lines
BTW, I am working on a change to
free_huge_folio(), which can remove__hugepage_handle_poison()entirely. See
https://lore.kernel.org/linux-mm/CACw3F53Q-h0jHH_JChMqojp6R_Zwx4DuD_Mte3Ve5CWc=01Z8A@mail.gmail.com.
Sounds like a good change. Thanks for your work.
Quoted 82 lines
Quoted 82 lines
Quoted 6 lines
mm/memory-failure.c +3
-0+* < 0: failed to dissolve folio. +*/ +static int __hugepage_handle_poison (struct page *page)...
Quoted 54 lines
mm/memory-failure.c +15
-9+/* +* Returns +* - true: checks and preparations all good, caller can proceed freeing. +* - false: do not proceed freeing for one of the following reasons: +* 1. Some check failed so it is not safe to proceed freeing. +* 2. A compound page has some HWPoison pages. The healthy pages +* are already safely freed, and the HWPoison ones isolated. +*/ static __always_inline bool __free_pages_prepare(struct page *page,unsigned int order,fpi_t fpi_flags) {int bad =0 ; -bool skip_kasan_poison =should_skip_kasan_poison (page); -bool init =want_init_on_free ();bool compound =PageCompound (page);struct folio *folio =page_folio (page); +unsigned int num_hwpoisoned =0 ;if (fpi_flags &FPI_PREPARED )return true;@@ -1376,6 +1437,7 @@ static __always_inline bool __free_pages_prepare(struct page *page, folio->_nr_pages =0 ;#endif } + num_hwpoisoned +=PageHWPoison (page);for (i =1 ; i < (1 << order); i++) {struct page *tail_page = page + i;@@ -1394,6 +1456,7 @@ static __always_inline bool __free_pages_prepare(struct page *page, } } tail_page->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP ; + num_hwpoisoned +=PageHWPoison (tail_page); } }if (folio_test_anon (folio)) {@@ -1425,34 +1488,20 @@ static __always_inline bool __free_pages_prepare(struct page *page, PAGE_SIZE << order); } -kernel_poison_pages (page,1 << order); -/* -* As memory initialization might be integrated into KASAN, -* KASAN poisoning and memory initialization code must be -* kept together to avoid discrepancies in behavior. +* After breaking down compound page and dealing with page metadata +* (e.g. page owner and page alloc tags), take a shortcut if this +* was a compound page containing certain HWPoison subpages. * -* With hardware tag-based KASAN, memory tags must be set before the -* page becomes unavailable via debug_pagealloc or arch_free_page. +* Pass FPI_SANITIZE to only free_pages_sanitize() healthy pages. */ mm/memory-failure.c static __always_inline bool __free_pages_prepare(struct page *page, · line 1501
Quoted 10 lines
mm/memory-failure.c +4
-6-if (!skip_kasan_poison) { -kasan_poison_pages (page, order, init); - -/* Memory is already initialized if KASAN did it internally. */ -if (kasan_has_integrated_init ()) - init = false; +if (unlikely (num_hwpoisoned)) { +free_has_hwpoisoned (page, order, num_hwpoisoned, + fpi_flags |FPI_SANITIZE ); +return false;There is
free_page_is_badcheck above this:if (is_check_pages_enabled()) { if (free_page_is_bad(page)) bad++; if (bad) return false; }
Quoted 5 lines
Quoted 2 lines
It can return early if bad is true. In this case,
free_has_hwpoisonedcannot handle the hwpoisoned subpages. Is this expected behavior?Yes, that is expected and safe: the whole folio is leaked if any bad check fails; neither healthy nor HWPoison page reaches buddy.
For order == 0 folios, HWPoison is checked and delt before free_page_is_bad. But for order > 0 folios, check order reversed. Won't this lead to divergent behavior?
Quoted 82 lines
Quoted 73 lines
Quoted 45 lines
mm/memory-failure.c +16
-10} -if (init) -clear_highpages_kasan_tagged (page,1 << order); - -/* -* arch_free_page() can make the page's contents inaccessible. s390 -* does this. So nothing which can access the page's contents should -* happen after this. -*/ -arch_free_page (page, order); -debug_pagealloc_unmap_pages (page,1 << order); +free_pages_sanitize (page, order);return true; }@@ -7059,7 +7108,14 @@ static void free_prepared_contig_range(struct page *page,/* * Free the chunk as a single block. Our caller has already * called free_pages_prepare() for each order-0 page. +* +* If the original compound page has HWPoison page, +* free_pages_prepare() has to skip sanitize at that time, +* but now it is good time to do that. */ +if (fpi_flags &FPI_SANITIZE ) +free_pages_sanitize (page, order); +__free_frozen_pages (page, order, fpi_flags |FPI_PREPARED ); pfn +=1UL << order;@@ -7141,6 +7197,69 @@ void __free_contig_range(unsigned long pfn, unsigned long nr_pages)__free_contig_range_common (pfn, nr_pages,/* is_frozen= */ false); } +/* +* Given some contiguous pages that have num_hwpoisoned HWPoison page(s), +* free only the healthy ones. +* +* Used at the end of __free_pages_prepare(). Even if having HWPoison pages, +* breaking down compound page and clearing metadata (e.g. page owner, alloc +* tag) can be done together during __free_pages_prepare(), which simplifies +* the splitting here: unlike __split_unmapped_folio(), there is no need to mm/memory-failure.c void __free_contig_range(unsigned long pfn, unsigned long nr_pages) · line 7217
Quoted 10 lines
mm/memory-failure.c +10
-0+* turn split pages into a compound page or to carry metadata. +* +* It scans every raw page of the compound page and causes nontrivial overhead. +* So only use this when the compound page contains HWPoison page(s). +* +* This implementation needs rework in memdesc world. +*/ +static void free_has_hwpoisoned (struct page *page,unsigned int order, +unsigned int num_hwpoisoned, +fpi_t fpi_flags)There are codes for order = 0 in
__free_pages_prepare:if (unlikely(PageHWPoison(page)) && !order) { /* Do not let hwpoison pages hit pcplists/buddy */ reset_page_owner(page, order); page_table_check_free(page, order); pgalloc_tag_sub(page, 1 << order); /* * The page is isolated and accounted for. * Mark the codetag as empty to avoid accounting error * when the page is freed by unpoison_memory(). */ clear_page_tag_ref(page); return false; }Quoted 2 lines
Can
free_has_hwpoisonedalso handle order=0 pages? This way, the hwpoison-related handling code can be centralized here.Yes,
free_has_hwpoisoned()can handle a 0-order page. I can do this in a separate commit, not folded into this commit, because once we leavefree_has_hwpoisoned()to handle the 0-order page, its end state will be refcount==1 and HWPoisonTakenOff. This is a behavior change from today's: refcount==0 and no HWPoisonTakenOff.
Quoted 6 lines
The end state matters to
unpoison_memory(). Todayunpoison_memory()only callsfolio_test_clear_hwpoison()as the page's refcount is 0. So after unpoison the page is not freed to buddy. In comparison I think the new end state is better: after handled byfree_has_hwpoisoned(),__get_unpoison_page()sees PageHWPoisonTakenOff sounpoison_memory()callsput_page_back_buddy()to free it to buddy.
This sounds like a reasonable adjustment. :)
Quoted 27 lines
Quoted 15 lines
Quoted 15 lines
mm/memory-failure.c +13
-0+{ +unsigned long curr =page_to_pfn (page); +unsigned long end_pfn = curr + (1UL << order); +unsigned long next; +struct page *hwpoisoned; + +while (curr < end_pfn) { +if (!num_hwpoisoned) { +/* No more HWPoison page in [curr, end_pfn) */ +free_prepared_contig_range (pfn_to_page (curr), + end_pfn - curr, fpi_flags); +break ; + }Quoted 8 lines
mm/memory-failure.c void __free_contig_range(unsigned long pfn, unsigned long nr_pages) · line 7236
Quoted 6 lines
mm/memory-failure.c +6
-0+ + next = curr; +while (next < end_pfn && !PageHWPoison (pfn_to_page (next))) + ++next; + +if (next != end_pfn) {We reach here with
num_hwpoisoned!= 0. So next can not be equal toend_pfn?Yes, we can take the block out of "if (next !=
end_pfn)" and remove "if (next ==end_pfn) break" too.
Quoted 7 lines
One thing I want to add:
unpoison_memory()on a page whose refcount is 0 (its ghp == 0 path) doesTestClearPageHWPoison()without any lock the free path holds. If that races with the free, the scan runs toend_pfn. So I'd like to make it visible by:if (WARN_ON_ONCE(next == end_pfn)) break;
That reminds me of a scenario. Is below race possible?
unpoison_memory free_has_hwpoisoned
get_hwpoison_page PageHWPoison still holds
if (!ghp)
folio_test_clear_hwpoison
page_ref_inc(hwpoisoned);
SetPageHWPoisonTakenOff(hwpoisoned);PageHWPoison would be cleared while folio is still in PageHWPoisonTakenOff state. So the folio is leaked. Or am I miss something?
Thanks.
.
Re: [PATCH v7 2/3] mm/page_alloc: only free healthy pages in high-order folio
Quoted 412 lines · Miaohe Lin
Quoted 171 lines · Jiaqi Yan
Quoted 112 lines · Miaohe Lin
Quoted 110 lines · Jiaqi Yan
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 betweendissolve_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, whichcheck_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 countingPageHWPoison()pages in that loop is cheap, as pointed out by David Hildenbrand [4]. UnlikePG_has_hwpoisoned, which is only maintained for THP, this catches HWPoison pages in any high-order folio, including dissolved HugeTLB folios.If any HWPoison page is found, then after all checks and preparations in
__free_pages_prepare()succeed, take a shortcut to the newly introducedfree_has_hwpoisoned(), which only frees the healthy pages and excludes the HWPoison ones.__free_pages_prepare()then returns false so that its callers don't free the folio again.
free_has_hwpoisoned()iterates through the pages of the folio to identify contiguous ranges of healthy pages. It usesfree_prepared_contig_range()to decompose each healthy range into the largest possible chunks of different orders, which are then freed via__free_frozen_pages(). Knowing the number of HWPoison pages from__free_pages_prepare(), it stops scanning once all of them are found, and frees the remaining pages without scanning them.Sanitizing pages at free time (e.g. page poisoning and
init_on_free) may write to page contents, which must be avoided for HWPoison pages. So factor it out of__free_pages_prepare()intofree_pages_sanitize(), and skip it for a folio that has HWPoison pages. Instead,free_has_hwpoisoned()passes the newFPI_SANITIZEflag tofree_prepared_contig_range(), which then sanitizes each healthy chunk right before freeing it.Each excluded HWPoison page is treated like a page that
memory_failure()takes off buddy allocator: it is marked PageHWPoisonTakenOff and holds a refcount of 1. Its alloc tag reference is also cleared, as is done for an order-0 HWPoison page in__free_pages_prepare(). This allowsunpoison_memory()to put it back to buddy allocator viaput_page_back_buddy()instead of leaking it.As a result,
memory_failure()no longer needs to take HWPoison pages off buddy allocator after dissolving a HugeTLB folio. For a free HugeTLB folio, or an anonymous one that becomes free after being unmapped,try_memory_failure_hugetlb()andme_huge_page()call__page_handle_poison(), which disables pcplists, dissolves the folio and then callstake_page_off_buddy(). Since the raw HWPoison page never reaches buddy allocator now,take_page_off_buddy()would fail, andmemory_failure()would reportMF_FAILED.So add
__hugepage_handle_poison()for these two callers. It dissolves the folio and then checks whether the raw HWPoison page has been isolated, i.e. is HWPoisonTakenOff. It doesn't test any HugeTLB flags, because the folio may have already been freed, e.g. byfolio_put()inme_huge_page()if it was a surplus folio, or by a concurrent dissolve. If the folio'sraw_hwp_listis unreliable,__update_and_free_hugetlb_folio()leaks the folio and the raw HWPoison page is not isolated, somemory_failure()still reportsMF_FAILED. Asfree_has_hwpoisoned()already holds a refcount on each isolated page, the callers no longerpage_ref_inc()it. Soft offline keeps using__page_handle_poison(), because it marks a page HWPoison only after taking it off buddy allocator.
free_has_hwpoisoned()has linear time complexity wrt the number of pages in the folio; the worst case is when the last page of the folio is HWPoison. While the power-of-two decomposition keeps the number of calls to buddy allocator small, the linear scan of pages to identifyPageHWPoison()defines the overall time complexity. For a 1G hugepage having 8 HWPoison pages and if the last page is HWPoison,free_has_hwpoisoned()takes in worst case 15x the timefree_one_page()takes for a healthy 1G hugepage, measured on a system having 56 Intel Skylake physical cores. The cost is nontrivial but far from triggering soft lockup, and fair for handling exceptional hardware memory errors.This commit message text was reworded with an AI assistant, then reviewed and edited by me. The code changes are my own, but they are reviewed by the AI assistant.
[1] https://lore.kernel.org/linux-mm/[email protected]
[2] https://lore.kernel.org/linux-mm/[email protected]
[3] https://lore.kernel.org/all/[email protected]
[4] https://lore.kernel.org/linux-mm/[email protected]Quoted 4 lines
Quoted 2 lines
Assisted-by Antigravity:claude-opus-5-5Signed-off-by Jiaqi Yan <[email protected]>Thanks for update. Some questions below.
Thanks for your review, Miaohe!
Quoted 42 lines
Quoted 42 lines
--- mm/internal.h | 3 + mm/memory-failure.c | 52 +++++++++----- mm/page_alloc.c | 170 +++++++++++++++++++++++++++++++++++++------- 3 files changed, 183 insertions(+), 42 deletions(-)mm/internal.h +4
-0@@ -1195,6 +1195,9 @@ static inline int unmap_poisoned_folio(struct folio *folio, unsigned long pfn, b {return -EBUSY ; } + +static inline void SetPageHWPoisonTakenOff (struct page *page) +{ +}#endif extern unsigned long __must_check vm_mmap_pgoff(struct file *, unsigned long,mm/memory-failure.c +12
-0@@ -214,7 +214,40 @@ static struct rb_root_cached pfn_space_itree = RB_ROOT_CACHED;static DEFINE_MUTEX (pfn_space_lock); +static inline bool PageHWPoisonTakenOff (struct page *page) +{ +return PageHWPoison (page) &&page_private (page) ==MAGIC_HWPOISON ; +} + +/* +* Only for a HugeTLB page being handled by memory_failure(). +* Unlike soft_offline_page(), no HWPoison subpage makes it into +* buddy allocator when the folio is freed, so take_page_off_buddy() +* is unnecessary. +* +* Return values: Quoted 8 lines
mm/memory-failure.c static struct rb_root_cached pfn_space_itree = RB_ROOT_CACHED; · line 233
Quoted 5 lines
mm/memory-failure.c +5
-0+* 1: the folio is dissolved and the page is isolated with +* HWPoisonTakenOff and refcount=1. Caller must not take +* another refcount. +* 0: the folio is dissolved but the page is not isolated, +* e.g. the folio's raw_hwp_list is unreliable. If folio's
raw_hwp_listis unreliable, I think it cannot be dissolved. So above comment confused me.Quoted 5 lines
Ah I think "dissolve" is ambiguous and confusing here. For
raw_hwp_unreliablefolio,dissolve_free_hugetlb_folio()does return 0 and deemed "success"; however, nothing went to buddy due toraw_hwp_unreliable. How about I say: "the folio has left the HugeTLB pool but the page is not isolated."Makes sense to me. However, this does not always hold: when
hugetlb_vmemmap_restore_folio()fails, theraw_hwp_unreliablehugetlb page is added back to the hugetlb pool.Quoted 4 lines
BTW, I am working on a change to
free_huge_folio(), which can remove__hugepage_handle_poison()entirely. See
https://lore.kernel.org/linux-mm/CACw3F53Q-h0jHH_JChMqojp6R_Zwx4DuD_Mte3Ve5CWc=01Z8A@mail.gmail.com.Sounds like a good change. Thanks for your work.
Quoted 82 lines
Quoted 82 lines
Quoted 6 lines
mm/memory-failure.c +3
-0+* < 0: failed to dissolve folio. +*/ +static int __hugepage_handle_poison (struct page *page)...
Quoted 54 lines
mm/memory-failure.c +15
-9+/* +* Returns +* - true: checks and preparations all good, caller can proceed freeing. +* - false: do not proceed freeing for one of the following reasons: +* 1. Some check failed so it is not safe to proceed freeing. +* 2. A compound page has some HWPoison pages. The healthy pages +* are already safely freed, and the HWPoison ones isolated. +*/ static __always_inline bool __free_pages_prepare(struct page *page,unsigned int order,fpi_t fpi_flags) {int bad =0 ; -bool skip_kasan_poison =should_skip_kasan_poison (page); -bool init =want_init_on_free ();bool compound =PageCompound (page);struct folio *folio =page_folio (page); +unsigned int num_hwpoisoned =0 ;if (fpi_flags &FPI_PREPARED )return true;@@ -1376,6 +1437,7 @@ static __always_inline bool __free_pages_prepare(struct page *page, folio->_nr_pages =0 ;#endif } + num_hwpoisoned +=PageHWPoison (page);for (i =1 ; i < (1 << order); i++) {struct page *tail_page = page + i;@@ -1394,6 +1456,7 @@ static __always_inline bool __free_pages_prepare(struct page *page, } } tail_page->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP ; + num_hwpoisoned +=PageHWPoison (tail_page); } }if (folio_test_anon (folio)) {@@ -1425,34 +1488,20 @@ static __always_inline bool __free_pages_prepare(struct page *page, PAGE_SIZE << order); } -kernel_poison_pages (page,1 << order); -/* -* As memory initialization might be integrated into KASAN, -* KASAN poisoning and memory initialization code must be -* kept together to avoid discrepancies in behavior. +* After breaking down compound page and dealing with page metadata +* (e.g. page owner and page alloc tags), take a shortcut if this +* was a compound page containing certain HWPoison subpages. * -* With hardware tag-based KASAN, memory tags must be set before the -* page becomes unavailable via debug_pagealloc or arch_free_page. +* Pass FPI_SANITIZE to only free_pages_sanitize() healthy pages. */ mm/memory-failure.c static __always_inline bool __free_pages_prepare(struct page *page, · line 1501
Quoted 10 lines
mm/memory-failure.c +4
-6-if (!skip_kasan_poison) { -kasan_poison_pages (page, order, init); - -/* Memory is already initialized if KASAN did it internally. */ -if (kasan_has_integrated_init ()) - init = false; +if (unlikely (num_hwpoisoned)) { +free_has_hwpoisoned (page, order, num_hwpoisoned, + fpi_flags |FPI_SANITIZE ); +return false;There is
free_page_is_badcheck above this:if (is_check_pages_enabled()) { if (free_page_is_bad(page)) bad++; if (bad) return false; }Quoted 5 lines
Quoted 2 lines
It can return early if bad is true. In this case,
free_has_hwpoisonedcannot handle the hwpoisoned subpages. Is this expected behavior?Yes, that is expected and safe: the whole folio is leaked if any bad check fails; neither healthy nor HWPoison page reaches buddy.
For order == 0 folios, HWPoison is checked and delt before
free_page_is_bad. But for order > 0 folios, check order reversed. Won't this lead to divergent behavior?Quoted 82 lines
Quoted 73 lines
Quoted 45 lines
mm/memory-failure.c +16
-10} -if (init) -clear_highpages_kasan_tagged (page,1 << order); - -/* -* arch_free_page() can make the page's contents inaccessible. s390 -* does this. So nothing which can access the page's contents should -* happen after this. -*/ -arch_free_page (page, order); -debug_pagealloc_unmap_pages (page,1 << order); +free_pages_sanitize (page, order);return true; }@@ -7059,7 +7108,14 @@ static void free_prepared_contig_range(struct page *page,/* * Free the chunk as a single block. Our caller has already * called free_pages_prepare() for each order-0 page. +* +* If the original compound page has HWPoison page, +* free_pages_prepare() has to skip sanitize at that time, +* but now it is good time to do that. */ +if (fpi_flags &FPI_SANITIZE ) +free_pages_sanitize (page, order); +__free_frozen_pages (page, order, fpi_flags |FPI_PREPARED ); pfn +=1UL << order;@@ -7141,6 +7197,69 @@ void __free_contig_range(unsigned long pfn, unsigned long nr_pages)__free_contig_range_common (pfn, nr_pages,/* is_frozen= */ false); } +/* +* Given some contiguous pages that have num_hwpoisoned HWPoison page(s), +* free only the healthy ones. +* +* Used at the end of __free_pages_prepare(). Even if having HWPoison pages, +* breaking down compound page and clearing metadata (e.g. page owner, alloc +* tag) can be done together during __free_pages_prepare(), which simplifies +* the splitting here: unlike __split_unmapped_folio(), there is no need to mm/memory-failure.c void __free_contig_range(unsigned long pfn, unsigned long nr_pages) · line 7217
Quoted 10 lines
mm/memory-failure.c +10
-0+* turn split pages into a compound page or to carry metadata. +* +* It scans every raw page of the compound page and causes nontrivial overhead. +* So only use this when the compound page contains HWPoison page(s). +* +* This implementation needs rework in memdesc world. +*/ +static void free_has_hwpoisoned (struct page *page,unsigned int order, +unsigned int num_hwpoisoned, +fpi_t fpi_flags)There are codes for order = 0 in
__free_pages_prepare:if (unlikely(PageHWPoison(page)) && !order) { /* Do not let hwpoison pages hit pcplists/buddy */ reset_page_owner(page, order); page_table_check_free(page, order); pgalloc_tag_sub(page, 1 << order); /* * The page is isolated and accounted for. * Mark the codetag as empty to avoid accounting error * when the page is freed by unpoison_memory(). */ clear_page_tag_ref(page); return false; }Quoted 2 lines
Can
free_has_hwpoisonedalso handle order=0 pages? This way, the hwpoison-related handling code can be centralized here.Yes,
free_has_hwpoisoned()can handle a 0-order page. I can do this in a separate commit, not folded into this commit, because once we leavefree_has_hwpoisoned()to handle the 0-order page, its end state will be refcount==1 and HWPoisonTakenOff. This is a behavior change from today's: refcount==0 and no HWPoisonTakenOff.Quoted 6 lines
The end state matters to
unpoison_memory(). Todayunpoison_memory()only callsfolio_test_clear_hwpoison()as the page's refcount is 0. So after unpoison the page is not freed to buddy. In comparison I think the new end state is better: after handled byfree_has_hwpoisoned(),__get_unpoison_page()sees PageHWPoisonTakenOff sounpoison_memory()callsput_page_back_buddy()to free it to buddy.This sounds like a reasonable adjustment. :)
Quoted 27 lines
Quoted 15 lines
Quoted 15 lines
mm/memory-failure.c +13
-0+{ +unsigned long curr =page_to_pfn (page); +unsigned long end_pfn = curr + (1UL << order); +unsigned long next; +struct page *hwpoisoned; + +while (curr < end_pfn) { +if (!num_hwpoisoned) { +/* No more HWPoison page in [curr, end_pfn) */ +free_prepared_contig_range (pfn_to_page (curr), + end_pfn - curr, fpi_flags); +break ; + }Quoted 8 lines
mm/memory-failure.c void __free_contig_range(unsigned long pfn, unsigned long nr_pages) · line 7236
Quoted 6 lines
mm/memory-failure.c +6
-0+ + next = curr; +while (next < end_pfn && !PageHWPoison (pfn_to_page (next))) + ++next; + +if (next != end_pfn) {We reach here with
num_hwpoisoned!= 0. So next can not be equal toend_pfn?Yes, we can take the block out of "if (next !=
end_pfn)" and remove "if (next ==end_pfn) break" too.Quoted 7 lines
One thing I want to add:
unpoison_memory()on a page whose refcount is 0 (its ghp == 0 path) doesTestClearPageHWPoison()without any lock the free path holds. If that races with the free, the scan runs toend_pfn. So I'd like to make it visible by:if (WARN_ON_ONCE(next == end_pfn)) break;That reminds me of a scenario. Is below race possible?
unpoison_memoryfree_has_hwpoisoned
get_hwpoison_pagePageHWPoison still holds
if (!ghp)
folio_test_clear_hwpoison
Quoted 5 lines
page_ref_inc(hwpoisoned); SetPageHWPoisonTakenOff(hwpoisoned);PageHWPoison would be cleared while folio is still in PageHWPoisonTakenOff state. So the folio is leaked. Or am I miss something?
Thanks, Miaohe.
Yeah, I think the race is possible, and the page is leaked: it ends up with refcount 1 and MAGIC_HWPOISON in page->private, but without PG_hwpoison, so it is not PageHWPoisonTakenOff and a second unpoison just says "already unpoisoned".
Before addressing this and your other comments here, a heads-up on the plan: following David's suggestion [1], I am splitting the actual fix out of this series, and will send it to you as a new, standalone series shortly. It keeps the whole high-order folio out of the buddy allocator if any of its pages is HWPoison, without the freeing part. The order-0 path in __free_pages_prepare() is left as is.
The "free healthy pages" part of v7 will come back later as a separate series on top of the new one. I will address your v7 comments there, when rebasing it.
[1] https://lore.kernel.org/linux-mm/[email protected]
Thanks,
Jiaqi
Quoted 3 lines
Thanks.
.
David Hildenbrand (Arm)
maintainerRe: [PATCH v7 2/3] mm/page_alloc: only free healthy pages in high-order folio
In reply to Jiaqi YanQuoted 30 lines · Jiaqi Yan
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 betweendissolve_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, whichcheck_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].
Quoted 7 lines
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 countingPageHWPoison()pages in that loop is cheap, as pointed out by David Hildenbrand [4]. UnlikePG_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/[email protected]/
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).
Signature · 3 lines
Cheers, David
Re: [PATCH v7 2/3] mm/page_alloc: only free healthy pages in high-order folio
Quoted 56 lines · David Hildenbrand (Arm)
Quoted 30 lines · Jiaqi Yan
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 betweendissolve_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, whichcheck_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].Quoted 7 lines
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 countingPageHWPoison()pages in that loop is cheap, as pointed out by David Hildenbrand [4]. UnlikePG_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_hwpoisonedalso 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/[email protected]/
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.
Quoted 6 lines
Of course, we might also be able to do that with PageHWPoison, but
PG_has_hwpoisonedwould 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).
Thanks David, that makes sense to me. I will split the "fix" from the "free healthy pages" part, and send the fix as a new, standalone
series: when a high-order folio with any HWPoison page is freed, __free_pages_prepare() rejects the whole folio.
The cost is leaking the whole folio, e.g. 1G per memory error for a 1G hugepage. That is intended: reusing a HWPoison page is argubably worse than losing the memory. Recycling the healthy pages can come as a separate series on top later, which is where I will rework what v7 did.
For detecting the HWPoison pages, I went with PageHWPoison instead of PG_has_hwpoisoned, at least for now. __free_pages_prepare() already walks every tail page of a high-order folio, so it is pretty cheap to just "has_hwpoisoned |= PageHWPoison(page)" in that loop, which you suggested earlier.
PG_has_hwpoisoned is only defined with CONFIG_TRANSPARENT_HUGEPAGE today. Willy's series [1] relaxes that with CONFIG_LARGE_FOLIO, but it is not merged yet. Besides, for a dissolved HugeTLB folio, the flag would have to survive until the folio is freed. However, [1] clears has_hwpoisoned in folio_clear_hugetlb_hwpoison() when moving the error flags to the raw pages (which is the right thing for his series). So I'd rather not depend on it, or conflict with it.
Once [1] lands, switching to has_hwpoisoned should be straightforward if we prefer it.
[1] https://lore.kernel.org/all/[email protected]/
Thanks,
Jiaqi
Quoted 5 lines
--
Cheers,David
PATCH v7 3/3 selftests/mm: add hard memory failure anonymous HugeTLB test
In reply to Jiaqi YanAdd a new testcase to validate memory failure recovery for HWPoison anonymous HugeTLB page, including proper SIGBUS delivery, releasing a HugeTLB page containing one HWPoison page to buddy allocator, and isolation of the raw HWPoison page.
The test uses HugeTLB's default hugesize.
Although can be added in future, this patch does not support testing the MADV_SOFT variant.
--- tools/testing/selftests/mm/memory-failure.c | 67 ++++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-)
tools/testing/selftests/mm/memory-failure.c +64 -3
@@ -27,6 +27,7 @@ enum inject_type {enum result_type {MADV_HARD_ANON , +MADV_HARD_ANON_HUGETLB ,MADV_HARD_CLEAN_PAGECACHE ,MADV_HARD_DIRTY_PAGECACHE ,MADV_HARD_CLEAN_SHMEM ,
@@ -44,6 +45,10 @@ static siginfo_t siginfo;const char *pagemap_proc ="/proc/self/pagemap" ;const char *kpageflags_proc ="/proc/kpageflags" ; +/* HugeTLB settings will be automatically restored when test exits. */ +#define NR_ALLOC_HUGETLB_PAGES 4 +HUGETLB_SETUP_DEFAULT_PAGES (NR_ALLOC_HUGETLB_PAGES) +FIXTURE (memory_failure ) {unsigned long page_size;
@@ -52,6 +57,8 @@ FIXTURE(memory_failure)int pagemap_fd;int kpageflags_fd;bool injection_attempted; +/* Number of initial HugeTLB pages with default hugepagesize. */ +unsigned long nr_hugetlb_pages; };FIXTURE_VARIANT (memory_failure)
@@ -155,6 +162,7 @@ static void check(struct __test_metadata *_metadata, FIXTURE_DATA(memory_failure void *vaddr, enum result_type type, int setjmp) { unsigned long size; +unsigned long nr_hugetlb_pages;uint64_t pfn_flags;switch (type) {
@@ -175,6 +183,7 @@ static void check(struct __test_metadata *_metadata, FIXTURE_DATA(memory_failureASSERT_NE (pagemap_get_pfn (self->pagemap_fd, vaddr), self->pfn);break ;case MADV_HARD_ANON : +case MADV_HARD_ANON_HUGETLB :case MADV_HARD_DIRTY_PAGECACHE :case MADV_HARD_DIRTY_SHMEM :case READ_ERROR :
@@ -187,8 +196,15 @@ static void check(struct __test_metadata *_metadata, FIXTURE_DATA(memory_failureASSERT_EQ (1UL << siginfo.si_addr_lsb, self->page_size);ASSERT_EQ (siginfo.si_addr, vaddr); -/* XXX Check backing pte is hwpoison entry when supported. */ -ASSERT_TRUE (pagemap_is_swapped (self->pagemap_fd, vaddr)); +if (type !=MADV_HARD_ANON_HUGETLB ) +/* +* Check backing pte is hwpoison entry when supported. +* Although try_to_unmap_one() also installs hwpoison +* entry for HugeTLB, pagemap_hugetlb_range() doesn't +* parse swap entries at all. +*/ +ASSERT_TRUE (pagemap_is_swapped (self->pagemap_fd, vaddr)); +break ;default :SKIP (return,"unexpected inject type %d.\n" , type);
@@ -196,7 +212,19 @@ static void check(struct __test_metadata *_metadata, FIXTURE_DATA(memory_failure/* Check if the value of HardwareCorrupted has increased. */ ASSERT_EQ (get_hardware_corrupted_size (&size),0 ); -ASSERT_EQ (size, self->corrupted_size + self->page_size /1024 ); + +if (type ==MADV_HARD_ANON_HUGETLB ) { +/* +* Only one page is hardware corrupted; the rest should all be +* released to buddy allocator. +*/ +ASSERT_EQ (size, self->corrupted_size +getpagesize () /1024 ); +/* HugeTLB should have lost the HWPoison HugeTLB page. */ + nr_hugetlb_pages =hugetlb_nr_default_pages (); +ASSERT_EQ (nr_hugetlb_pages +1 , self->nr_hugetlb_pages); + }else { +ASSERT_EQ (size, self->corrupted_size + self->page_size /1024 ); + }/* Check if HWPoison flag is set. */ ASSERT_EQ (pageflags_get (self->pfn, self->kpageflags_fd, &pfn_flags),0 );
@@ -261,6 +289,39 @@ TEST_F(memory_failure, anon)ASSERT_EQ (munmap (addr, self->page_size),0 ); } +TEST_F(memory_failure, anon_hugetlb) +{ +char *addr; +int ret; +unsigned long alloc_size; + +if (variant->type ==MADV_SOFT ) +SKIP (return,"Soft offline test is not implemented" ); + + alloc_size =default_huge_page_size () *NR_ALLOC_HUGETLB_PAGES ; + self->page_size =default_huge_page_size (); + self->nr_hugetlb_pages =hugetlb_nr_default_pages (); + + addr =mmap (0 , alloc_size,PROT_READ |PROT_WRITE , +MAP_ANONYMOUS |MAP_PRIVATE |MAP_HUGETLB ,-1 ,0 ); +if (addr ==MAP_FAILED ) +SKIP (return,"mmap failed, not enough memory or hugetlb not supported.\n" ); +memset (addr,0xce , alloc_size); + +prepare (_metadata, self, addr); + + ret =sigsetjmp (signal_jmp_buf,1 ); +if (!self->injection_attempted) { + self->injection_attempted = true; +ASSERT_EQ (variant->inject (self, addr),0 ); +FORCE_READ (*addr); + } + +check (_metadata, self, addr,MADV_HARD_ANON_HUGETLB , ret); + +ASSERT_EQ (munmap (addr, alloc_size),0 ); +} +static int prepare_file (const char *fname,unsigned long size) {int fd;
Signature · 1 line
2.56.0.506.g506a7eabc5-goog