[PATCH 1/2] userfaultfd: handle dup_userfaultfd() NULL check inline

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Make the NULL check for vma's userfaultfd ctx inline, so we can
avoid the function call overhead if the ctx is NULL.

Signed-off-by: Jinjie Ruan <ruanjinjie@xxxxxxxxxx>
---
 fs/userfaultfd.c              |  5 +----
 include/linux/userfaultfd_k.h | 11 ++++++++++-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c
index 7c0bd0b55f88..7e551c234832 100644
--- a/fs/userfaultfd.c
+++ b/fs/userfaultfd.c
@@ -615,15 +615,12 @@ static void userfaultfd_event_complete(struct userfaultfd_ctx *ctx,
 	__remove_wait_queue(&ctx->event_wqh, &ewq->wq);
 }
 
-int dup_userfaultfd(struct vm_area_struct *vma, struct list_head *fcs)
+int __dup_userfaultfd(struct vm_area_struct *vma, struct list_head *fcs)
 {
 	struct userfaultfd_ctx *ctx = NULL, *octx;
 	struct userfaultfd_fork_ctx *fctx;
 
 	octx = vma->vm_userfaultfd_ctx.ctx;
-	if (!octx)
-		return 0;
-
 	if (!(octx->features & UFFD_FEATURE_EVENT_FORK)) {
 		userfaultfd_reset_ctx(vma);
 		return 0;
diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h
index cb40f1a1d081..06b47104aa1a 100644
--- a/include/linux/userfaultfd_k.h
+++ b/include/linux/userfaultfd_k.h
@@ -247,7 +247,16 @@ static inline bool vma_can_userfault(struct vm_area_struct *vma,
 	    vma_is_shmem(vma);
 }
 
-extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *);
+int __dup_userfaultfd(struct vm_area_struct *, struct list_head *);
+static inline int dup_userfaultfd(struct vm_area_struct *vma,
+				  struct list_head *fcs)
+{
+	if (likely(!vma->vm_userfaultfd_ctx.ctx))
+		return 0;
+
+	return __dup_userfaultfd(vma, fcs);
+}
+
 extern void dup_userfaultfd_complete(struct list_head *);
 void dup_userfaultfd_fail(struct list_head *);
 
-- 
2.34.1





[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux