[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130326152653.GA3061@htj.dyndns.org>
Date: Tue, 26 Mar 2013 08:26:53 -0700
From: Tejun Heo <tj@...nel.org>
To: Jeff Layton <jlayton@...hat.com>
Cc: "J. Bruce Fields" <bfields@...ldses.org>,
akpm@...ux-foundation.org, linux-kernel@...r.kernel.org,
rusty@...tcorp.com.au, skinsbursky@...allels.com,
ebiederm@...ssion.com, jmorris@...ei.org, axboe@...nel.dk
Subject: Re: [PATCHSET] idr: implement idr_alloc() and convert existing users
Hello, Jeff.
On Tue, Mar 26, 2013 at 11:19:36AM -0400, Jeff Layton wrote:
> +/**
> + * idr_alloc_cyclic - allocate new idr entry in a cyclical fashion
> + * @idr: the (initialized) idr
> + * @ptr: pointer to be associated with the new id
> + * @start: the minimum id (inclusive)
> + * @end: the maximum id (exclusive, <= 0 for max)
> + * @cur: ptr to current position in the range (typically, last allocated + 1)
> + * @gfp_mask: memory allocation flags
> + *
> + * Essentially the same as idr_alloc, but prefers to allocate progressively
> + * higher ids if it can. If the "cur" counter wraps, then it will start again
> + * at the "start" end of the range and allocate one that has already been used.
> + */
> +int idr_alloc_cyclic(struct idr *idr, void *ptr, int start, int end, int *cur,
> + gfp_t gfp_mask)
> +{
> + int id;
> +
> + id = idr_alloc(idr, ptr, *cur, end, gfp_mask);
> + if (id == -ENOSPC)
> + id = idr_alloc(idr, ptr, start, end, gfp_mask);
> +
> + if (likely(id >= 0))
> + *cur = id + 1;
> + return id;
> +}
Wouldn't it be better if idr itself could remember the last position?
Also, @start/@end should always be honored even if, say, @start moves
above the last position. Other than that, yeah.
Thanks.
--
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists