Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Vlastimil Babka (SUSE)" <vbabka@kernel.org>,
	William Roche <william.roche@oracle.com>,
	Jiaqi Yan <jiaqiyan@google.com>,
	linmiaohe@huawei.com, ljs@kernel.org, ziy@nvidia.com
Cc: osalvador@kernel.org, harry.yoo@oracle.com, willy@infradead.org,
	osalvador@suse.de, jackmanb@google.com, hannes@cmpxchg.org,
	nao.horiguchi@gmail.com, tony.luck@intel.com,
	wangkefeng.wang@huawei.com, jane.chu@oracle.com,
	akpm@linux-foundation.org, muchun.song@linux.dev,
	liam@infradead.org, rientjes@google.com, duenwen@google.com,
	jthoughton@google.com, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, rppt@kernel.org, shuah@kernel.org,
	surenb@google.com, mhocko@suse.com, boudewijn@delta-utec.com
Subject: Re: [PATCH v6 0/5] Only free healthy pages in high-order has_hwpoisoned folio
Date: Wed, 5 Aug 2026 11:09:52 +0200	[thread overview]
Message-ID: <352e1f42-2e89-4445-a20e-572ee35c7a0c@kernel.org> (raw)
In-Reply-To: <c5658175-8d1d-4aec-9a66-b07d53f75547@kernel.org>

