git: kmalloc: Add kmalloc_powerof2() and kmalloc_cachealign()

Venkatesh Srinivas vsrinivas at ops101.org
Sun Oct 7 05:18:34 PDT 2012


On Sat, Oct 6, 2012 at 9:42 PM, Sepherosa Ziehau
<sephe at crater.dragonflybsd.org> wrote:
>
> commit 55126ffeefe32fac458f727ce228b9ea3320ac6a
> Author: Sepherosa Ziehau <sephe at dragonflybsd.org>
> Date:   Sun Oct 7 12:14:52 2012 +0800
>
>     kmalloc: Add kmalloc_powerof2() and kmalloc_cachealign()
>
>     kmalloc_powerof2()
>         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);
  return (j);
}

instead of the existing loop. It might be a bit faster/more-suitable
in hotter-paths.

I also would expose this as another kmalloc M_* flag, instead of
another function; but that is just an opinion...

Thanks!
-- vs;
http://ops101.org/4k/



More information about the Commits mailing list