Return early if ctx is NULL for dup_userfaultfd() or if anon_vma is NULL for anon_vma_fork().
Jinjie Ruan (2): fork: Return early if ctx is NULL for dup_userfaultfd() fork: Return early if anon_vma is NULL for anon_vma_fork()
fs/userfaultfd.c | 2 -- kernel/fork.c | 17 ++++++++++++----- mm/rmap.c | 4 ---- 3 files changed, 12 insertions(+), 11 deletions(-)
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.
hulk inclusion category: performance bugzilla: https://gitee.com/src-openeuler/kernel/issues/IBA1TU
--------------------------------
Check the anon_vma of pvma 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 previous patch.
Signed-off-by: Jinjie Ruan ruanjinjie@huawei.com --- kernel/fork.c | 6 ++++-- mm/rmap.c | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c index 919ccd202698..3f3d15321e38 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -746,8 +746,10 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, * copy page for current vma. */ tmp->anon_vma = NULL; - } else if (anon_vma_fork(tmp, mpnt)) - goto fail_nomem_anon_vma_fork; + } else if (unlikely(mpnt->anon_vma)) { + if (anon_vma_fork(tmp, mpnt)) + goto fail_nomem_anon_vma_fork; + } vm_flags_clear(tmp, VM_LOCKED_MASK); /* * Copy/update hugetlb private vma information. diff --git a/mm/rmap.c b/mm/rmap.c index dbcdac9bb7a3..b533c613d515 100644 --- a/mm/rmap.c +++ b/mm/rmap.c @@ -337,10 +337,6 @@ int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma) 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;
反馈: 您发送到kernel@openeuler.org的补丁/补丁集,已成功转换为PR! PR链接地址: https://gitee.com/openeuler/kernel/pulls/14122 邮件列表地址:https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/J...
FeedBack: The patch(es) which you have sent to kernel@openeuler.org mailing list has been converted to a pull request successfully! Pull request link: https://gitee.com/openeuler/kernel/pulls/14122 Mailing list address: https://mailweb.openeuler.org/hyperkitty/list/kernel@openeuler.org/message/J...