hulk inclusion category: performance bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBA1TU
--------------------------------
Check the vma's userfaultfd ctx ahead to dup_mmap(), so we can avoid the function call overhead if the ctx is NULL.
The Unixbench single core process create has 2 ~ 3% improve with this and following patch.
Signed-off-by: Jinjie Ruan ruanjinjie@huawei.com --- fs/userfaultfd.c | 2 -- kernel/fork.c | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index c64ad1fca4e4..b61cc1b6db60 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -707,8 +707,6 @@ 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) - return 0;
if (!(octx->features & UFFD_FEATURE_EVENT_FORK)) { vma_start_write(vma); diff --git a/kernel/fork.c b/kernel/fork.c index f30b24c68442..919ccd202698 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -731,9 +731,14 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, if (retval) goto fail_nomem_policy; tmp->vm_mm = mm; - retval = dup_userfaultfd(tmp, &uf); - if (retval) - goto fail_nomem_anon_vma_fork; + +#ifdef CONFIG_USERFAULTFD + if (unlikely(tmp->vm_userfaultfd_ctx.ctx)) { + retval = dup_userfaultfd(tmp, &uf); + if (retval) + goto fail_nomem_anon_vma_fork; + } +#endif if (tmp->vm_flags & VM_WIPEONFORK) { /* * VM_WIPEONFORK gets a clean slate in the child.