DragonFly commits List (threaded) for 2012-10
Re: git: kmalloc: Add kmalloc_powerof2() and kmalloc_cachealign()
On Sat, Oct 6, 2012 at 9:42 PM, Sepherosa Ziehau
> commit 55126ffeefe32fac458f727ce228b9ea3320ac6a
> Author: Sepherosa Ziehau <firstname.lastname@example.org>
> Date: Sun Oct 7 12:14:52 2012 +0800
> kmalloc: Add kmalloc_powerof2() and kmalloc_cachealign()
> Ensures that the returned address will be power of 2 aligned.
> These two function probably should _not_ be used on the hot code path
> due to the computational cost to find the nearest power of 2 size.
The core of kmalloc_powerof2()'s nearest-power-of-2 could probably look like:
int i, wt;
unsigned long j;
i = flsl(size_alloc);
wt = (size_alloc & ~(1 << (i - 1)));
if (!wt) --i;
j = (1 << i);
instead of the existing loop. It might be a bit faster/more-suitable
I also would expose this as another kmalloc M_* flag, instead of
another function; but that is just an opinion...