All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-fsdevel@vger.kernel.org, Nicolin Chen <nicolinc@nvidia.com>
Subject: Re: xa_cmpxchg and XA_ZERO_ENTRY?
Date: Wed, 30 Oct 2024 14:21:48 -0300	[thread overview]
Message-ID: <20241030172148.GH6956@nvidia.com> (raw)
In-Reply-To: <ZyJkHHUSyVgO419i@casper.infradead.org>

On Wed, Oct 30, 2024 at 04:51:40PM +0000, Matthew Wilcox wrote:
> On Wed, Oct 30, 2024 at 10:15:13AM -0300, Jason Gunthorpe wrote:
> > Hi Matthew,
> > 
> > Nicolin pointed this out and I was wondering what is the right thing.
> > 
> > For instance this:
> > 
> > 	xa_init(&xa);
> > 	ret = xa_reserve(&xa, 1, GFP_KERNEL);
> > 	printk("xa_reserve() = %d\n", ret);
> > 	old = xa_cmpxchg(&xa, 1, NULL, &xa, GFP_KERNEL);
> 
> You're really not supposed to be doing xa_cmpxchg() here.  Just use
> xa_store().  That's the intended way to use these APIs.

xa_store() also looses the XA_ZERO_ENTRY, it doesn't help to write an
assertion that the index was reserved.

> > The general purpose of code like the above is to just validate that
> > the xa has not been corrupted, that the index we are storing to has
> > been reserved. Maybe we can't sleep or something.
> 
> Thr intent is to provide you with an array abstraction.  You don't
> cmpxchg() pointers into an array, do you?  Almost everybody just does
> array[i] = p.

Sort of, what is desired here is test and store, not cmpxchg. You
would do that in normal arrays:

 if (WARN_ON(array[i] == NULL)
     return;
 array[i] = foo;

In xarray it would be nice to do both those under a single walk and
lock.

Jason

      reply	other threads:[~2024-10-30 17:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-30 13:15 xa_cmpxchg and XA_ZERO_ENTRY? Jason Gunthorpe
2024-10-30 16:51 ` Matthew Wilcox
2024-10-30 17:21   ` Jason Gunthorpe [this message]

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=20241030172148.GH6956@nvidia.com \
    --to=jgg@nvidia.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=nicolinc@nvidia.com \
    --cc=willy@infradead.org \
    /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.