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

Matthew Dillon dillon at apollo.backplane.com
Mon Oct 8 09:45:47 PDT 2012


: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 at backplane.com>



More information about the Commits mailing list