mm/hugetlb: fix memory offline failure due to hwpoisoned file hugetlb
Subsystems (2)
PATCH v2 1/1 mm/hugetlb: fix memory offline failure due to hwpoisoned file hugetlb
When a file hugetlb folio triggers UCE, me_huge_page() will keep the hugetlb folio in pagcahe with refcount increased and PG_hwpoison set. Even after the hugetlb file is deleted, the hugetlb folio is still leaked.
If we want to offline the memory block that the hwpoisoned hugetlb folio belongs to, it fails in dissolve_free_hugetlb_folios() due to the hwpoisoned hugetlb folio isn't free.
I can reproduce this issue with the following steps in qemu:
1) echo offline >/sys/devices/system/memory/auto_online_blocks
2) in qemu monitor:
object_add memory-backend-ram,id=mem10,size=1G
device_add pc-dimm,id=dimm1,memdev=mem10,node=2 3) echo online_movable > /sys/devices/system/node/node2/memory136/state
4) echo 5 > /sys/devices/system/node/node2/hugepages/hugepages-2048kB/nr_hugepages
5) run ./hugetlb_file. This process will receive SIGBUS.
6) remove the hugetlbfs file.
7) echo offline > /sys/devices/system/node/node2/memory136/state
hugetlb_file.c:
fd = open("/dev/hugepages/my_hugepage_file", O_CREAT | O_RDWR, 0755); fallocate(fd, 0, 0, HUGEPAGE_SIZE * 2);
addr = mmap(NULL, HUGEPAGE_SIZE * 2, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_HUGETLB, fd, 0);
memset(addr, 0xaa, HUGEPAGE_SIZE * 2);
madvise(addr, HUGEPAGE_SIZE, MADV_HWPOISON);
To fix it, force to put ref of hwpoisoned hugetlb in memory offline, the hwpoisoned hugetlb will be freed and succeeds to be dissolved. We couldn't avoid races here, just like commit b023f46813cd ("memory-hotplug: skip HWPoisoned page when offlining pages"), which force to skip hwpoisoned page regardless of refcount.
--- mm/hugetlb.c | 9 +++++++++ 1 file changed, 9 insertions(+)
mm/hugetlb.c +9 -0
@@ -2115,6 +2115,15 @@ int dissolve_free_hugetlb_folios(unsigned long start_pfn, unsigned long end_pfn)for (pfn = start_pfn; pfn < end_pfn; pfn +=1 << order) { folio =pfn_folio (pfn); + +/* +* For hwpoisoned hugetlb, put the refcount increaed by +* memory-failure, make it succeed to dissolve. +*/ +if (unlikely (folio_test_hwpoison (folio) &&folio_test_hugetlb (folio) + &&folio_ref_count (folio))) +folio_put (folio); + rc =dissolve_free_hugetlb_folio (folio);if (rc)break ;
Signature · 1 line
2.43.0
Andrew Morton
maintainerQuoted 24 lines · On Sat, 21 Mar 2026 10:10:31 +0800 Jinjiang Tu <[email protected]> wrote:
When a file hugetlb folio triggers UCE,
me_huge_page()will keep the hugetlb folio in pagcahe with refcount increased andPG_hwpoisonset. Even after the hugetlb file is deleted, the hugetlb folio is still leaked.If we want to offline the memory block that the hwpoisoned hugetlb folio belongs to, it fails in
dissolve_free_hugetlb_folios()due to the hwpoisoned hugetlb folio isn't free.I can reproduce this issue with the following steps in qemu:
1) echo offline >/sys/devices/system/memory/auto_online_blocks
2) in qemu monitor:object_add memory-backend-ram,id=mem10,size=1G device_add pc-dimm,id=dimm1,memdev=mem10,node=23) echo
online_movable>/sys/devices/system/node/node2/memory136/state
4) echo 5 >/sys/devices/system/node/node2/hugepages/hugepages-2048kB/nr_hugepages
5) run ./hugetlb_file. This process will receive SIGBUS.
6) remove the hugetlbfs file.
7) echo offline >/sys/devices/system/node/node2/memory136/state
hugetlb_file.c:
fd =open("/dev/hugepages/my_hugepage_file", O_CREAT | O_RDWR, 0755);fallocate(fd, 0, 0, HUGEPAGE_SIZE * 2);
addr = mmap(NULL,HUGEPAGE_SIZE* 2,PROT_READ|PROT_WRITE,MAP_SHARED | MAP_HUGETLB, fd, 0);
Quoted 9 lines
memset(addr, 0xaa, HUGEPAGE_SIZE * 2);
madvise(addr, HUGEPAGE_SIZE, MADV_HWPOISON);To fix it, force to put ref of hwpoisoned hugetlb in memory offline, the hwpoisoned hugetlb will be freed and succeeds to be dissolved. We couldn't avoid races here, just like commit
b023f46813cd("memory-hotplug: skip HWPoisoned page when offlining pages"), which force to skip hwpoisoned page regardless of refcount.
It would be nice to know what changed since v1 and why, although the patch is super-tiny so I guess that doesn't matter much.
AI review has a question regarding the v1 patch:
https://sashiko.dev/#/patchset/[email protected]
David Hildenbrand (Arm)
reviewerQuoted 24 lines · Jinjiang Tu
When a file hugetlb folio triggers UCE,
me_huge_page()will keep the hugetlb folio in pagcahe with refcount increased andPG_hwpoisonset. Even after the hugetlb file is deleted, the hugetlb folio is still leaked.If we want to offline the memory block that the hwpoisoned hugetlb folio belongs to, it fails in
dissolve_free_hugetlb_folios()due to the hwpoisoned hugetlb folio isn't free.I can reproduce this issue with the following steps in qemu:
1) echo offline >/sys/devices/system/memory/auto_online_blocks
2) in qemu monitor:object_add memory-backend-ram,id=mem10,size=1G device_add pc-dimm,id=dimm1,memdev=mem10,node=23) echo
online_movable>/sys/devices/system/node/node2/memory136/state
4) echo 5 >/sys/devices/system/node/node2/hugepages/hugepages-2048kB/nr_hugepages
5) run ./hugetlb_file. This process will receive SIGBUS.
6) remove the hugetlbfs file.
7) echo offline >/sys/devices/system/node/node2/memory136/state
hugetlb_file.c:
fd =open("/dev/hugepages/my_hugepage_file", O_CREAT | O_RDWR, 0755);fallocate(fd, 0, 0, HUGEPAGE_SIZE * 2);
addr = mmap(NULL,HUGEPAGE_SIZE* 2,PROT_READ|PROT_WRITE,MAP_SHARED | MAP_HUGETLB, fd, 0);
Quoted 8 lines
memset(addr, 0xaa, HUGEPAGE_SIZE * 2);
madvise(addr, HUGEPAGE_SIZE, MADV_HWPOISON);To fix it, force to put ref of hwpoisoned hugetlb in memory offline, the hwpoisoned hugetlb will be freed and succeeds to be dissolved. We couldn't avoid races here, just like commit
b023f46813cd("memory-hotplug: skip HWPoisoned page when offlining pages"), which force to skip hwpoisoned page regardless of refcount.
I always considered that handling quite dubious. Just because a page has hwpoisoned set doesn't mean that we can just offline it.
I think that mus be cleaned up at some point.
But not sure how to do this cleanly.
Why do we even care about offlining memory with hwpoisoned pages? What is the use case for your change?
I know, it's very desirable to do it, but I much rather have it not working then having something that is likely mostly broken and actually might cause harm.
Signature · 3 lines
Cheers, David
Quoted 36 lines · David Hildenbrand (Arm)
Quoted 27 lines · Jinjiang Tu
When a file hugetlb folio triggers UCE,
me_huge_page()will keep the hugetlb folio in pagcahe with refcount increased andPG_hwpoisonset. Even after the hugetlb file is deleted, the hugetlb folio is still leaked.If we want to offline the memory block that the hwpoisoned hugetlb folio belongs to, it fails in
dissolve_free_hugetlb_folios()due to the hwpoisoned hugetlb folio isn't free.I can reproduce this issue with the following steps in qemu:
1) echo offline >/sys/devices/system/memory/auto_online_blocks
2) in qemu monitor:object_add memory-backend-ram,id=mem10,size=1G device_add pc-dimm,id=dimm1,memdev=mem10,node=23) echo
online_movable>/sys/devices/system/node/node2/memory136/state
4) echo 5 >/sys/devices/system/node/node2/hugepages/hugepages-2048kB/nr_hugepages
5) run ./hugetlb_file. This process will receive SIGBUS.
6) remove the hugetlbfs file.
7) echo offline >/sys/devices/system/node/node2/memory136/state
hugetlb_file.c:fd = open("/dev/hugepages/my_hugepage_file", O_CREAT | O_RDWR, 0755); fallocate(fd, 0, 0, HUGEPAGE_SIZE * 2); addr = mmap(NULL, HUGEPAGE_SIZE * 2, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_HUGETLB, fd, 0); memset(addr, 0xaa, HUGEPAGE_SIZE * 2); madvise(addr, HUGEPAGE_SIZE, MADV_HWPOISON);Quoted 5 lines
To fix it, force to put ref of hwpoisoned hugetlb in memory offline, the hwpoisoned hugetlb will be freed and succeeds to be dissolved. We couldn't avoid races here, just like commit
b023f46813cd("memory-hotplug: skip HWPoisoned page when offlining pages"), which force to skip hwpoisoned page regardless of refcount.I always considered that handling quite dubious. Just because a page has hwpoisoned set doesn't mean that we can just offline it.
Quoted 6 lines
I think that mus be cleaned up at some point.
But not sure how to do this cleanly.
Why do we even care about offlining memory with hwpoisoned pages? What is the use case for your change?
Considering CXL memory device and we hotplug the memory as NUMA. If the device is disconnected, accessing the CXL memory will trigger memory-failure.
We still want to offline the memory, so that we can reonline and use the memory again when CXL memory device is reconnected.
Quoted 4 lines
I know, it's very desirable to do it, but I much rather have it not working then having something that is likely mostly broken and actually might cause harm.
David Hildenbrand (Arm)
reviewerQuoted 49 lines · Jinjiang Tu
Quoted 40 lines · David Hildenbrand (Arm)
Quoted 30 lines · Jinjiang Tu
When a file hugetlb folio triggers UCE,
me_huge_page()will keep the hugetlb folio in pagcahe with refcount increased andPG_hwpoisonset. Even
after the hugetlb file is deleted, the hugetlb folio is still leaked.If we want to offline the memory block that the hwpoisoned hugetlb folio belongs to, it fails in
dissolve_free_hugetlb_folios()due to the hwpoisoned hugetlb folio isn't free.I can reproduce this issue with the following steps in qemu:
1) echo offline >/sys/devices/system/memory/auto_online_blocks
2) in qemu monitor:
object_addmemory-backend-ram,id=mem10,size=1Gdevice_addpc-dimm,id=dimm1,memdev=mem10,node=2
3) echoonline_movable>/sys/devices/system/node/node2/memory136/state
4) echo 5 >/sys/devices/system/node/node2/hugepages/hugepages-2048kB/nr_hugepages
5) run ./hugetlb_file. This process will receive SIGBUS.
6) remove the hugetlbfs file.
7) echo offline >/sys/devices/system/node/node2/memory136/state
hugetlb_file.c:
fd =open("/dev/hugepages/my_hugepage_file", O_CREAT | O_RDWR, 0755);fallocate(fd, 0, 0, HUGEPAGE_SIZE * 2);
addr =mmap(NULL, HUGEPAGE_SIZE * 2, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_HUGETLB, fd, 0);
memset(addr, 0xaa, HUGEPAGE_SIZE * 2);
madvise(addr, HUGEPAGE_SIZE, MADV_HWPOISON);Quoted 6 lines
To fix it, force to put ref of hwpoisoned hugetlb in memory offline, the hwpoisoned hugetlb will be freed and succeeds to be dissolved. We couldn't
avoid races here, just like commitb023f46813cd("memory-hotplug: skip HWPoisoned page when offlining pages"), which force to skip hwpoisoned page regardless of refcount.I always considered that handling quite dubious. Just because a page has hwpoisoned set doesn't mean that we can just offline it.
Quoted 6 lines
I think that mus be cleaned up at some point.
But not sure how to do this cleanly.
Why do we even care about offlining memory with hwpoisoned pages? What is the use case for your change?
Quoted 6 lines
Considering CXL memory device and we hotplug the memory as NUMA. If the device is disconnected, accessing the CXL memory will trigger memory- failure.
We still want to offline the memory, so that we can reonline and use the memory again when CXL memory device is reconnected.
Disconnecting a CXL device while the memory is still exposed to Linux, and using memory-faults for protecting from that?
Oh my, that is horrible!
That's not what memory-failure handling is supposed to be used for. It's supposed to be used for, you know "memory failure", not disconnected devices :)
Signature · 3 lines
Cheers, David
Andrew Morton
maintainerQuoted 24 lines · On Sat, 21 Mar 2026 10:10:31 +0800 Jinjiang Tu <[email protected]> wrote:
When a file hugetlb folio triggers UCE,
me_huge_page()will keep the hugetlb folio in pagcahe with refcount increased andPG_hwpoisonset. Even after the hugetlb file is deleted, the hugetlb folio is still leaked.If we want to offline the memory block that the hwpoisoned hugetlb folio belongs to, it fails in
dissolve_free_hugetlb_folios()due to the hwpoisoned hugetlb folio isn't free.I can reproduce this issue with the following steps in qemu:
1) echo offline >/sys/devices/system/memory/auto_online_blocks
2) in qemu monitor:object_add memory-backend-ram,id=mem10,size=1G device_add pc-dimm,id=dimm1,memdev=mem10,node=23) echo
online_movable>/sys/devices/system/node/node2/memory136/state
4) echo 5 >/sys/devices/system/node/node2/hugepages/hugepages-2048kB/nr_hugepages
5) run ./hugetlb_file. This process will receive SIGBUS.
6) remove the hugetlbfs file.
7) echo offline >/sys/devices/system/node/node2/memory136/state
hugetlb_file.c:
fd =open("/dev/hugepages/my_hugepage_file", O_CREAT | O_RDWR, 0755);fallocate(fd, 0, 0, HUGEPAGE_SIZE * 2);
addr = mmap(NULL,HUGEPAGE_SIZE* 2,PROT_READ|PROT_WRITE,MAP_SHARED | MAP_HUGETLB, fd, 0);
Quoted 8 lines
memset(addr, 0xaa, HUGEPAGE_SIZE * 2);
madvise(addr, HUGEPAGE_SIZE, MADV_HWPOISON);To fix it, force to put ref of hwpoisoned hugetlb in memory offline, the hwpoisoned hugetlb will be freed and succeeds to be dissolved. We couldn't avoid races here, just like commit
b023f46813cd("memory-hotplug: skip HWPoisoned page when offlining pages"), which force to skip hwpoisoned page regardless of refcount.
Well, David sounds skeptical, although discussion petered out a week ago. We haven't heard from Miahoe or Muchun and the AI review might be seeing some issues
(https://sashiko.dev/#/patchset/[email protected]).
So I'll drop this one.
Please feel free to resend after -rc1 if you feel this is a desirable change. When doing so, please review the concerns which have been raised thus far and attempt to address those within the updated changelog.
Thanks.