From 022fcc44c5059e7debf3b2442b554ee0bc36212a Mon Sep 17 00:00:00 2001 From: Christoph Lameter Date: Sat, 28 Jul 2007 12:35:30 -0700 Subject: [PATCH] Simple Performance Counters: SLUB instrumentation With this patch SLUB will perform tests on bootup and display results. Signed-off-by: Christoph Lameter --- mm/slub.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 92 insertions(+), 5 deletions(-) Index: linux-2.6/mm/slub.c =================================================================== --- linux-2.6.orig/mm/slub.c 2007-07-28 22:42:49.000000000 -0700 +++ linux-2.6/mm/slub.c 2007-07-28 22:44:21.000000000 -0700 @@ -20,6 +20,7 @@ #include #include #include +#include /* * Lock order: @@ -152,6 +153,7 @@ static inline void ClearSlabDebug(struct /* Enable to test recovery from slab corruption on boot */ #undef SLUB_RESILIENCY_TEST +#undef SLUB_PERFORMANCE_TEST #if PAGE_SHIFT <= 12 @@ -2869,9 +2871,97 @@ static long validate_slab_cache(struct k return count; } -#ifdef SLUB_RESILIENCY_TEST static void resiliency_test(void) { +#ifdef SLUB_PERFORMANCE_TEST +#define TEST_COUNT 10000 + int size, i; + struct pc x; + void **v = kmalloc(TEST_COUNT * sizeof(void *), GFP_KERNEL); + + printk(KERN_INFO "SLUB Performance testing\n"); + printk(KERN_INFO "========================\n"); + printk(KERN_INFO "1. Kmalloc: Repeatedly allocate then free test\n"); + for (size = 8; size <= PAGE_SIZE << 2; size <<= 1) { + pc_start(&x); + for(i = 0; i < TEST_COUNT; i++) { + v[i] = kmalloc(size, GFP_KERNEL); + } + printk(KERN_INFO "%i times kmalloc(%d) = ", i, size); + pc_stop_printk(&x); + pc_start(&x); + for(i = 0; i < TEST_COUNT; i++) + kfree(v[i]); + printk(" kfree() = "); + pc_stop_printk(&x); + printk("\n"); + } + + printk(KERN_INFO "2. Kmalloc: alloc/free test\n"); + for (size = 8; size <= PAGE_SIZE << 2; size <<= 1) { + pc_start(&x); + for(i = 0; i < TEST_COUNT; i++) + kfree(kmalloc(size, GFP_KERNEL)); + printk(KERN_INFO "%i times kmalloc(%d)/kfree = ", i, size); + pc_stop_printk(&x); + printk("\n"); + } + printk(KERN_INFO "3. kmem_cache_alloc: Repeatedly allocate then free test\n"); + for (size = 3; size <= PAGE_SHIFT; size ++) { + pc_start(&x); + for(i = 0; i < TEST_COUNT; i++) { + v[i] = kmem_cache_alloc(kmalloc_caches + size, GFP_KERNEL); + } + printk(KERN_INFO "%d times kmem_cache_alloc(%d) = ", i, 1 << size); + pc_stop_printk(&x); + pc_start(&x); + for(i = 0; i < TEST_COUNT; i++) + kmem_cache_free(kmalloc_caches + size, v[i]); + printk(" kmem_cache_free() = "); + pc_stop_printk(&x); + printk("\n"); + } + + printk(KERN_INFO "4. kmem_cache_alloc: alloc/free test\n"); + for (size = 3; size <= PAGE_SHIFT; size++) { + pc_start(&x); + for(i = 0; i < TEST_COUNT; i++) + kmem_cache_free(kmalloc_caches + size, + kmem_cache_alloc(kmalloc_caches + size, + GFP_KERNEL)); + printk(KERN_INFO "%d times kmem_cache_alloc(%d)/kmem_cache_free = ", i, 1 << size); + pc_stop_printk(&x); + printk("\n"); + } + printk(KERN_INFO "5. kmem_cache_zalloc: Repeatedly allocate then free test\n"); + for (size = 3; size <= PAGE_SHIFT; size ++) { + pc_start(&x); + for(i = 0; i < TEST_COUNT; i++) { + v[i] = kmem_cache_zalloc(kmalloc_caches + size, GFP_KERNEL); + } + printk(KERN_INFO "%d times kmem_cache_zalloc(%d) = ", i, 1 << size); + pc_stop_printk(&x); + pc_start(&x); + for(i = 0; i < TEST_COUNT; i++) + kmem_cache_free(kmalloc_caches + size, v[i]); + printk(" kmem_cache_free() = "); + pc_stop_printk(&x); + printk("\n"); + } + + printk(KERN_INFO "6. kmem_cache_zalloc: alloc/free test\n"); + for (size = 3; size <= PAGE_SHIFT; size++) { + pc_start(&x); + for(i = 0; i < TEST_COUNT; i++) + kmem_cache_free(kmalloc_caches + size, + kmem_cache_zalloc(kmalloc_caches + size, + GFP_KERNEL)); + printk(KERN_INFO "%d times kmem_cache_zalloc(%d)/kmem_cache_free = ", i, 1 << size); + pc_stop_printk(&x); + printk("\n"); + } +#endif +#ifdef SLUB_RESILIENCY_TEST u8 *p; printk(KERN_ERR "SLUB resiliency testing\n"); @@ -2919,11 +3009,8 @@ static void resiliency_test(void) p[512] = 0xab; printk(KERN_ERR "\n3. kmalloc-512: Clobber redzone 0xab->0x%p\n\n", p); validate_slab_cache(kmalloc_caches + 9); -} -#else -static void resiliency_test(void) {}; #endif - +} /* * Generate lists of code addresses where slabcache objects are allocated * and freed.