linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] pid: remove redundant condition
@ 2012-04-06  6:16 Liu Ping Fan
  2012-04-06  6:26 ` Linus Torvalds
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Ping Fan @ 2012-04-06  6:16 UTC (permalink / raw)
  To: linux-kernel, Linus Torvalds

From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>

Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
---
 kernel/pid.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)

diff --git a/kernel/pid.c b/kernel/pid.c
index 9f08dfa..e4ca244 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -248,8 +248,7 @@ void put_pid(struct pid *pid)
 		return;
 
 	ns = pid->numbers[pid->level].ns;
-	if ((atomic_read(&pid->count) == 1) ||
-	     atomic_dec_and_test(&pid->count)) {
+	if (atomic_dec_and_test(&pid->count) {
 		kmem_cache_free(ns->pid_cachep, pid);
 		put_pid_ns(ns);
 	}
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pid: remove redundant condition
  2012-04-06  6:16 [PATCH] pid: remove redundant condition Liu Ping Fan
@ 2012-04-06  6:26 ` Linus Torvalds
  2012-04-06  8:33   ` Liu ping fan
  0 siblings, 1 reply; 3+ messages in thread
From: Linus Torvalds @ 2012-04-06  6:26 UTC (permalink / raw)
  To: Liu Ping Fan; +Cc: linux-kernel

On Thu, Apr 5, 2012 at 11:16 PM, Liu Ping Fan <kernelfans@gmail.com> wrote:
> From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
>
> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
> ---
>  kernel/pid.c |    3 +--
>  1 files changed, 1 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/pid.c b/kernel/pid.c
> index 9f08dfa..e4ca244 100644
> --- a/kernel/pid.c
> +++ b/kernel/pid.c
> @@ -248,8 +248,7 @@ void put_pid(struct pid *pid)
>                return;
>
>        ns = pid->numbers[pid->level].ns;
> -       if ((atomic_read(&pid->count) == 1) ||
> -            atomic_dec_and_test(&pid->count)) {
> +       if (atomic_dec_and_test(&pid->count) {
>                kmem_cache_free(ns->pid_cachep, pid);
>                put_pid_ns(ns);
>        }

No, this isn't necessarily redundant.

The atomic_dec_and_test() instruction can be very expensive. So if
count was 1 before, we're the last user, and we can free it without
the expensive atomic_dec_and_test().

However, if we are *not* the last user, then we can race with another
user decrementing the count, so now we need to use the expensive
version.

Now, whether that special case is really worth it or not, I don't
know. But it's not redundant.

                    Linus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pid: remove redundant condition
  2012-04-06  6:26 ` Linus Torvalds
@ 2012-04-06  8:33   ` Liu ping fan
  0 siblings, 0 replies; 3+ messages in thread
From: Liu ping fan @ 2012-04-06  8:33 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel

On Fri, Apr 6, 2012 at 2:26 PM, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
> On Thu, Apr 5, 2012 at 11:16 PM, Liu Ping Fan <kernelfans@gmail.com> wrote:
>> From: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
>>
>> Signed-off-by: Liu Ping Fan <pingfank@linux.vnet.ibm.com>
>> ---
>>  kernel/pid.c |    3 +--
>>  1 files changed, 1 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/pid.c b/kernel/pid.c
>> index 9f08dfa..e4ca244 100644
>> --- a/kernel/pid.c
>> +++ b/kernel/pid.c
>> @@ -248,8 +248,7 @@ void put_pid(struct pid *pid)
>>                return;
>>
>>        ns = pid->numbers[pid->level].ns;
>> -       if ((atomic_read(&pid->count) == 1) ||
>> -            atomic_dec_and_test(&pid->count)) {
>> +       if (atomic_dec_and_test(&pid->count) {
>>                kmem_cache_free(ns->pid_cachep, pid);
>>                put_pid_ns(ns);
>>        }
>
> No, this isn't necessarily redundant.
>
> The atomic_dec_and_test() instruction can be very expensive. So if
Oh, got it, thanks.

Regards,
pingfan
> count was 1 before, we're the last user, and we can free it without
> the expensive atomic_dec_and_test().
>
> However, if we are *not* the last user, then we can race with another
> user decrementing the count, so now we need to use the expensive
> version.
>
> Now, whether that special case is really worth it or not, I don't
> know. But it's not redundant.
>
>                    Linus

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-04-06  8:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-06  6:16 [PATCH] pid: remove redundant condition Liu Ping Fan
2012-04-06  6:26 ` Linus Torvalds
2012-04-06  8:33   ` Liu ping fan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).