On 8/5/26 10:58, Vlastimil Babka (SUSE) wrote:
> On 8/4/26 21:51, David Hildenbrand (Arm) wrote:
>> On 7/28/26 19:18, Vlastimil Babka (SUSE) wrote:
>>>
>>> We check all kinds of unexpected state, when that's enable. PageHWPoison
>>> could have been considered unexpected too, when the checks were made more
>>> and more optional (first by Mel and then me).
>>>
>>> But indeed it seems the PageHWPoison check is supposed to be load-bearing
>>> (hi, Lorenzo!). It's intentionally handled before bad_page() (with a taint)
>>> in check_new_page_bad(). Commits 2a7684a23e9c and f4c18e6f7b5b are also a hint.
>>>
>>>
>>> Yes, the PageHWPoison handling was made part of debugging sanity check and
>>> then not recognized properly as load-bearing later.
>>
>> BTW, I'd assume we can check for PageHWPoison at free time fairly efficiently, as we
>> touch all page flags already.
>>
>> Something along the lines of:
>>
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index 520ebd2fa40b5..57f89f8684168 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -1321,6 +1321,7 @@ static __always_inline bool __free_pages_prepare(struct page *page,
>>         bool init = want_init_on_free();
>>         bool compound = PageCompound(page);
>>         struct folio *folio = page_folio(page);
>> +       unsigned int hwpoisoned = 0;
>>  
>>         if (fpi_flags & FPI_PREPARED)
>>                 return true;
>> @@ -1347,21 +1348,6 @@ static __always_inline bool __free_pages_prepare(struct page *page,
>>                 count_vm_events(UNEVICTABLE_PGCLEARED, nr_pages);
>>         }
>>  
>> -       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;
>> -       }
>> -
>>         VM_BUG_ON_PAGE(compound && compound_order(page) != order, page);
>>  
>>         /*
>> @@ -1395,8 +1381,26 @@ static __always_inline bool __free_pages_prepare(struct page *page,
>>                                 }
>>                         }
>>                         tail_page->flags.f &= ~PAGE_FLAGS_CHECK_AT_PREP;
>> +                       hwpoisoned += PageHWPoison(tail_page);
>>                 }
>>         }
>> +       hwpoisoned += PageHWPoison(page);
>> +
>> +       if (unlikely(hwpoisoned)) {
>> +               /* 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;
>> +       }
>> +
>>         if (folio_test_anon(folio)) {
>>                 mod_mthp_stat(order, MTHP_STAT_NR_ANON, -1);
>>                 folio->mapping = NULL;
>> diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile
>>
>>
>> Of course, we could also fallback for order>0 to do some smart splitting.
> 
> I think the freeing part is relatively fine, as tackled by this series.

I think we should really do something like the above to detect hwpoison, to then
fallback to a slow path.

> 
>> Checking on allocation efficiently is indeed a bit more tricky. For compound
>> pages prep_compound_page() will already walk all pages.
> 
> Yeah and non-compound high-order pages should just go away eventually, so I
> wouldn't worry about making them slower now.
> But it's tricky because prep_compound_page() happens later when we don't
> expect anything to fail anymore, so it would take some refactoring.

Agreed.

> 
>> Having hwpoison logic to just sync with the buddy when setting hwpoison flags
>> would be nicer.
> 
> I suggested that (soft-offline does it). There might be some downsides, but
> I can't judge how much they would manifest in practice:
> 
> https://lore.kernel.org/all/CACw3F50nVECJ%2Bk4g%3DQVZ80yzi_awCOcUiCuB0CYcUfxND9-7Tw@mail.gmail.com/

Agreed.

-- 
Cheers,

David


      reply	other threads:[~2026-08-05  9:10 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-05 18:07 [PATCH v6 0/5] Only free healthy pages in high-order has_hwpoisoned folio Jiaqi Yan
2026-07-05 18:07 ` [PATCH v6 1/5] mm/page_alloc: introduce __free_prepared_contig_range() with fpi_t Jiaqi Yan
2026-07-17  7:17   ` Miaohe Lin
2026-07-22  9:38   ` Vlastimil Babka (SUSE)
2026-07-25  3:54   ` Matthew Wilcox
2026-07-05 18:07 ` [PATCH v6 2/5] mm/page_alloc: only free healthy pages in high-order has_hwpoisoned folio Jiaqi Yan
2026-07-17  7:19   ` Miaohe Lin
2026-07-22  9:40   ` Vlastimil Babka (SUSE)
2026-07-05 18:07 ` [PATCH v6 3/5] mm/memory-failure: set has_hwpoisoned flags on dissolved HugeTLB folio Jiaqi Yan
2026-07-25  3:05   ` Jiaqi Yan
2026-07-05 18:07 ` [PATCH v6 4/5] mm/memory-failure: skip take_page_off_buddy after dissolving HWPoison HugeTLB page Jiaqi Yan
2026-07-05 18:07 ` [PATCH v6 5/5] selftests/mm: add hard memory failure anonymous HugeTLB test Jiaqi Yan
2026-07-25  3:05   ` Jiaqi Yan
2026-07-05 18:50 ` [PATCH v6 0/5] Only free healthy pages in high-order has_hwpoisoned folio Andrew Morton
2026-07-06  9:03   ` David Hildenbrand (Arm)
2026-07-25  3:06   ` Jiaqi Yan
     [not found] ` <85cb7ea8-8116-4092-8310-69b61eb8602c@kernel.org>
     [not found]   ` <ee6bcc74-0846-43f2-bcca-b1bedff74351@oracle.com>
2026-07-22  8:27     ` Vlastimil Babka (SUSE)
2026-07-22  9:03       ` Vlastimil Babka (SUSE)
2026-07-25  6:00         ` Jiaqi Yan
2026-07-25  6:52       ` Jiaqi Yan
2026-07-27 14:20       ` David Hildenbrand (Arm)
2026-07-27 18:20         ` Matthew Wilcox
2026-07-28 17:18         ` Vlastimil Babka (SUSE)
2026-08-04 19:51           ` David Hildenbrand (Arm)
2026-08-05  8:58             ` Vlastimil Babka (SUSE)
2026-08-05  9:09               ` David Hildenbrand (Arm) [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=352e1f42-2e89-4445-a20e-572ee35c7a0c@kernel.org \
    --to=david@kernel.org \
    --cc=akpm@linux-foundation.org \
    --cc=boudewijn@delta-utec.com \
    --cc=duenwen@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=harry.yoo@oracle.com \
    --cc=jackmanb@google.com \
    --cc=jane.chu@oracle.com \
    --cc=jiaqiyan@google.com \
    --cc=jthoughton@google.com \
    --cc=liam@infradead.org \
    --cc=linmiaohe@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=ljs@kernel.org \
    --cc=mhocko@suse.com \
    --cc=muchun.song@linux.dev \
    --cc=nao.horiguchi@gmail.com \
    --cc=osalvador@kernel.org \
    --cc=osalvador@suse.de \
    --cc=rientjes@google.com \
    --cc=rppt@kernel.org \
    --cc=shuah@kernel.org \
    --cc=surenb@google.com \
    --cc=tony.luck@intel.com \
    --cc=vbabka@kernel.org \
    --cc=wangkefeng.wang@huawei.com \
    --cc=william.roche@oracle.com \
    --cc=willy@infradead.org \
    --cc=ziy@nvidia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox