• Christoph Lameter's avatar
    SLUB: faster more efficient slab determination for __kmalloc · f1b26339
    Christoph Lameter authored
    kmalloc_index is a long series of comparisons.  The attempt to replace
    kmalloc_index with something more efficient like ilog2 failed due to compiler
    issues with constant folding on gcc 3.3 / powerpc.
    
    kmalloc_index()'es long list of comparisons works fine for constant folding
    since all the comparisons are optimized away.  However, SLUB also uses
    kmalloc_index to determine the slab to use for the __kmalloc_xxx functions.
    This leads to a large set of comparisons in get_slab().
    
    The patch here allows to get rid of that list of comparisons in get_slab():
    
    1. If the requested size is larger than 192 then we can simply use
       fls to determine the slab index since all larger slabs are
       of the power of two type.
    
    2. If the requested size is smaller then we cannot use fls since there
       are non power of two caches to be considered. However, the sizes are
       in a managable range. So we divide the size by 8. Then we have only
       24 possibilities left and then we simply look up the kmalloc index
       in a table.
    
    Code size of slub.o decreases by more than 200 bytes through this patch.
    Signed-off-by: default avatarChristoph Lameter <clameter@sgi.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    f1b26339
slub.c 88.6 KB