[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241209132549.2878604-2-ruanjinjie@huawei.com>
Date: Mon, 9 Dec 2024 21:25:48 +0800
From: Jinjie Ruan <ruanjinjie@...wei.com>
To: <viro@...iv.linux.org.uk>, <brauner@...nel.org>, <jack@...e.cz>,
<akpm@...ux-foundation.org>, <Liam.Howlett@...cle.com>,
<lokeshgidra@...gle.com>, <lorenzo.stoakes@...cle.com>, <rppt@...nel.org>,
<aarcange@...hat.com>, <ruanjinjie@...wei.com>, <Jason@...c4.com>,
<linux-fsdevel@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-mm@...ck.org>
Subject: [PATCH 1/2] userfaultfd: handle dup_userfaultfd() NULL check inline
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@...wei.com>
---
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
Powered by blists - more mailing lists