set SLAB_HWCACHE_ALIGN for kmalloc caches
RFC PATCH 1/1 set SLAB_HWCACHE_ALIGN for kmalloc caches
Hi,
The recent patches that changed the default alignment for slab caches affected the alignment of the kmalloc caches:
Initially the default was word alignment and it was increased for the kmalloc caches by setting SLAB_HWCACHE_ALIGN.
The "align" patch changed the default to cache line alignment and removed the SLAB_HWCACHE_ALIGN flag from the kmem_cache_create calls for kmalloc. But when the default was changed back to word alignment the flag was not reintroduced for kmalloc.
I think the kmalloc caches should remain cache line aligned: the object sizes are powers of two, so there is virtually no wasted memory. What about the attached patch? I've added an arch override, perhaps someone wants unaligned kmalloc caches (caused by word offsets for coloring instead of cache line offsets).
An arch override is definitively needed: One of SGI's drivers needs cache line alignment due to hardware constraints. --
Manfred
// $Header$
// Kernel Version:
// VERSION = 2 // PATCHLEVEL = 6 // SUBLEVEL = 6 // EXTRAVERSION = -mm5
mm/slab.c +10 -4
@@ -129,6 +129,10 @@#define ARCH_KMALLOC_MINALIGN 0#endif +#ifndef ARCH_KMALLOC_FLAGS +#define ARCH_KMALLOC_FLAGS SLAB_HWCACHE_ALIGN +#endif +/* Legal flag mask for kmem_cache_create(). */ #if DEBUG # define CREATE_MASK (SLAB_DEBUG_INITIAL | SLAB_RED_ZONE | \
@@ -756,7 +760,7 @@* allow tighter packing of the smaller caches. */ sizes->cs_cachep =kmem_cache_create ( names->name, sizes->cs_size, -ARCH_KMALLOC_MINALIGN ,0 ,NULL ,NULL ); +ARCH_KMALLOC_MINALIGN ,ARCH_KMALLOC_FLAGS ,NULL ,NULL );if (!sizes->cs_cachep)BUG ();
@@ -768,7 +772,8 @@ sizes->cs_dmacachep =kmem_cache_create ( names->name_dma, sizes->cs_size, -ARCH_KMALLOC_MINALIGN ,SLAB_CACHE_DMA ,NULL ,NULL ); +ARCH_KMALLOC_MINALIGN ,ARCH_KMALLOC_FLAGS |SLAB_CACHE_DMA , +NULL ,NULL );if (!sizes->cs_dmacachep)BUG ();
@@ -1118,8 +1123,9 @@* %SLAB_NO_REAP - Don't automatically reap this cache when we're under * memory pressure. * -* %SLAB_HWCACHE_ALIGN - This flag has no effect and will be removed soon. -* +* %SLAB_HWCACHE_ALIGN - Align the objects in this cache to a hardware +* cacheline. This can be beneficial if you're counting cycles as closely +* as davem. */ kmem_cache_t * kmem_cache_create (const char *name, size_t size, size_t align,
Quoted 2 lines · Manfred Spraul
I think the kmalloc caches should remain cache line aligned
I'm not so sure. size-64 is used a lot for out-of-line dentry names. Taking these up to 128 bytes or even more will consume considerable memory in some situations.
Quoted 12 lines · Andrew Morton
Quoted 3 lines · Manfred Spraul
I think the kmalloc caches should remain cache line aligned
I'm not so sure. size-64 is used a lot for out-of-line dentry names. Taking these up to 128 bytes or even more will consume considerable memory in some situations.
No, it won't:
Quoted 7 lines
/* Default alignment: as specified by the arch code.
* Except if an object is really small, then squeeze multiple
* into one cacheline.
*/
align = cache_line_size();
while (size <= align/2)
align /= 2;SLAB_HWCACHE_ALIGN is still just a hint, for small objects it's converted to alignment to a power of two boundary.
--
Manfred