From: Peter Zijlstra <peterz@infradead.org>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Salman <sqazi@google.com>,
akpm@linux-foundation.org, mingo@elte.hu,
linux-kernel@vger.kernel.org, tytso@google.com
Subject: Re: [PATCH] Fix a race in pid generation that causes pids to be reused immediately.
Date: Wed, 09 Jun 2010 23:33:27 +0200 [thread overview]
Message-ID: <1276119207.1745.154.camel@laptop> (raw)
In-Reply-To: <alpine.LFD.2.00.1006091408430.4506@i5.linux-foundation.org>
On Wed, 2010-06-09 at 14:21 -0700, Linus Torvalds wrote:
>
> On Wed, 9 Jun 2010, Salman wrote:
> > +/*
> > + * If we started walking pids at 'base', is 'a' seen before 'b'?
> > + *
> > + */
> > +static int pid_before(int base, int a, int b)
> > +{
> > + int a_lt_b = (a < b);
> > + int min_a_b = min(a, b);
> > + int max_a_b = max(a, b);
> > +
> > + if ((base <= min_a_b) || (base >= max_a_b))
> > + return a_lt_b;
> > +
> > + return !a_lt_b;
> > +}
>
> Ok, so that's a very confusing expression. I'm sure it gets the right
> value, but it's not exactly straightforward, is it?
>
> Wouldn't it be nicer to write it out in a more straightforward way?
> Something like
>
> /* a and b in order? base must not be between them */
> if (a <= b)
> return (base <= a || base >= b);
> /* b < a? We reach 'a' first iff base is between them */
> return base >= b && base <= a;
>
> would seem to be equivalent and easier to explain, no?
>
> And when you write it that way, it looks like the compiler should be able
> to trivially CSE the five comparisons down to just three (notice how the
> "base <= a" and "base >= b" comparisons are repeated. Which I'm sure some
> super-optimizing compiler can do from your version too, but mine seems
> more straightforward.
>
> But maybe I did that thing wrong, and I just confused myself. I have _not_
> checked the logic deeply, somebody else should definitely double-check me.
Isn't: return a - base < b - base, the natural way to express this?
next prev parent reply other threads:[~2010-06-09 21:34 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-06-09 21:00 [PATCH] Fix a race in pid generation that causes pids to be reused immediately Salman
2010-06-09 21:21 ` Linus Torvalds
2010-06-09 21:33 ` Peter Zijlstra [this message]
2010-06-09 22:20 ` Linus Torvalds
2010-06-09 22:27 ` Linus Torvalds
2010-06-10 0:08 ` Salman Qazi
2010-06-10 0:20 ` Linus Torvalds
[not found] ` <AANLkTilXJ0X2qxD9cNTlLayKzySEZu1HEZUWu--Go8kw@mail.gmail.com>
2010-06-10 5:55 ` Salman Qazi
2010-06-10 16:39 ` Linus Torvalds
-- strict thread matches above, loose matches on Subject: below --
2010-06-11 17:17 Salman
2010-06-11 17:44 ` Linus Torvalds
2010-06-11 22:49 ` Salman
2010-06-11 23:07 ` Linus Torvalds
2010-06-14 23:58 ` Andrew Morton
2010-06-15 0:56 ` tytso
2010-06-15 1:55 ` Andrew Morton
2010-06-15 3:26 ` Paul Mackerras
2010-06-15 4:21 ` Andrew Morton
2010-06-15 4:38 ` Eric Dumazet
2010-06-15 6:57 ` Benjamin Herrenschmidt
2010-06-15 7:25 ` Paul Mackerras
2010-06-15 12:56 ` tytso
2010-06-15 13:06 ` Kyle McMartin
2010-06-15 14:35 ` Peter Zijlstra
2010-06-15 19:37 ` Andrew Morton
2010-06-10 21:24 Salman
2010-06-10 20:09 Salman
2010-06-10 20:38 ` tytso
2010-06-10 21:04 ` Salman Qazi
2010-06-09 6:24 Salman
2010-06-09 6:53 ` Andi Kleen
2010-06-09 9:48 ` Ingo Molnar
2010-06-09 15:39 ` Linus Torvalds
2010-06-09 15:50 ` tytso
2010-06-09 16:06 ` Linus Torvalds
2010-06-09 17:10 ` tytso
2010-06-09 17:23 ` Linus Torvalds
2010-06-09 17:25 ` Linus Torvalds
2010-06-09 17:34 ` tytso
2010-06-09 17:43 ` Linus Torvalds
2010-06-09 17:47 ` tytso
2010-06-09 18:09 ` Salman Qazi
2010-06-09 11:49 ` Michel Lespinasse
2010-06-09 12:37 ` tytso
2010-06-09 12:17 ` tytso
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=1276119207.1745.154.camel@laptop \
--to=peterz@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=sqazi@google.com \
--cc=torvalds@linux-foundation.org \
--cc=tytso@google.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox