Re: xarray reserve/release?
From: Matthew Wilcox
Date: Wed Feb 20 2019 - 12:14:17 EST
On Tue, Feb 19, 2019 at 08:46:27PM -0700, Jason Gunthorpe wrote:
> On Tue, Feb 19, 2019 at 05:26:09PM -0800, Matthew Wilcox wrote:
> > On Tue, Feb 19, 2019 at 04:53:49PM -0700, Jason Gunthorpe wrote:
> > > Hey Matt,
> > >
> > > Did you intend that xa_release doesn't work on allocating arrays:
> >
> > That surprises me. I'll take a look in the morning.
>
> I think the issue is that this:
>
> static inline void xa_release(struct xarray *xa, unsigned long index)
> {
> xa_cmpxchg(xa, index, NULL, NULL, 0);
>
> relies on the NULL actually being xas_store(NULL), but cmpxchg
> transforms it into xas_store(XA_ZERO_ENTRY) when allocating..
Yes, you're right.
> So xa_reserve(), xa_release() and xa_cmpxchg() all do the same thing
> for allocating arrays.
>
> Perhaps this:
>
> void __xa_release(struct xarray *xa, unsigned long index)
> {
> XA_STATE(xas, xa, index);
> void *curr;
>
> curr = xas_load(&xas);
> if (curr == XA_ZERO_ENTRY)
> xas_store(&xas, NULL);
> }
>
> ?
I decided to instead remove the magic from xa_cmpxchg(). I used
to prohibit any internal entry being passed to the regular API, but
I recently changed that with 76b4e5299565 ("XArray: Permit storing
2-byte-aligned pointers"). Now that we can pass XA_ZERO_ENTRY, I
think this all makes much more sense.
> Also, I wonder if xa_reserve() is better written as as
>
> xa_cmpxchg(xa, index, NULL, XA_ZERO_ENTRY)
>
> Bit clearer what is going on..
Yes, I agree. I've pushed a couple of new commits to
http://git.infradead.org/users/willy/linux-dax.git/shortlog/refs/heads/xarray
which should fix your problem, and implement this optimisation.
Thanks for the report!