From: Jinjie Ruan <ruanjinjie@huawei.com>
To: <viro@zeniv.linux.org.uk>, <brauner@kernel.org>, <jack@suse.cz>,
<akpm@linux-foundation.org>, <Liam.Howlett@Oracle.com>,
<lokeshgidra@google.com>, <lorenzo.stoakes@oracle.com>,
<rppt@kernel.org>, <aarcange@redhat.com>, <ruanjinjie@huawei.com>,
<Jason@zx2c4.com>, <linux-fsdevel@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-mm@kvack.org>
Subject: [PATCH 2/2] mm, rmap: handle anon_vma_fork() NULL check inline
Date: Mon, 9 Dec 2024 21:25:49 +0800 [thread overview]
Message-ID: <20241209132549.2878604-3-ruanjinjie@huawei.com> (raw)
In-Reply-To: <20241209132549.2878604-1-ruanjinjie@huawei.com>
Check the anon_vma of pvma inline so we can avoid the function call
overhead if the anon_vma is NULL.
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
---
include/linux/rmap.h | 12 +++++++++++-
mm/rmap.c | 6 +-----
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/include/linux/rmap.h b/include/linux/rmap.h
index 683a04088f3f..9ddba9b23a1c 100644
--- a/include/linux/rmap.h
+++ b/include/linux/rmap.h
@@ -154,7 +154,17 @@ void anon_vma_init(void); /* create anon_vma_cachep */
int __anon_vma_prepare(struct vm_area_struct *);
void unlink_anon_vmas(struct vm_area_struct *);
int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
+
+int __anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
+static inline int anon_vma_fork(struct vm_area_struct *vma,
+ struct vm_area_struct *pvma)
+{
+ /* Don't bother if the parent process has no anon_vma here. */
+ if (!pvma->anon_vma)
+ return 0;
+
+ return __anon_vma_fork(vma, pvma);
+}
static inline int anon_vma_prepare(struct vm_area_struct *vma)
{
diff --git a/mm/rmap.c b/mm/rmap.c
index c6c4d4ea29a7..06e9b68447c2 100644
--- a/mm/rmap.c
+++ b/mm/rmap.c
@@ -331,16 +331,12 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
* the corresponding VMA in the parent process is attached to.
* Returns 0 on success, non-zero on failure.
*/
-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
+int __anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
{
struct anon_vma_chain *avc;
struct anon_vma *anon_vma;
int error;
- /* Don't bother if the parent process has no anon_vma here. */
- if (!pvma->anon_vma)
- return 0;
-
/* Drop inherited anon_vma, we'll reuse existing or allocate new. */
vma->anon_vma = NULL;
--
2.34.1
next prev parent reply other threads:[~2024-12-09 13:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-09 13:25 [PATCH 0/2] userfaultfd: handle few " Jinjie Ruan
2024-12-09 13:25 ` [PATCH 1/2] userfaultfd: handle dup_userfaultfd() " Jinjie Ruan
2024-12-09 13:25 ` Jinjie Ruan [this message]
2024-12-09 13:35 ` [PATCH 2/2] mm, rmap: handle anon_vma_fork() " Matthew Wilcox
2024-12-10 2:25 ` Jinjie Ruan
2024-12-09 13:42 ` [PATCH 0/2] userfaultfd: handle few " Lorenzo Stoakes
2024-12-10 1:21 ` Jinjie Ruan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241209132549.2878604-3-ruanjinjie@huawei.com \
--to=ruanjinjie@huawei.com \
--cc=Jason@zx2c4.com \
--cc=Liam.Howlett@Oracle.com \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=lokeshgidra@google.com \
--cc=lorenzo.stoakes@oracle.com \
--cc=rppt@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox