Re: [PATCH v2 1/2] pid: Replace pid bitmap implementation with IDR API

From: Rik van Riel
Date: Mon Oct 02 2017 - 09:05:53 EST


On Sun, 2017-10-01 at 02:15 -0700, Christoph Hellwig wrote:
> > - task_active_pid_ns(current)->last_pid);
> > + task_active_pid_ns(current)->idr.idr_next-1);
>
> I think we want a well documented helper for this pattern instead
> of poking into the internals.
>
> Also is last - 1 always the correct answer?ÂÂEven with
> idr_alloc_cyclic
> we could wrap around, couldn't we?

Good point. I wonder if it makes sense to change the IDR
code, so idr_get_cursor returns the last allocated ID?

I see only two users of idr_get_cursor in the kernel,
and it looks like both would work fine if idr_get_cursor
returned the previously allocated value.

That would require a small change to idr_alloc_cyclic,
to have it start searching at a position one larger than
the cursor, and maybe renaming idr->idr_next to
idr->cursor, since it would now represent the last
value allocated, not the next.

Would that make sense?

--
All Rights Reversed.

Attachment: signature.asc
Description: This is a digitally signed message part