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

Rik van Riel
2017-10-02T13:05:50Z

[-- Attachment #1: Type: text/plain, Size: 966 bytes --]

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 #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]