* [PATCH] mm: skip temporary folio allocation for anonymous UFFD missing faults @ 2026-11-19 18:00 Avi Weiss 2026-11-19 18:22 ` Lorenzo Stoakes (ARM) 0 siblings, 1 reply; 7+ messages in thread From: Avi Weiss @ 2026-11-19 18:00 UTC (permalink / raw) To: david; +Cc: akpm, ljs, rppt, peterx, linux-mm, linux-kernel, Avi Weiss An anonymous write fault on a VMA registered for missing userfaultfd faults currently allocates, zeroes and memcg-charges a folio before checking the PTE and handing the fault to userspace. The folio is then immediately discarded without ever being mapped. Check the PTE and address-space stability under the PTE lock before allocating a folio when missing faults are registered. Deliver the fault to userfaultfd without allocating and discarding a temporary folio. In a four-boot native B/P/B/P comparison, the mean UFFD fault median fell from 13,997.75 ns to 13,093.55 ns (-904.2 ns, -6.46%). A guest allocation trace saw 256 fewer allocations in the faulting task for 256 registered missing faults. Note: this changes OOM ordering. In a fixed 18 MiB memcg test, the baseline OOM-killed only the faulting client before delivering a UFFD event. With this change, the event reached an unprotected shared handler, and its UFFDIO_COPY allocation could trigger an additional OOM kill of the handler. A separate surviving client consequently lost its handler and failed a page-content check after the UFFD registration was released. The same handler-death mechanism was reproducible on the unmodified (mainline) kernel when memory pressure was imposed after event delivery but before UFFDIO_COPY, although the fixed-limit outcomes differed. Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> --- mm/memory.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 0fb676d..63b39fa 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -5547,6 +5547,22 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) ret = vmf_anon_prepare(vmf); if (ret) return ret; + + if (unlikely(userfaultfd_missing(vma))) { + vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, + vmf->address, &vmf->ptl); + if (!vmf->pte) + goto unlock; + if (vmf_pte_changed(vmf)) { + update_mmu_tlb(vma, vmf->address, vmf->pte); + goto unlock; + } + ret = check_stable_address_space(vma->vm_mm); + if (ret) + goto unlock; + pte_unmap_unlock(vmf->pte, vmf->ptl); + return handle_userfault(vmf, VM_UFFD_MISSING); + } /* Returns NULL on OOM or ERR_PTR(-EAGAIN) if we must retry the fault */ folio = alloc_anon_folio(vmf); if (IS_ERR(folio)) @@ -5579,12 +5595,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) if (ret) goto release; - /* Deliver the page fault to userland, check inside PT lock */ - if (userfaultfd_missing(vma)) { - pte_unmap_unlock(vmf->pte, vmf->ptl); - folio_put(folio); - return handle_userfault(vmf, VM_UFFD_MISSING); - } map_anon_folio_pte_pf(folio, vmf->pte, vma, addr, vmf_orig_pte_uffd_wp(vmf)); unlock: -- 2.43.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] mm: skip temporary folio allocation for anonymous UFFD missing faults 2026-11-19 18:00 [PATCH] mm: skip temporary folio allocation for anonymous UFFD missing faults Avi Weiss @ 2026-11-19 18:22 ` Lorenzo Stoakes (ARM) 2026-11-19 19:31 ` Avi 0 siblings, 1 reply; 7+ messages in thread From: Lorenzo Stoakes (ARM) @ 2026-11-19 18:22 UTC (permalink / raw) To: Avi Weiss Cc: david, akpm, rppt, peterx, linux-mm, linux-kernel, liam, mhocko, surenb, vbabka +cc missing. Please just stop. You sent 7 series across 6 different subsystems over 11 hours. You(r AI) even failed to cc the right people (added). On Thu, Nov 19, 2026 at 08:00:15PM +0200, Avi Weiss wrote: > An anonymous write fault on a VMA registered for missing userfaultfd > faults currently allocates, zeroes and memcg-charges a folio before > checking the PTE and handing the fault to userspace. The folio is then > immediately discarded without ever being mapped. > > Check the PTE and address-space stability under the PTE lock before > allocating a folio when missing faults are registered. Deliver the fault > to userfaultfd without allocating and discarding a temporary folio. > > In a four-boot native B/P/B/P comparison, the mean UFFD fault median > fell from 13,997.75 ns to 13,093.55 ns (-904.2 ns, -6.46%). A guest > allocation trace saw 256 fewer allocations in the faulting task for > 256 registered missing faults. A .9us delta on a _uffd_ fault (nobody in their right mind puts it on a hot path) with no standard deviation? Seriously? > > Note: this changes OOM ordering. In a fixed 18 MiB memcg test, the > baseline OOM-killed only the faulting client before delivering a UFFD > event. With this change, the event reached an unprotected shared handler, > and its UFFDIO_COPY allocation could trigger an additional OOM kill of the > handler. A separate surviving client consequently lost its handler and > failed a page-content check after the UFFD registration was released. > The same handler-death mechanism was reproducible on the unmodified > (mainline) kernel when memory pressure was imposed after event delivery > but before UFFDIO_COPY, although the fixed-limit outcomes differed. This is both unreadable word salad and alludes to you causing possibly breaking changes for a barely-distinguishable-from-noise fault time improvement. > > Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> Please stop submitting patches, thanks. "You are expected to understand and to be able to defend everything you submit. If you are unable to do so, then do not submit the resulting changes." https://docs.kernel.org/process/generated-content.html > --- > mm/memory.c | 22 ++++++++++++++++------ > 1 file changed, 16 insertions(+), 6 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index 0fb676d..63b39fa 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -5547,6 +5547,22 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > ret = vmf_anon_prepare(vmf); > if (ret) > return ret; > + > + if (unlikely(userfaultfd_missing(vma))) { > + vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, > + vmf->address, &vmf->ptl); > + if (!vmf->pte) > + goto unlock; > + if (vmf_pte_changed(vmf)) { > + update_mmu_tlb(vma, vmf->address, vmf->pte); > + goto unlock; > + } > + ret = check_stable_address_space(vma->vm_mm); > + if (ret) > + goto unlock; > + pte_unmap_unlock(vmf->pte, vmf->ptl); > + return handle_userfault(vmf, VM_UFFD_MISSING); > + } > /* Returns NULL on OOM or ERR_PTR(-EAGAIN) if we must retry the fault */ > folio = alloc_anon_folio(vmf); > if (IS_ERR(folio)) > @@ -5579,12 +5595,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > if (ret) > goto release; > > - /* Deliver the page fault to userland, check inside PT lock */ > - if (userfaultfd_missing(vma)) { > - pte_unmap_unlock(vmf->pte, vmf->ptl); > - folio_put(folio); > - return handle_userfault(vmf, VM_UFFD_MISSING); > - } > map_anon_folio_pte_pf(folio, vmf->pte, vma, addr, > vmf_orig_pte_uffd_wp(vmf)); > unlock: > -- > 2.43.0 > -- Cheers, Lorenzo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm: skip temporary folio allocation for anonymous UFFD missing faults 2026-11-19 18:22 ` Lorenzo Stoakes (ARM) @ 2026-11-19 19:31 ` Avi 2026-11-19 22:34 ` David Hildenbrand (Arm) 0 siblings, 1 reply; 7+ messages in thread From: Avi @ 2026-11-19 19:31 UTC (permalink / raw) To: Lorenzo Stoakes (ARM) Cc: david, akpm, rppt, peterx, linux-mm, linux-kernel, liam, mhocko, surenb, vbabka Hi Lorenzo - I don't think you are in charge of all of Linux and can decide who can and cannot submit contributions. This is a legitimate improvement in my opinion - if you disagree that's fine. The 'word salad' you describe is my best attempt at describing an issue that this patch potentially makes worse, but is nevertheless preexisting. Regarding cc'ing the right people - you're right, it's very hard to always know who to CC and who to not include - it's easy to make mistakes with that. Good Luck On Thu, Nov 19, 2026 at 8:22 PM Lorenzo Stoakes (ARM) <ljs@kernel.org> wrote: > > +cc missing. > > Please just stop. You sent 7 series across 6 different subsystems over 11 > hours. You(r AI) even failed to cc the right people (added). > > On Thu, Nov 19, 2026 at 08:00:15PM +0200, Avi Weiss wrote: > > An anonymous write fault on a VMA registered for missing userfaultfd > > faults currently allocates, zeroes and memcg-charges a folio before > > checking the PTE and handing the fault to userspace. The folio is then > > immediately discarded without ever being mapped. > > > > Check the PTE and address-space stability under the PTE lock before > > allocating a folio when missing faults are registered. Deliver the fault > > to userfaultfd without allocating and discarding a temporary folio. > > > > In a four-boot native B/P/B/P comparison, the mean UFFD fault median > > fell from 13,997.75 ns to 13,093.55 ns (-904.2 ns, -6.46%). A guest > > allocation trace saw 256 fewer allocations in the faulting task for > > 256 registered missing faults. > > A .9us delta on a _uffd_ fault (nobody in their right mind puts it on a hot > path) with no standard deviation? Seriously? > > > > > Note: this changes OOM ordering. In a fixed 18 MiB memcg test, the > > baseline OOM-killed only the faulting client before delivering a UFFD > > event. With this change, the event reached an unprotected shared handler, > > and its UFFDIO_COPY allocation could trigger an additional OOM kill of the > > handler. A separate surviving client consequently lost its handler and > > failed a page-content check after the UFFD registration was released. > > The same handler-death mechanism was reproducible on the unmodified > > (mainline) kernel when memory pressure was imposed after event delivery > > but before UFFDIO_COPY, although the fixed-limit outcomes differed. > > This is both unreadable word salad and alludes to you causing possibly > breaking changes for a barely-distinguishable-from-noise fault time > improvement. > > > > > Signed-off-by: Avi Weiss <thnkslprpt@gmail.com> > > Please stop submitting patches, thanks. > > "You are expected to understand and to be able to defend everything you > submit. If you are unable to do so, then do not submit the resulting > changes." > > https://docs.kernel.org/process/generated-content.html > > > --- > > mm/memory.c | 22 ++++++++++++++++------ > > 1 file changed, 16 insertions(+), 6 deletions(-) > > > > diff --git a/mm/memory.c b/mm/memory.c > > index 0fb676d..63b39fa 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -5547,6 +5547,22 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > > ret = vmf_anon_prepare(vmf); > > if (ret) > > return ret; > > + > > + if (unlikely(userfaultfd_missing(vma))) { > > + vmf->pte = pte_offset_map_lock(vma->vm_mm, vmf->pmd, > > + vmf->address, &vmf->ptl); > > + if (!vmf->pte) > > + goto unlock; > > + if (vmf_pte_changed(vmf)) { > > + update_mmu_tlb(vma, vmf->address, vmf->pte); > > + goto unlock; > > + } > > + ret = check_stable_address_space(vma->vm_mm); > > + if (ret) > > + goto unlock; > > + pte_unmap_unlock(vmf->pte, vmf->ptl); > > + return handle_userfault(vmf, VM_UFFD_MISSING); > > + } > > /* Returns NULL on OOM or ERR_PTR(-EAGAIN) if we must retry the fault */ > > folio = alloc_anon_folio(vmf); > > if (IS_ERR(folio)) > > @@ -5579,12 +5595,6 @@ static vm_fault_t do_anonymous_page(struct vm_fault *vmf) > > if (ret) > > goto release; > > > > - /* Deliver the page fault to userland, check inside PT lock */ > > - if (userfaultfd_missing(vma)) { > > - pte_unmap_unlock(vmf->pte, vmf->ptl); > > - folio_put(folio); > > - return handle_userfault(vmf, VM_UFFD_MISSING); > > - } > > map_anon_folio_pte_pf(folio, vmf->pte, vma, addr, > > vmf_orig_pte_uffd_wp(vmf)); > > unlock: > > -- > > 2.43.0 > > > > -- > Cheers, Lorenzo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm: skip temporary folio allocation for anonymous UFFD missing faults 2026-11-19 19:31 ` Avi @ 2026-11-19 22:34 ` David Hildenbrand (Arm) 2026-11-20 4:20 ` Avi 0 siblings, 1 reply; 7+ messages in thread From: David Hildenbrand (Arm) @ 2026-11-19 22:34 UTC (permalink / raw) To: Avi, Lorenzo Stoakes (ARM) Cc: akpm, rppt, peterx, linux-mm, linux-kernel, liam, mhocko, surenb, vbabka On 11/19/26 20:31, Avi wrote: > Hi Lorenzo - I don't think you are in charge of all of Linux and can > decide who can and cannot submit contributions. > This is a legitimate improvement in my opinion - if you disagree that's fine. May I ask which workloads you are running (for customers? etc) where you would care about this improvements? IOW, the real motivation. -- Cheers, David ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm: skip temporary folio allocation for anonymous UFFD missing faults 2026-11-19 22:34 ` David Hildenbrand (Arm) @ 2026-11-20 4:20 ` Avi 2026-11-20 8:38 ` David Hildenbrand (Arm) 0 siblings, 1 reply; 7+ messages in thread From: Avi @ 2026-11-20 4:20 UTC (permalink / raw) To: David Hildenbrand (Arm) Cc: Lorenzo Stoakes (ARM), akpm, rppt, peterx, linux-mm, linux-kernel, liam, mhocko, surenb, vbabka Hi David - the real motivation is very simple - avoiding the wasted allocation (if possible). That's it. On Fri, Nov 20, 2026 at 12:35 AM David Hildenbrand (Arm) <david@kernel.org> wrote: > > On 11/19/26 20:31, Avi wrote: > > Hi Lorenzo - I don't think you are in charge of all of Linux and can > > decide who can and cannot submit contributions. > > This is a legitimate improvement in my opinion - if you disagree that's fine. > > May I ask which workloads you are running (for customers? etc) where you would > care about this improvements? IOW, the real motivation. > > -- > Cheers, > > David ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm: skip temporary folio allocation for anonymous UFFD missing faults 2026-11-20 4:20 ` Avi @ 2026-11-20 8:38 ` David Hildenbrand (Arm) 2026-11-20 8:43 ` Avi 0 siblings, 1 reply; 7+ messages in thread From: David Hildenbrand (Arm) @ 2026-11-20 8:38 UTC (permalink / raw) To: Avi Cc: Lorenzo Stoakes (ARM), akpm, rppt, peterx, linux-mm, linux-kernel, liam, mhocko, surenb, vbabka On 11/20/26 05:20, Avi wrote: > Hi David - the real motivation is very simple - avoiding the wasted > allocation (if possible). > That's it. Just to clarify: we are all right now completely under water with fixes. Optimizations "because we can" are not heplful. They cause more stress on maintainers and reviewers without possibly benefiting anybody in practice. But that's nothing new: we always required a good motivation in order to spend our precious time on proposed changes. Because maintainer+reviewer time was always a limiting factor. While your changes might optimize some uffd workloads, they make the kernel code more complicated. "Because we can" is not sufficient motivation to do that. IOW, if you don't actively run into a problem, there is not actually something broken, or you have a real use case that needs solving in core-kernel code, changes are high that your submissions will be dismissed. Because we simply don't have the capacity to engage with that, sorry. -- Cheers, David ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] mm: skip temporary folio allocation for anonymous UFFD missing faults 2026-11-20 8:38 ` David Hildenbrand (Arm) @ 2026-11-20 8:43 ` Avi 0 siblings, 0 replies; 7+ messages in thread From: Avi @ 2026-11-20 8:43 UTC (permalink / raw) To: David Hildenbrand (Arm) Cc: Lorenzo Stoakes (ARM), akpm, rppt, peterx, linux-mm, linux-kernel, liam, mhocko, surenb, vbabka [-- Attachment #1: Type: text/plain, Size: 1320 bytes --] Thanks for the explanation David. The additional context helps me understand what contributions make sense at the moment. I'll take it into account. Have a nice weekend ;-) On Fri, 20 Nov 2026, 10:38 David Hildenbrand (Arm), <david@kernel.org> wrote: > On 11/20/26 05:20, Avi wrote: > > Hi David - the real motivation is very simple - avoiding the wasted > > allocation (if possible). > > That's it. > > Just to clarify: we are all right now completely under water with fixes. > > Optimizations "because we can" are not heplful. They cause more stress on > maintainers and reviewers without possibly benefiting anybody in practice. > > But that's nothing new: we always required a good motivation in order to > spend > our precious time on proposed changes. Because maintainer+reviewer time was > always a limiting factor. > > While your changes might optimize some uffd workloads, they make the > kernel code > more complicated. > > "Because we can" is not sufficient motivation to do that. > > IOW, if you don't actively run into a problem, there is not actually > something > broken, or you have a real use case that needs solving in core-kernel code, > changes are high that your submissions will be dismissed. > > Because we simply don't have the capacity to engage with that, sorry. > > -- > Cheers, > > David > [-- Attachment #2: Type: text/html, Size: 1822 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-20 8:43 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-19 18:00 [PATCH] mm: skip temporary folio allocation for anonymous UFFD missing faults Avi Weiss 2026-11-19 18:22 ` Lorenzo Stoakes (ARM) 2026-11-19 19:31 ` Avi 2026-11-19 22:34 ` David Hildenbrand (Arm) 2026-11-20 4:20 ` Avi 2026-11-20 8:38 ` David Hildenbrand (Arm) 2026-11-20 8:43 ` Avi
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.