All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@redhat.com>
To: Ming Lei <tom.leiming@gmail.com>,
	"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
	Frederic Weisbecker <fweisbec@gmail.com>
Cc: Shaohua Li <shli@kernel.org>, Al Viro <viro@zeniv.linux.org.uk>,
	Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org
Subject: Re: + atomic-improve-atomic_inc_unless_negative-atomic_dec_unless_positive .patch added to -mm tree
Date: Fri, 15 Mar 2013 17:51:31 +0100	[thread overview]
Message-ID: <20130315165131.GA32065@redhat.com> (raw)
In-Reply-To: <CACVXFVOjWc4RU+A-8PeYP9RfJ1-HSiZHbbv771LXDynMs0ybMQ@mail.gmail.com>

On 03/15, Ming Lei wrote:
>
> On Fri, Mar 15, 2013 at 9:46 PM, Oleg Nesterov <oleg@redhat.com> wrote:
> > On 03/15, Ming Lei wrote:
> >>
> >> On Fri, Mar 15, 2013 at 12:24 AM, Oleg Nesterov <oleg@redhat.com> wrote:
> >> >  static inline int atomic_inc_unless_negative(atomic_t *p)
> >> >  {
> >> >         int v, v1;
> >> > -       for (v = 0; v >= 0; v = v1) {
> >> > +       for (v = atomic_read(p); v >= 0; v = v1) {
> >> >                 v1 = atomic_cmpxchg(p, v, v + 1);
> >>
> >> Unfortunately, the above will exchange the current value even though
> >> it is negative, so it isn't correct.
> >
> > Hmm, why? We always check "v >= 0" before we try to do
> > atomic_cmpxchg(old => v) ?
>
> Sorry, yes, you are right. But then your patch is basically same with the
> previous one, isn't it?

Sure, the logic is the same, just the patch (and the code) looks simpler
and more understandable.

> And has same problem, see below discussion:
>
> http://marc.info/?t=136284366900001&r=1&w=2

The lack of the barrier?

I thought about this, this should be fine? atomic_add_unless() has the same
"problem", but this is documented in atomic_ops.txt:

	atomic_add_unless requires explicit memory barriers around the operation
	unless it fails (returns 0).

I thought that atomic_add_unless_negative() should have the same
guarantees?

Paul? Frederic?

Oleg.


  reply	other threads:[~2013-03-15 16:53 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-14 16:24 + atomic-improve-atomic_inc_unless_negative-atomic_dec_unless_positive .patch added to -mm tree Oleg Nesterov
2013-03-15  3:46 ` Ming Lei
2013-03-15 13:46   ` Oleg Nesterov
2013-03-15 15:13     ` Ming Lei
2013-03-15 16:51       ` Oleg Nesterov [this message]
2013-03-15 17:23         ` Frederic Weisbecker
2013-03-15 17:51           ` Oleg Nesterov
2013-03-15 18:34             ` Frederic Weisbecker
2013-03-15 20:17               ` Paul E. McKenney
2013-03-16 18:30                 ` Oleg Nesterov
2013-03-17 17:26                   ` Paul E. McKenney
2013-03-21 17:08                     ` Oleg Nesterov
2013-03-21 17:34                       ` Paul E. McKenney
2013-03-21 18:03                       ` Eric Dumazet
2013-03-21 18:30                         ` Oleg Nesterov
2013-03-21 22:56                           ` Eric Dumazet
2013-03-22 12:59                             ` Oleg Nesterov
2013-03-22 16:34                             ` Paul E. McKenney
2013-03-16 18:19               ` Oleg Nesterov

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=20130315165131.GA32065@redhat.com \
    --to=oleg@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@linux.vnet.ibm.com \
    --cc=shli@kernel.org \
    --cc=tom.leiming@gmail.com \
    --cc=viro@zeniv.linux.org.uk \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.