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

Re: git: kmalloc: Use 'fls' to round up the size to the nearest power of 2


From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 8 Oct 2012 09:45:47 -0700 (PDT)

:http://gitweb.dragonflybsd.org/dragonfly.git/commitdiff/1e57f8673c953ace8a25ada0a39ab83008646ce3
:

    For cache alignment any allocation that is already a power of 2 will be
    at least that specific power-of-2 aligned.  Any allocation that is not
    a power of 2 will be aligned to the slab chunking:

 *      Alloc Size      Chunking        Number of zones
 *      0-127           8               16
 *      128-255         16              8
 *      256-511         32              8
 *      512-1023        64              8
 ...

    What this means is that in order to cache align an allocation you only
    need to do it for allocations < 256 bytes (if the cache line size is
    32 bytes).  Any allocation >= 256 bytes will be at least 32-byte aligned
    even if it is not a power of 2.

    So we don't necessarily need to enforce a power-of-2 size in all cases,
    only in cases where the allocation size < 256 bytes.

					-Matt
					Matthew Dillon 
					<dillon@backplane.com>



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