Re: [PATCH v1 1/6] idr: introduce idr_alloc_cyclic

From: Tejun Heo
Date: Wed Mar 27 2013 - 12:26:05 EST


Hello, Jeff.

On Wed, Mar 27, 2013 at 09:18:03AM -0400, Jeff Layton wrote:
> + * Note that people using cyclic allocation to avoid premature reuse of an
> + * already-used ID may be in for a nasty surprise after idr->cur wraps. The
> + * IDR code is designed to avoid unnecessary allocations. If there is space
> + * in an existing layer that holds high IDs then it will return one of those
> + * instead of allocating a new layer at the bottom of the range.

Ooh, does it? Where?

> +int idr_alloc_cyclic(struct idr *idr, void *ptr, int start, int end,
> + gfp_t gfp_mask)
> +{
> + int id;
> + int cur = idr->cur;
> +
> + if (unlikely(start > cur))
> + cur = start;
> +
> + id = idr_alloc(idr, ptr, cur, end, gfp_mask);

Would max(id->cur, start) be easier to follow?

> + if (id == -ENOSPC)
> + id = idr_alloc(idr, ptr, start, end, gfp_mask);
> +
> + if (likely(id >= 0))
> + idr->cur = id + 1;

If @id is INT_MAX, idr->cur will be -1 which is okay as start > cur
test above will correct it on the next iteration but maybe we can do
idr->cur = max(id + 1, 0); for clarity?

Both my points are cosmetic and the patch looks good to me.

Reviewed-by: Tejun Heo <tj@xxxxxxxxxx>

Thanks!

--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/