From 0579dcb2417b4950db3405a8b6c823450772e6d3 Mon Sep 17 00:00:00 2001 From: Christoph Lameter Date: Mon, 7 Jan 2008 14:18:24 -0800 Subject: [PATCH 04/22] VM test: Add capability to test 1 alloc N free Add another test to measure performance if objects are allocated on a single processor but are freed fast on remote processors. This mimicks hackbench and can produce larger regressions than hackbench. Signed-off-by: Christoph Lameter --- tests/slub_test.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/slub_test.c b/tests/slub_test.c index d9a4fbf..64ba3b6 100644 --- a/tests/slub_test.c +++ b/tests/slub_test.c @@ -83,6 +83,45 @@ static void remote_free_test_p2(struct test_struct *t) } /* + * Allocate TEST_COUNT objects on cpu 0 and free them immediately on the + * other processors. + */ +static void alloc_n_free_test_p1(struct test_struct *t) +{ + int i; + int cpu; + char *p; + + if (smp_processor_id()) { + /* Consumer */ + for (i = 0; i < t->count / num_online_cpus(); i++) { +// printk("alloc_n_free cpu=%d i=%d\n", smp_processor_id(), i); + do { + p = t->v[i]; + if (!p) + cpu_relax(); + else + *p = 17; + } while (!p); + kfree(p); + t->v[i] = NULL; + } + return; + } + /* Producer */ + for (i = 0; i < t->count; i++) { + for_each_online_cpu(cpu) { + if (cpu) { + p = kmalloc(t->size, GFP_KERNEL); + /* Use object */ + *p = 17; + test[cpu].v[i] = p; + } + } + } +} + +/* * Allocate TEST_COUNT objects and later free them all again */ static void kmalloc_alloc_then_free_test_p1(struct test_struct *t) @@ -137,7 +176,7 @@ static int test_func(void *private) cpu_set(t->cpu, newmask); set_cpus_allowed(current, newmask); - t->v = kmalloc(t->count * sizeof(void *), GFP_KERNEL); + t->v = kzalloc(t->count * sizeof(void *), GFP_KERNEL); atomic_inc(&tests_running); wait_for_completion(&completion1); @@ -310,8 +349,15 @@ static int slub_test_init(void) 1 << i, "N*remote free"); } -#endif + printk(KERN_INFO "1 alloc N free test\n"); + printk(KERN_INFO "===================\n"); + for (i = 3; i <= PAGE_SHIFT; i++) { + do_concurrent_test(alloc_n_free_test_p1, + NULL, + 1 << i, "1 alloc N free"); + } +#endif return -EAGAIN; /* Fail will directly unload the module */ } -- 1.6.4.3