Twenty Three Microseconds Gone

Bonwick measured the cost of allocating and freeing one stream head in the SunOS kernel, before and after the slab allocator:

allocator construction + destruction memory allocation other init total
old 23.6 us 9.4 us 1.9 us 34.9 us
slab 0.0 us 3.8 us 1.9 us 5.7 us

Which change accounts for most of the improvement?

A

Fixed-size slabs removed external fragmentation, so more requests were satisfied from pages that were already mapped.

B

Per-cache freelists made the raw memory allocation itself much cheaper, from 9.4 us down to 3.8 us.

C

Objects are handed back to the cache in their constructed state and handed out again without being rebuilt, so the mutex and condition variable inside each object are initialized once instead of on every use.

D

Slab colouring spread objects across cache lines, so the same code touched fewer conflicting lines and ran faster.