Re: [PATCH] pid: remove redundant condition

From: Liu ping fan
Date: Fri Apr 06 2012 - 04:33:24 EST


On Fri, Apr 6, 2012 at 2:26 PM, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
> On Thu, Apr 5, 2012 at 11:16 PM, Liu Ping Fan <kernelfans@xxxxxxxxx> wrote:
>> From: Liu Ping Fan <pingfank@xxxxxxxxxxxxxxxxxx>
>>
>> Signed-off-by: Liu Ping Fan <pingfank@xxxxxxxxxxxxxxxxxx>
>> ---
>> Â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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/