* [RFC, PATCH] set SLAB_HWCACHE_ALIGN for kmalloc caches
@ 2004-05-28 20:47 Manfred Spraul
2004-05-28 23:25 ` Andrew Morton
0 siblings, 1 reply; 3+ messages in thread
From: Manfred Spraul @ 2004-05-28 20:47 UTC (permalink / raw)
To: linux-kernel; +Cc: Dean Nelson
[-- Attachment #1: Type: text/plain, Size: 942 bytes --]
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
[-- Attachment #2: patch-slab-kmallocalign --]
[-- Type: text/plain, Size: 1509 bytes --]
// $Header$
// Kernel Version:
// VERSION = 2
// PATCHLEVEL = 6
// SUBLEVEL = 6
// EXTRAVERSION = -mm5
--- 2.6/mm/slab.c 2004-05-23 21:11:54.000000000 +0200
+++ build-2.6/mm/slab.c 2004-05-28 22:14:36.000000000 +0200
@@ -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,
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [RFC, PATCH] set SLAB_HWCACHE_ALIGN for kmalloc caches
2004-05-28 20:47 [RFC, PATCH] set SLAB_HWCACHE_ALIGN for kmalloc caches Manfred Spraul
@ 2004-05-28 23:25 ` Andrew Morton
2004-05-29 6:57 ` Manfred Spraul
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2004-05-28 23:25 UTC (permalink / raw)
To: Manfred Spraul; +Cc: linux-kernel, dcn
Manfred Spraul <manfred@colorfullife.com> wrote:
>
> 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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC, PATCH] set SLAB_HWCACHE_ALIGN for kmalloc caches
2004-05-28 23:25 ` Andrew Morton
@ 2004-05-29 6:57 ` Manfred Spraul
0 siblings, 0 replies; 3+ messages in thread
From: Manfred Spraul @ 2004-05-29 6:57 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-kernel, dcn
Andrew Morton wrote:
>Manfred Spraul <manfred@colorfullife.com> wrote:
>
>
>>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:
> /* 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-05-29 6:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-05-28 20:47 [RFC, PATCH] set SLAB_HWCACHE_ALIGN for kmalloc caches Manfred Spraul
2004-05-28 23:25 ` Andrew Morton
2004-05-29 6:57 ` Manfred Spraul
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox