nmalloc - Further optimize posix_memalign()
authorMatthew Dillon <dillon@apollo.backplane.com>
Thu, 30 Apr 2009 03:07:07 +0000 (20:07 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Thu, 30 Apr 2009 03:07:07 +0000 (20:07 -0700)
commit8ff099aed96957a9a33da8f0a729263c4bac2bc3
treece1403198fa5339bf10b9aac83e88775af239c7c
parent85a8e8a761ebbbe3c89eac489ab13089d54d5be5
nmalloc - Further optimize posix_memalign()

Align the requested size to the nearest alignment to improve our chances
of coming up with a power-of-2.

Greatly improve the fitting algorithm for oddly sized requests, e.g.

(1) 32 byte alignment on a 1026 size.  In this case the zone for 1026
    already has a chunking (128) that exceeds the requested alignment,
    so we just do a _slaballoc().

(2) A 256 byte alignment on a 513 byte size.  In this case the zone
    for 513 has a chunking of 64, which is not sufficient, so we
    find the nearest power-of-2 >= 513 and allocate that.  In our
    case we would find 1024.  Since _slaballoc() guarantees that
    power-of-2 allocations within the zone limit will be on the
    same-sized boundary, we then just allocate the nearest power of 2.
lib/libc/stdlib/nmalloc.c