From: Matthew Wilcox <willy@infradead.org>
To: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Tejun Heo <tj@kernel.org>, Eric Biggers <ebiggers@google.com>,
Chris Mi <chrism@mellanox.com>,
dri-devel <dri-devel@lists.freedesktop.org>
Subject: Re: [RFC] Rebasing the IDR
Date: Thu, 30 Nov 2017 13:09:28 -0800 [thread overview]
Message-ID: <20171130210928.GA816@bombadil.infradead.org> (raw)
In-Reply-To: <CAKMK7uEKq-sM0iVXpOQ4MZzS1qA8w7=Z2ENQVTh+Gnq=0mcDng@mail.gmail.com>
On Thu, Nov 30, 2017 at 08:56:43PM +0100, Daniel Vetter wrote:
> Adding dri-devel, I think a pile of those are in drm.
Yeah, quite a lot! This is a good thing; means you didn't invent your
own custom ID allocator.
> On Thu, Nov 30, 2017 at 6:36 PM, Matthew Wilcox <willy@infradead.org> wrote:
> > About 40 of the approximately 180 users of the IDR in the kernel are
> > "1-based" instead of "0-based". That is, they never want to have ID 0
> > allocated; they want to see IDs allocated between 1 and N. Usually, that's
> > expressed like this:
> >
> > /* Get the user-visible handle using idr. */
> > ret = idr_alloc(&file_priv->object_idr, obj, 1, 0, GFP_KERNEL);
> >
> Just quick context on why we do this: We need to marshal/demarshal
> NULL in a ton of our ioctls, mapping that to 0 is natural.
Yep. You could actually store NULL at IDR index 0; the IDR distinguishes
between an allocated NULL and an unallocated entry.
> And yes I very much like this, and totally fine with trading an
> idr_init_base when we can nuke the explicit index ranges at every
> alloc side instead. So if you give me an idr_alloc function that
> doesn't take a range as icing, that would be great.
I think the API is definitely bad at making the easy things easy ... I'd
call the current idr_alloc() idr_alloc_range(). But I don't want to change
200+ call sites, so I'll settle for a new name.
ret = idr_get(&file_priv->object_idr, obj, GFP_KERNEL);
I have another new API in the works for after the xarray lands and we can
simplify the locking --
int __must_check idr_alloc_u32(struct idr *idr, void *ptr,
unsigned int *nextid, unsigned int max, gfp_t gfp)
The trick is that we store to nextid before inserting the ptr into the
xarray, so this will enable more users to dispense with their own locking
(or avoid awful i-looked-up-this-object-but-it's-not-initialised-so-
pretend-i-didn't-see-it dances).
(There's also an idr_alloc_ul for completeness, but I think this is
actually a bad idea; the radix tree gets pretty unwieldy at large sparse
indices and I don't want to encourage people to go outside unsigned int).
next prev parent reply other threads:[~2017-11-30 21:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-30 17:36 [RFC] Rebasing the IDR Matthew Wilcox
2017-11-30 19:56 ` Daniel Vetter
2017-11-30 21:09 ` Matthew Wilcox [this message]
2017-12-03 12:09 ` Daniel Vetter
2017-12-11 10:54 ` Chris Wilson
2018-02-09 19:46 ` Matthew Wilcox
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=20171130210928.GA816@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=chrism@mellanox.com \
--cc=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=ebiggers@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tj@kernel.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;
as well as URLs for NNTP newsgroup(s).