mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] userfaultfd: early return in dup_userfaultfd()
@ 2024-03-27  9:08 Peng Zhang
  2024-03-27 18:56 ` Peter Xu
  0 siblings, 1 reply; 2+ messages in thread
From: Peng Zhang @ 2024-03-27  9:08 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: akpm, peterx, david, axelrasmussen, surenb, lokeshgidra,
	Liam.Howlett, wangkefeng.wang, sunnanyong

From: ZhangPeng <zhangpeng362@huawei.com>

When vma->vm_userfaultfd_ctx.ctx is NULL, vma->vm_flags should have
cleared __VM_UFFD_FLAGS. Therefore, there is no need to down_write or
clear the flag, which will affect fork performance. Fix this by
returning early if octx is NULL in dup_userfaultfd().

By applying this patch we can get a 1.3% performance improvement for
lmbench fork_prot. Results are as follows:
                   base      early return
Process fork+exit: 419.1106  413.4804

Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>
---
 fs/userfaultfd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 60dcfafdc11a..3e6ddda6f159 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -657,7 +657,10 @@ int dup_userfaultfd(struct vm_area_struct *vma, struct list_head *fcs)
 	struct userfaultfd_fork_ctx *fctx;
 
 	octx = vma->vm_userfaultfd_ctx.ctx;
-	if (!octx || !(octx->features & UFFD_FEATURE_EVENT_FORK)) {
+	if (!octx)
+		return 0;
+
+	if (!(octx->features & UFFD_FEATURE_EVENT_FORK)) {
 		vma_start_write(vma);
 		vma->vm_userfaultfd_ctx = NULL_VM_UFFD_CTX;
 		userfaultfd_set_vm_flags(vma, vma->vm_flags & ~__VM_UFFD_FLAGS);
-- 
2.25.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] userfaultfd: early return in dup_userfaultfd()
  2024-03-27  9:08 [PATCH] userfaultfd: early return in dup_userfaultfd() Peng Zhang
@ 2024-03-27 18:56 ` Peter Xu
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Xu @ 2024-03-27 18:56 UTC (permalink / raw)
  To: Peng Zhang
  Cc: linux-mm, linux-kernel, akpm, david, axelrasmussen, surenb,
	lokeshgidra, Liam.Howlett, wangkefeng.wang, sunnanyong

On Wed, Mar 27, 2024 at 05:08:35PM +0800, Peng Zhang wrote:
> From: ZhangPeng <zhangpeng362@huawei.com>
> 
> When vma->vm_userfaultfd_ctx.ctx is NULL, vma->vm_flags should have
> cleared __VM_UFFD_FLAGS. Therefore, there is no need to down_write or
> clear the flag, which will affect fork performance. Fix this by
> returning early if octx is NULL in dup_userfaultfd().
> 
> By applying this patch we can get a 1.3% performance improvement for
> lmbench fork_prot. Results are as follows:
>                    base      early return
> Process fork+exit: 419.1106  413.4804
> 
> Signed-off-by: ZhangPeng <zhangpeng362@huawei.com>

Reviewed-by: Peter Xu <peterx@redhat.com>

-- 
Peter Xu


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-27 18:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-27  9:08 [PATCH] userfaultfd: early return in dup_userfaultfd() Peng Zhang
2024-03-27 18:56 ` Peter Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®