[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <AANLkTikK9m7USWqN9QZnjnNbHen9bVyFt6xiGxNG4OyY@mail.gmail.com>
Date: Wed, 9 Jun 2010 22:55:13 -0700
From: Salman Qazi <sqazi@...gle.com>
To: Michel Lespinasse <walken@...gle.com>
Cc: Linus Torvalds <torvalds@...ux-foundation.org>,
Peter Zijlstra <peterz@...radead.org>,
akpm@...ux-foundation.org, mingo@...e.hu,
linux-kernel@...r.kernel.org, tytso@...gle.com
Subject: Re: [PATCH] Fix a race in pid generation that causes pids to be
reused immediately.
On Wed, Jun 9, 2010 at 10:17 PM, Michel Lespinasse <walken@...gle.com> wrote:
> On Wed, Jun 9, 2010 at 5:20 PM, Linus Torvalds
> <torvalds@...ux-foundation.org> wrote:
>>
>> On Wed, 9 Jun 2010, Salman Qazi wrote:
>> >
>> > I don't think this gives the right answer in the a < base < b case.
>> > Here a - base < 0 and
>> > b - base > 0. But we really want b to be before a, since a has rolled
>> > over further than b.
>>
>> Right you are.
>>
>> > I think the right solution is comparing (a - base + max_pid) % max_pid
>> > with (b - base + max_pid) % max_pid. Am I correct or deluded? .
>>
>> That would work, but it would be horrible. Just use the three compares
>> version: doing a integer 'mod' operator is _way_ more expensive.
>
> As shown by the three compares version, the question here does not depend on
> the max_pid value. So, we can replace max_pid with any integer >= max_pid
> without changing the result. This is nice because, replacing max_pid with
> 2^32, the expression simplifies to:
>
> (unsigned)(a - base) < (unsigned)(b - base)
>
> I think I like this form after all :)
I don't mind doing this, if nobody disagrees. Should be fine with a
comment on top explaining the intention?
>
> --
> Michel "Walken" Lespinasse
> A program is never fully debugged until the last user dies.
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists