From addee8626472bc3b4cc234d5ea8b32dc382934df Mon Sep 17 00:00:00 2001 From: Christoph Lameter Date: Mon, 17 Mar 2008 00:46:18 -0700 Subject: [PATCH] slub: Do not align on UP systems If we do not have an smp system then alignment to a cacheline via SLAB_HWCACHE_ALIGN is not useful. SLAB_HWCACHE_ALIGN is already fuzzy because the slab allocators may choose not to align each object to cacheline boundaries if they are small. So optimize it further by making another exception for systems that have only a single processor. This will pack the data more densely on UP and may save some more memory. Signed-off-by: Christoph Lameter --- include/linux/slab.h | 2 +- mm/slub.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/slab.h b/include/linux/slab.h index f62caaa..c5ce876 100644 --- a/include/linux/slab.h +++ b/include/linux/slab.h @@ -21,7 +21,7 @@ #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */ #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */ #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */ -#define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */ +#define SLAB_HWCACHE_ALIGN 0x00002000UL /* Optimize object alignment */ #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */ #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */ #define SLAB_PANIC 0x00040000UL /* Panic if kmem_cache_create() fails */ diff --git a/mm/slub.c b/mm/slub.c index ca71d5b..319a9fc 100644 --- a/mm/slub.c +++ b/mm/slub.c @@ -1862,7 +1862,7 @@ static unsigned long calculate_alignment(unsigned long flags, * The hardware cache alignment cannot override the specified * alignment though. If that is greater then use it. */ - if (flags & SLAB_HWCACHE_ALIGN) { + if ((flags & SLAB_HWCACHE_ALIGN) && nr_cpu_ids > 1) { unsigned long ralign = cache_line_size(); while (size <= ralign / 2) ralign /= 2; -- 1.5.4.1