memory_failure(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– memory_failure(9) πŸ’–

ok so you're reading the Kernel API Manual bestie, and this is the page for memory_failure(9) β€” literally the function that handles a memory failure of a page. yes THAT kind of failure. the hardware kind. buckle up πŸŽ€


✨ NAME ✨

memory_failure β€” Handle memory failure of a page. that's it, that's the whole vibe. when a page goes bad, this is the girl they call πŸ’…


✨ SYNOPSIS ✨

int memory_failure (unsigned long pfn , int flags );

like, it takes two things and returns an int. concise. iconic. no notes πŸ‘‘


✨ ARGUMENTS ✨

  • pfn β€” Page Number of the corrupted page. that's the address of the page that's gone bad 😭 the one having a whole crisis.
  • flags β€” fine tune action taken. itty bitty knobs to nudge how it behaves, iykyk πŸŽ›οΈ

✨ DESCRIPTION ✨

okay so picture this 🫢 β€” the low level machine check code of an architecture notices that hardware memory corruption happened on a page. and then it calls this function. and memory_failure tries its best to recover, which β€” ngl β€” includes dropping pages, killing processes etc. like, it's doing the absolute most to save the day, and sometimes the day gets saved by literally ending a process πŸ’€ no cap.

this function is primarily of use for corruptions that happen outside the current execution context β€” for example when a background scrubber detects it 🧹✨ (scrubber said "not on my watch").

🚨 IMPORTANT VIBE CHECK: this must run in process context (e.g. a work queue) with interrupts enabled and no spinlocks held. do not try this from a spinlock bestie, it will not slay, it will not go well πŸ™ˆ

✨ RETURN ✨

so the return values are giving a whole spectrum, let's go through them one by one:

  • 0 β€” success πŸŽ‰ periodt.
  • -ENXIO β€” memory not managed by the kernel. not our page, not our problem πŸ«₯
  • -EOPNOTSUPP β€” hwpoison_filter filtered the error event. the bouncer said no βœ‹
  • -EHWPOISON β€” the page was already poisoned, potentially kill process. she's already been through it 😭 maybe someone's getting killed over it, lowkey.
  • other negative values β€” failure. yeah. just... failure. πŸ’€

✨ SEE ALSO ✨

go read these next, fr fr, they're the rest of the friend group πŸ‘―β€β™€οΈ:


okay that's the whole page!! this came from ./mm and it's dated October 2026 🌸 so yeah, that's the source, that's the version, that's the date β€” mwah, go forth and handle those failures bestie πŸ¦‹βœ¨πŸ’–

πŸ“¦ where this page comes from