[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130316181947.GA7560@redhat.com>
Date: Sat, 16 Mar 2013 19:19:47 +0100
From: Oleg Nesterov <oleg@...hat.com>
To: Frederic Weisbecker <fweisbec@...il.com>
Cc: Ming Lei <tom.leiming@...il.com>,
"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
Shaohua Li <shli@...nel.org>,
Al Viro <viro@...iv.linux.org.uk>,
Andrew Morton <akpm@...ux-foundation.org>,
linux-kernel@...r.kernel.org
Subject: Re: +
atomic-improve-atomic_inc_unless_negative-atomic_dec_unless_positive
.patch added to -mm tree
On 03/15, Frederic Weisbecker wrote:
>
> 2013/3/15 Oleg Nesterov <oleg@...hat.com>:
> >
> > 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
> case.
>
> 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.
Oleg.
--
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