Re: +atomic-improve-atomic_inc_unless_negative-atomic_dec_unless_positive.patch added to -mm tree
From: Oleg Nesterov
Date: Sat Mar 16 2013 - 14:21:53 EST
On 03/15, Frederic Weisbecker wrote:
> 2013/3/15 Oleg Nesterov <oleg@xxxxxxxxxx>:
> > do_something() looks fine, if atomic_add_unless_negative() succeeds
> > we do have a barrier?
> Ok, I guess the guarantee of a barrier in case of failure is probably
> not needed. But since the only way to safely read the atomic value is
> a cmpxchg like operation, I guess a barrier must be involved in any
> Using atomic_read() may return some stale value.
Oh, if the lack of the barrier is fine, then "stale" should be fine
too, I think. I bet you can't describe accurately what "stale" can
actually mean in this case ;)
If, say, atomic_inc_unless_negative(p) sees the stale value < 0, it
was actually negative somewhere in the past. If it was changed later,
we can pretend that atomic_inc_unless_negative() was called before
the change which makes it positive.
> > Anyway, I understand that it is possible to write the code which
> > won't work without the uncoditional mb().
> Yeah that's my fear.
I see... well personally I can't imagine the "natural" (non-artificial)
code example which needs mb() in case of failure.
However, I have to agree with Paul's "It is not like memory ordering is
simple", so I won't argue.
> > My point was: should we fix atomic_add_unless() then? If not, why
> > should atomic_add_unless_negative() differ?
> They shouldn't differ I guess.
Agreed, they shouldn't.
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/