From: ebiederm@xmission.com (Eric W. Biederman)
To: Daeseok Youn <daeseok.youn@gmail.com>
Cc: akpm@linux-foundation.org, oleg@redhat.com,
viro@zeniv.linux.org.uk, luto@amacapital.net,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] kernel/fork.c : remove local 'oldmm' and retval
Date: Wed, 27 Nov 2013 03:24:11 +0000 [thread overview]
Message-ID: <87y54attlw.fsf@xmission.com> (raw)
In-Reply-To: <2547094.3YTvOEEdct@daeseok-laptop> (Daeseok Youn's message of "Wed, 27 Nov 2013 12:12:13 +0900")
Daeseok Youn <daeseok.youn@gmail.com> writes:
> From cec2f201f0dc99a33a58d9d1e0452140bb0993a1 Mon Sep 17 00:00:00 2001
> From: Daeseok Youn <daeseok.youn@lge.com>
> Date: Wed, 27 Nov 2013 09:54:41 +0900
> Subject: [PATCH] kernel/fork.c : remove local 'oldmm' and retval
>
> Local oldmm is used only for increaing mm_users field
> in current->mm. When clone_flags have a CLONE_VM flag,
> current->mm is assigning to local 'mm'.
> Local retval is used only for returning -ENOMEM value.
> When dup_mm() is failed, just return -ENOMEM.
You are making the generated code worse, and the source less
comprehensible.
You are adding additional exit points making it harder to analyze the
function.
You are introducing races and expense by not caching current->mm in
oldmm.
This looks like code churn for no good reason, and that will result in
worse code.
ick.
Eric
> Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
> ---
> kernel/fork.c | 16 +++++-----------
> 1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 728d5be..022a0af 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -857,8 +857,7 @@ fail_nocontext:
>
> static int copy_mm(unsigned long clone_flags, struct task_struct *tsk)
> {
> - struct mm_struct *mm, *oldmm;
> - int retval;
> + struct mm_struct *mm;
>
> tsk->min_flt = tsk->maj_flt = 0;
> tsk->nvcsw = tsk->nivcsw = 0;
> @@ -874,28 +873,23 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk)
> *
> * We need to steal a active VM for that..
> */
> - oldmm = current->mm;
> - if (!oldmm)
> + if (!current->mm)
> return 0;
>
> if (clone_flags & CLONE_VM) {
> - atomic_inc(&oldmm->mm_users);
> - mm = oldmm;
> + mm = current->mm;
> + atomic_inc(&mm->mm_users);
> goto good_mm;
> }
>
> - retval = -ENOMEM;
> mm = dup_mm(tsk);
> if (!mm)
> - goto fail_nomem;
> + return -ENOMEM;
>
> good_mm:
> tsk->mm = mm;
> tsk->active_mm = mm;
> return 0;
> -
> -fail_nomem:
> - return retval;
> }
>
> static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
WARNING: multiple messages have this Message-ID (diff)
From: ebiederm@xmission.com (Eric W. Biederman)
To: Daeseok Youn <daeseok.youn@gmail.com>
Cc: akpm@linux-foundation.org, oleg@redhat.com,
viro@zeniv.linux.org.uk, luto@amacapital.net,
linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: Re: [PATCH] kernel/fork.c : remove local 'oldmm' and retval
Date: Tue, 26 Nov 2013 19:24:11 -0800 [thread overview]
Message-ID: <87y54attlw.fsf@xmission.com> (raw)
In-Reply-To: <2547094.3YTvOEEdct@daeseok-laptop> (Daeseok Youn's message of "Wed, 27 Nov 2013 12:12:13 +0900")
Daeseok Youn <daeseok.youn@gmail.com> writes:
> From cec2f201f0dc99a33a58d9d1e0452140bb0993a1 Mon Sep 17 00:00:00 2001
> From: Daeseok Youn <daeseok.youn@lge.com>
> Date: Wed, 27 Nov 2013 09:54:41 +0900
> Subject: [PATCH] kernel/fork.c : remove local 'oldmm' and retval
>
> Local oldmm is used only for increaing mm_users field
> in current->mm. When clone_flags have a CLONE_VM flag,
> current->mm is assigning to local 'mm'.
> Local retval is used only for returning -ENOMEM value.
> When dup_mm() is failed, just return -ENOMEM.
You are making the generated code worse, and the source less
comprehensible.
You are adding additional exit points making it harder to analyze the
function.
You are introducing races and expense by not caching current->mm in
oldmm.
This looks like code churn for no good reason, and that will result in
worse code.
ick.
Eric
> Signed-off-by: Daeseok Youn <daeseok.youn@gmail.com>
> ---
> kernel/fork.c | 16 +++++-----------
> 1 file changed, 5 insertions(+), 11 deletions(-)
>
> diff --git a/kernel/fork.c b/kernel/fork.c
> index 728d5be..022a0af 100644
> --- a/kernel/fork.c
> +++ b/kernel/fork.c
> @@ -857,8 +857,7 @@ fail_nocontext:
>
> static int copy_mm(unsigned long clone_flags, struct task_struct *tsk)
> {
> - struct mm_struct *mm, *oldmm;
> - int retval;
> + struct mm_struct *mm;
>
> tsk->min_flt = tsk->maj_flt = 0;
> tsk->nvcsw = tsk->nivcsw = 0;
> @@ -874,28 +873,23 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk)
> *
> * We need to steal a active VM for that..
> */
> - oldmm = current->mm;
> - if (!oldmm)
> + if (!current->mm)
> return 0;
>
> if (clone_flags & CLONE_VM) {
> - atomic_inc(&oldmm->mm_users);
> - mm = oldmm;
> + mm = current->mm;
> + atomic_inc(&mm->mm_users);
> goto good_mm;
> }
>
> - retval = -ENOMEM;
> mm = dup_mm(tsk);
> if (!mm)
> - goto fail_nomem;
> + return -ENOMEM;
>
> good_mm:
> tsk->mm = mm;
> tsk->active_mm = mm;
> return 0;
> -
> -fail_nomem:
> - return retval;
> }
>
> static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
next prev parent reply other threads:[~2013-11-27 3:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-27 3:12 [PATCH] kernel/fork.c : remove local 'oldmm' and retval Daeseok Youn
2013-11-27 3:12 ` Daeseok Youn
2013-11-27 3:24 ` Eric W. Biederman [this message]
2013-11-27 3:24 ` Eric W. Biederman
[not found] ` <CAHb8M2A5h==bu76m1AitY3G6gaTrTdL+VMUw9XUWTC5HB4=79Q@mail.gmail.com>
2013-11-27 5:28 ` DaeSeok Youn
2013-11-27 5:28 ` DaeSeok Youn
2013-11-27 6:35 ` Julia Lawall
2013-11-27 6:35 ` Julia Lawall
2013-11-27 7:33 ` DaeSeok Youn
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=87y54attlw.fsf@xmission.com \
--to=ebiederm@xmission.com \
--cc=akpm@linux-foundation.org \
--cc=daeseok.youn@gmail.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=oleg@redhat.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.