get_hwpoison_page(9)

๐Ÿ“ฆ version 7.3.1, in nixpkgs unstable

๐Ÿ’… get_hwpoison_page โ€” the Kernel API Manual girlie edition

okay so bestie, welcome to get_hwpoison_page(9) โ€” the function whose whole personality is "gimme a refcount on this busted page so we can deal with the memory error". come sit with me, this one's a bop ๐Ÿซถ


โœจ NAME โœจ

get_hwpoison_page โ€” Get refcount for memory error handling ๐Ÿ’–


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

int get_hwpoison_page (struct page *p , unsigned long flags );

that's it. that's the whole mood. look at her go ๐Ÿฆ‹


๐ŸŒธ ARGUMENTS ๐ŸŒธ

  • p โ€” the raw error page, aka the one that got hit by the memory error. this is our main character, our problem child, our literal blorbo ๐Ÿ˜ญ
  • flags โ€” flags that control the behavior of error handling. the vibes-configurator, if you will โœจ

๐Ÿงš DESCRIPTION ๐Ÿงš

so what does get_hwpoison_page actually do? it takes a page refcount of an error page so we can handle the memory error on it โ€” but like, not before checking that the error page is in a well-defined state. and "well-defined state" here means a page-type we can actually successfully handle the memory error on, like an LRU page or a hugetlb page. no cap, that's the whole gatekeep ๐Ÿ’…

here's the tea though: memory error handling can be triggered at any time on any type of page, so it's lowkey prone to racing with the typical memory management lifecycle (you know, allocation and free, the usual suspects). ๐Ÿ™ˆ

so to avoid those races, get_hwpoison_page takes extra care for the error page's state (as done in __get_hwpoison_page), and has some retry logic in get_any_page. she's thorough. she's careful. she ate and left no crumbs ๐Ÿ”ฅ

and one more thing, bestie โ€” when called from unpoison_memory, the caller should already ensure that the given page has PG_hwpoison. which means it's never reused for other page allocations, and __get_unpoison_page never races with them. iconic behavior, honestly ๐Ÿ‘‘


โญ RETURN โญ

the return values, ranked with love:

  • 0 โ€” on failure, or a free buddy (hugetlb) page ๐Ÿ’€
  • 1 โ€” on success for in-use pages in a well-defined state ๐ŸŽ‰
  • -EIO โ€” for pages on which we can not handle memory errors ๐Ÿšซ
  • -EBUSY โ€” when get_hwpoison_page has raced with page lifecycle operations like allocation and free ๐Ÿƒโ€โ™€๏ธ๐Ÿ’จ
  • -EHWPOISON โ€” when the page is hwpoisoned and taken off from buddy ๐Ÿ˜ต
  • -ENOTRECOVERABLE โ€” for kernel-owned pages identified by is_kernel_owned_page (PG_reserved, slab, page-table, large-kmalloc) that the handler cannot recover. yeah. that's a no from her ๐Ÿ™…โ€โ™€๏ธ

๐Ÿ”ฎ SEE ALSO ๐Ÿ”ฎ

go read these next, bestie, they're all in the same friend group:


fr fr, this page is dangerous-adjacent territory โ€” it's out here racing with allocation and free, so keep those retry vibes and refcounts in mind. ๐Ÿซง

alright bestie, that's the whole page โ€” source is the ./mm directory, this is the Kernel API Manual, and the date on it is October 2026. go slay your memory errors, mwah ๐Ÿ’‹โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from