From: "Fabio M. De Francesco" <fmdefrancesco@gmail.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: outreachy-kernel@googlegroups.com, linux-staging@lists.linux.dev,
linux-kernel@vger.kernel.org,
David Kershner <david.kershner@unisys.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Daniel Vetter <daniel@ffwll.ch>
Subject: Re: [Outreachy kernel] [RFC PATCH] staging: unisys: visorhba: Convert module from IDR to XArray
Date: Mon, 26 Apr 2021 15:50:06 +0200 [thread overview]
Message-ID: <2352794.1zacegZ1vs@linux.local> (raw)
In-Reply-To: <20210426132928.GL235567@casper.infradead.org>
On Monday, April 26, 2021 3:29:28 PM CEST Matthew Wilcox wrote:
> On Mon, Apr 26, 2021 at 03:14:42PM +0200, Fabio M. De Francesco wrote:
> > > > - int id;
> > > > - unsigned long flags;
> > > >
> > > > - idr_preload(GFP_KERNEL);
> > > > - spin_lock_irqsave(lock, flags);
> > > > - id = idr_alloc(idrtable, p, 1, INT_MAX, GFP_NOWAIT);
> > > > - spin_unlock_irqrestore(lock, flags);
> > > > - idr_preload_end();
> > > > - /* failure */
> > > > - if (id < 0)
> > > > - return 0;
> > > > - /* idr_alloc() guarantees > 0 */
> > > > - return (unsigned int)(id);
> > >
> > > And it shouldn't be using GFP_NOWAIT, but GFP_KERNEL, like the IDR code
> > > used to do.
> >
> > I'm not sure to understand why idr_preload() uses GFP_KERNEL and instead
> > idr_alloc() uses GFP_NOWAIT. I'd better read anew the documentation of the
> > above-mentioned functions
>
> If you're holding a spinlock, you can't do a GFP_KERNEL allocation,
> because it can sleep, and sleeping while holding a spinlock isn't allowed.
>
I know that since a long time... that is last week, day more day less :)
I've just started to read R.Love's LKD 3rd ed. I don't have enough time to
read it at the moment, however I skipped a few chapters and read "Kernel
synchronization methods" and "Memory management".
>
> The IDR and radix tree have an approach where you first preallocate
> memory using GFP_KERNEL and then use GFP_NOWAIT or GFP_ATOMIC after
> you've taken the spinlock. XArray doesn't do that; it takes the spinlock
> and does a GFP_NOWAIT allocation. If it fails, it drops the spinlock,
> allocates the memory using GFP_KERNEL, and retries.
>
This is something one cannot find in Love's book, unless I overlooked that.
>
> > This will not be anymore a problem when I'll restore the use of one
namespace
> > per HBA. It's correct?
>
> true ...
>
> > > More generally, the IDR required you call idr_destroy() to avoid leaking
> > > preallocated memory. I changed that, but there are still many drivers
> > > that have unnecessary calls to idr_destroy(). It's good form to just
> > > delete them and not turn them into calls to xa_destroy().
> >
> > This one is a bit obscure to me. I have to look into it more carefully.
Maybe
> > I'll ask for some further help.
>
> The IDR used to have a per-idr preallocation, so you had to destroy it
> in order to make sure they were freed. I got rid of that about five
> years ago because most IDR users weren't calling idr_destroy().
>
OK, I think I got it.
>
Thanks again,
Fabio
prev parent reply other threads:[~2021-04-26 13:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-26 9:50 [Outreachy kernel] [RFC PATCH] staging: unisys: visorhba: Convert module from IDR to XArray Fabio M. De Francesco
2021-04-26 9:56 ` Greg Kroah-Hartman
2021-04-26 10:39 ` Fabio M. De Francesco
2021-04-26 10:42 ` Julia Lawall
2021-04-26 10:07 ` Julia Lawall
2021-04-26 11:49 ` Matthew Wilcox
2021-04-26 13:14 ` Fabio M. De Francesco
2021-04-26 13:29 ` Matthew Wilcox
2021-04-26 13:50 ` Fabio M. De Francesco [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=2352794.1zacegZ1vs@linux.local \
--to=fmdefrancesco@gmail.com \
--cc=daniel@ffwll.ch \
--cc=david.kershner@unisys.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=outreachy-kernel@googlegroups.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox