mm/hugetlb: change ENOSPC to ENOMEM in alloc_hugetlb_folio
Subsystems (3)
PATCH 1/1 mm/hugetlb: change ENOSPC to ENOMEM in alloc_hugetlb_folio
The error ENOSPC is translated in vmf_error to VM_FAULT_SIGBUS which is further translated in EFAULT in i.e. pin/get_user_pages.
But when running out of pages/hugepages we expect to see ENOMEM and not EFAULT.
--- mm/hugetlb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
mm/hugetlb.c +1 -1
@@ -3113,7 +3113,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,if (!memcg_charge_ret)mem_cgroup_cancel_charge (memcg, nr_pages);mem_cgroup_put (memcg); -return ERR_PTR (-ENOSPC ); +return ERR_PTR (-ENOMEM ); }int alloc_bootmem_huge_page (struct hstate *h,int nid)
Signature · 1 line
2.34.1
Andrew Morton
maintainerQuoted 10 lines · On Sun, 1 Dec 2024 03:03:41 +0200 Dafna Hirschfeld…
The error ENOSPC is translated in
vmf_errortoVM_FAULT_SIGBUSwhich is further translated in EFAULT in i.e. pin/get_user_pages.
But when running out of pages/hugepages we expect to see ENOMEM and not EFAULT....
mm/hugetlb.c struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma, · line 3119
Quoted 8 lines
mm/hugetlb.c +1
-1@@ -3113,7 +3113,7 @@ struct folio *alloc_hugetlb_folio(struct vm_area_struct *vma,if (!memcg_charge_ret)mem_cgroup_cancel_charge (memcg, nr_pages);mem_cgroup_put (memcg); -return ERR_PTR (-ENOSPC ); +return ERR_PTR (-ENOMEM ); }int alloc_bootmem_huge_page (struct hstate *h,int nid)
err, yes. ENOSPC is for disk drives! I'll slap a cc:stable on this fix for a decade old bug.
Alexander Gordeev
maintainerOn Sat, Nov 30, 2024 at 06:51:21PM -0800, Andrew Morton wrote:
Hi Andrew,
...
Quoted 2 lines
Quoted 2 lines
mm/hugetlb.c +1
-1-return ERR_PTR (-ENOSPC ); +return ERR_PTR (-ENOMEM );
...
Quoted 2 lines
err, yes. ENOSPC is for disk drives! I'll slap a cc:stable on this fix for a decade old bug.
This fix invalidates the comment in hugetlb_no_page():
/* * Returning error will result in faulting task being * sent SIGBUS. The hugetlb fault mutex prevents two ... */
The problem is an attempt to write to a MAP_NORESERVE huge page (as per [1]) causes an infinite page fault cycle instead of SIGBUS, at least on s390:
q = mmap(NULL, hpage_size, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_NORESERVE, fd2, 0); ... test_write(q);
1. https://github.com/libhugetlbfs/libhugetlbfs/blob/master/tests/noresv-preserve-resv-page.c
Thanks!
Quoted 4 lines · Dafna Hirschfeld
The error ENOSPC is translated in
vmf_errortoVM_FAULT_SIGBUSwhich is further translated in EFAULT in i.e. pin/get_user_pages.
But when running out of pages/hugepages we expect to see ENOMEM and not EFAULT.
Do we? ENOSPC is for media full, and since memory is the medium, ENOSPC seems entirely appropriate to me. It's been this way since 2008, so any change should be done with due care and attention to what else we might break.
Muchun Song
maintainerQuoted 8 lines · Dafna Hirschfeld
The error ENOSPC is translated in
vmf_errortoVM_FAULT_SIGBUSwhich is further translated in EFAULT in i.e. pin/get_user_pages.
But when running out of pages/hugepages we expect to see ENOMEM and not EFAULT.
Hi Dafna,
Refers to Documentation/mm/hugetlbfs_reserv.rst. I saw:
If no huge page exists at page fault time, the task is sent a **SIGBUS** and often dies an unhappy death.
Seems SIGBUS is expected since it is introduced.
Thanks.
Quoted 9 lines · Muchun Song
Quoted 8 lines · Dafna Hirschfeld
The error ENOSPC is translated in
vmf_errortoVM_FAULT_SIGBUSwhich is further translated in EFAULT in i.e. pin/get_user_pages.
But when running out of pages/hugepages we expect to see ENOMEM and not EFAULT.
Quoted 8 lines
Hi Dafna,
Refers to
Documentation/mm/hugetlbfs_reserv.rst. I saw:If no huge page exists at page fault time, the task is sent a **SIGBUS** and often dies an unhappy death.
Seems SIGBUS is expected since it is introduced.
Ok, but for functions such as pin/get_user_pages, it is translated to EFAULT, which is not clear if this is what we want.
Quoted 2 lines
Thanks.
Quoted 9 lines · Muchun Song
Quoted 8 lines · Dafna Hirschfeld
The error ENOSPC is translated in
vmf_errortoVM_FAULT_SIGBUSwhich is further translated in EFAULT in i.e. pin/get_user_pages.
But when running out of pages/hugepages we expect to see ENOMEM and not EFAULT.
Quoted 8 lines
Hi Dafna,
Refers to
Documentation/mm/hugetlbfs_reserv.rst. I saw:If no huge page exists at page fault time, the task is sent a **SIGBUS** and often dies an unhappy death.
Seems SIGBUS is expected since it is introduced.
Hi, thanks for pointing this out, the question is wheather EFAULT is the expected return code from pin/get_user_pages* funcs in such case. Dafna
Quoted 2 lines
Thanks.
Quoted 9 lines · Muchun Song
Quoted 8 lines · Dafna Hirschfeld
The error ENOSPC is translated in
vmf_errortoVM_FAULT_SIGBUSwhich is further translated in EFAULT in i.e. pin/get_user_pages.
But when running out of pages/hugepages we expect to see ENOMEM and not EFAULT.
Quoted 8 lines
Hi Dafna,
Refers to
Documentation/mm/hugetlbfs_reserv.rst. I saw:If no huge page exists at page fault time, the task is sent a **SIGBUS** and often dies an unhappy death.
Seems SIGBUS is expected since it is introduced.
Hi,
I see that mlock do return ENOMEM when out of hugepages.
It has the function "__mlock_posix_error_return" that converts EFAULT returned from "get_user_pages" to ENOMEM.
So callers to "get_user_pages" can override EFAULT with ENOMEM but then it obscure cases where EFUALT should really be the return code.
thanks,
Dafna
Quoted 2 lines
Thanks.