Skip to contentSkip to conversation

slub: Do not use 192 byte sized cache if minimum alignment is 128 byte

PATCH Christoph Lameter 3 participants 5 messages Jul 3, 2008 – Jul 4, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

The 192 byte cache is not necessary if we have a basic alignment of 128 byte. If it would be used then the 192 would be aligned to the next 128 byte boundary which would result in another 256 byte cache. Two 256 kmalloc caches cause sysfs to complain about a duplicate entry.

MIPS needs 128 byte aligned kmalloc caches and spits out warnings on boot without this patch.

include/linux/slub_def.h +2 -0
Index: linux-2.6/include/linux/slub_def.h
===================================================================
@@ -137,10 +137,12 @@
 	if (size <= KMALLOC_MIN_SIZE)
 		return KMALLOC_SHIFT_LOW;
 
+#if KMALLOC_MIN_SIZE <= 64
 	if (size > 64 && size <= 96)
 		return 1;
 	if (size > 128 && size <= 192)
 		return 2;
+#endif
 	if (size <=          8) return 3;
 	if (size <=         16) return 4;
 	if (size <=         32) return 5;
mm/slub.c +10 -2
Index: linux-2.6/mm/slub.c
===================================================================
@@ -2995,8 +2995,6 @@
 		create_kmalloc_cache(&kmalloc_caches[1],
 				"kmalloc-96", 96, GFP_KERNEL);
 		caches++;
-	}
-	if (KMALLOC_MIN_SIZE <= 128) {
 		create_kmalloc_cache(&kmalloc_caches[2],
 				"kmalloc-192", 192, GFP_KERNEL);
 		caches++;
@@ -3026,6 +3024,16 @@
 	for (i = 8; i < KMALLOC_MIN_SIZE; i += 8)
 		size_index[(i - 1) / 8] = KMALLOC_SHIFT_LOW;
 
+	if (KMALLOC_MIN_SIZE == 128) {
+		/*
+		 * The 192 byte sized cache is not used if the alignment
+		 * is 128 byte. Redirect kmalloc to use the 256 byte cache
+		 * instead.
+		 */
+		for (i = 128 + 8; i <= 192; i += 8)
+			size_index[(i - 1) / 8] = 8;
+	}
+
 	slab_state = UP;
 
 	/* Provide the correct kmalloc names now that the caches are up */
#1 lore raw
Quoted 9 lines · Christoph Lameter

The 192 byte cache is not necessary if we have a basic alignment of 128 byte. If it would be used then the 192 would be aligned to the next 128 byte boundary which would result in another 256 byte cache. Two 256 kmalloc caches cause sysfs to complain about a duplicate entry.

MIPS needs 128 byte aligned kmalloc caches and spits out warnings on boot without this patch.

Looks good to me. Yoichi, did you have the chance to test this? Christoph, are the warnings harmless or do we need to get this into 2.6.26?

#3 lore raw
In reply to Pekka Enberg
Quoted 7 lines · On Thu, 3 Jul 2008 18:37:52 +0300 "Pekka Enberg" <[email protected]> wrote:
Quoted 5 lines · Christoph Lameter

The 192 byte cache is not necessary if we have a basic alignment of 128 byte. If it would be used then the 192 would be aligned to the next 128 byte boundary which would result in another 256 byte cache. Two 256 kmalloc caches cause sysfs to complain about a duplicate entry.

Quoted 6 lines
Quoted 4 lines

MIPS needs 128 byte aligned kmalloc caches and spits out warnings on boot without this patch.

Looks good to me. Yoichi, did you have the chance to test this?

I've already done.
It has no problem.

Yoichi

#4 lore raw

Hi Yoichi,

Quoted 9 lines · Christoph Lameter
Quoted 9 lines
Quoted 9 lines

The 192 byte cache is not necessary if we have a basic alignment of 128 byte. If it would be used then the 192 would be aligned to the next 128 byte boundary which would result in another 256 byte cache. Two 256 kmalloc caches cause sysfs to complain about a duplicate entry.

MIPS needs 128 byte aligned kmalloc caches and spits out warnings on boot without this patch.

Quoted 1 line · On Thu, 3 Jul 2008 18:37:52 +0300 "Pekka Enberg" <[email protected]> wrote:
Quoted 1 line

Looks good to me. Yoichi, did you have the chance to test this?

Quoted 2 lines · Yoichi Yuasa

I've already done.
It has no problem.

Thank you for testing!