DragonFly BSD
DragonFly commits List (threaded) for 2012-10
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

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


From: Venkatesh Srinivas <vsrinivas@xxxxxxxxxx>
Date: Sun, 7 Oct 2012 05:18:34 -0700

On Sat, Oct 6, 2012 at 9:42 PM, Sepherosa Ziehau
<sephe@crater.dragonflybsd.org> wrote:
>
> commit 55126ffeefe32fac458f727ce228b9ea3320ac6a
> Author: Sepherosa Ziehau <sephe@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/



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]