Messages in this thread Patch in this message | | | Date | Wed, 26 Jul 2006 14:16:06 +0300 (EEST) | From | Pekka J Enberg <> | Subject | Re: [patch 2/2] slab: always consider arch mandated alignment |
| |
On Wed, 26 Jul 2006, Heiko Carstens wrote: > We only specify ARCH_KMALLOC_MINALIGN, since that aligns only the kmalloc > caches, but it doesn't disable debugging on other caches that are created > via kmem_cache_create() where an alignment of e.g. 0 is specified. > > The point of the first patch is: why should the slab cache be allowed to chose > an aligment that is less than what the caller specified? This does very likely > break things.
Ah, yes, you are absolutely right. We need to respect caller mandated alignment too. How about this?
Pekka
[PATCH] slab: respect architecture and caller mandated alignment
Ensure cache alignment is always at minimum what the architecture or caller mandates even if slab debugging is enabled.
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi> ---
diff --git a/mm/slab.c b/mm/slab.c index 0f20843..3767460 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -2097,6 +2097,15 @@ #endif } else { ralign = BYTES_PER_WORD; } + + /* + * Redzoning and user store require word alignment. Note this will be + * overridden by architecture or caller mandated alignment if either + * is greater than BYTES_PER_WORD. + */ + if (flags & SLAB_RED_ZONE || flags & SLAB_STORE_USER) + ralign = BYTES_PER_WORD; + /* 2) arch mandated alignment: disables debug if necessary */ if (ralign < ARCH_SLAB_MINALIGN) { ralign = ARCH_SLAB_MINALIGN; @@ -2123,20 +2132,19 @@ #endif #if DEBUG cachep->obj_size = size; + /* + * Both debugging options require word-alignment which is calculated + * into align above. + */ if (flags & SLAB_RED_ZONE) { - /* redzoning only works with word aligned caches */ - align = BYTES_PER_WORD; - /* add space for red zone words */ cachep->obj_offset += BYTES_PER_WORD; size += 2 * BYTES_PER_WORD; } if (flags & SLAB_STORE_USER) { - /* user store requires word alignment and - * one word storage behind the end of the real - * object. + /* user store requires one word storage behind the end of + * the real object. */ - align = BYTES_PER_WORD; size += BYTES_PER_WORD; } #if FORCED_DEBUG && defined(CONFIG_DEBUG_PAGEALLOC) - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
| |