3 * Compare local cmpxchg with irq disable / enable with cmpxchg_local for slub.
7 #include <linux/jiffies.h>
8 #include <linux/compiler.h>
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/calc64.h>
12 #include <asm/timex.h>
13 #include <asm/system.h>
15 #define TEST_COUNT 10000
17 extern atomic_t slub_fast_count
;
18 extern atomic_t slub_slow_count
;
20 static int slub_test_init(void)
22 void **v
= kmalloc(TEST_COUNT
* sizeof(void *), GFP_KERNEL
);
24 cycles_t time1
, time2
, time
;
28 printk(KERN_ALERT
"test init\n");
30 printk("Fast slub free: %u\n", atomic_read(&slub_fast_count
));
31 printk("Slow slub free: %u\n", atomic_read(&slub_slow_count
));
32 printk(KERN_ALERT
"SLUB Performance testing\n");
33 printk(KERN_ALERT
"========================\n");
34 printk(KERN_ALERT
"1. Kmalloc: Repeatedly allocate then free test\n");
35 for (size
= 8; size
<= PAGE_SIZE
<< 2; size
<<= 1) {
37 for (i
= 0; i
< TEST_COUNT
; i
++) {
38 v
[i
] = kmalloc(size
, GFP_KERNEL
);
43 printk(KERN_ALERT
"%i times kmalloc(%d) = \n", i
, size
);
44 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
45 printk(KERN_ALERT
"total time: %llu\n", time
);
46 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
47 printk(KERN_ALERT
"-> %llu cycles\n", time
);
50 for (i
= 0; i
< TEST_COUNT
; i
++) {
56 printk(KERN_ALERT
"%i times kfree = \n", i
);
57 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
58 printk(KERN_ALERT
"total time: %llu\n", time
);
59 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
60 printk(KERN_ALERT
"-> %llu cycles\n", time
);
62 printk("Fast slub free: %u\n", atomic_read(&slub_fast_count
));
63 printk("Slow slub free: %u\n", atomic_read(&slub_slow_count
));
65 printk(KERN_ALERT
"2. Kmalloc: alloc/free test\n");
66 for (size
= 8; size
<= PAGE_SIZE
<< 2; size
<<= 1) {
68 for (i
= 0; i
< TEST_COUNT
; i
++) {
69 kfree(kmalloc(size
, GFP_KERNEL
));
74 printk(KERN_ALERT
"%i times kmalloc(%d)/kfree = \n", i
, size
);
75 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
76 printk(KERN_ALERT
"total time: %llu\n", time
);
77 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
78 printk(KERN_ALERT
"-> %llu cycles\n", time
);
80 printk("Fast slub free: %u\n", atomic_read(&slub_fast_count
));
81 printk("Slow slub free: %u\n", atomic_read(&slub_slow_count
));
83 printk(KERN_ALERT
"3. kmem_cache_alloc: Repeatedly allocate then free test\n");
84 for (size
= 3; size
<= PAGE_SHIFT
; size
++) {
86 for (i
= 0; i
< TEST_COUNT
; i
++) {
87 v
[i
] = kmem_cache_alloc(kmalloc_caches
+ size
, GFP_KERNEL
);
92 printk(KERN_ALERT
"%d times kmem_cache_alloc(%d) = \n", i
, 1 << size
);
93 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
94 printk(KERN_ALERT
"total time: %llu\n", time
);
95 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
96 printk(KERN_ALERT
"-> %llu cycles\n", time
);
99 for (i
= 0; i
< TEST_COUNT
; i
++) {
100 kmem_cache_free(kmalloc_caches
+ size
, v
[i
]);
102 time2
= get_cycles();
103 time
= time2
- time1
;
105 printk(KERN_ALERT
"%i times kmem_cache_free = \n", i
);
106 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
107 printk(KERN_ALERT
"total time: %llu\n", time
);
108 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
109 printk(KERN_ALERT
"-> %llu cycles\n", time
);
112 printk(KERN_ALERT
"4. kmem_cache_alloc: alloc/free test\n");
113 for (size
= 3; size
<= PAGE_SHIFT
; size
++) {
114 time1
= get_cycles();
115 for (i
= 0; i
< TEST_COUNT
; i
++) {
116 kmem_cache_free(kmalloc_caches
+ size
,
117 kmem_cache_alloc(kmalloc_caches
+ size
,
120 time2
= get_cycles();
121 time
= time2
- time1
;
123 printk(KERN_ALERT
"%d times kmem_cache_alloc(%d)/kmem_cache_free = \n", i
, 1 << size
);
124 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
125 printk(KERN_ALERT
"total time: %llu\n", time
);
126 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
127 printk(KERN_ALERT
"-> %llu cycles\n", time
);
129 printk(KERN_ALERT
"5. kmem_cache_zalloc: Repeatedly allocate then free test\n");
130 for (size
= 3; size
<= PAGE_SHIFT
; size
++) {
131 time1
= get_cycles();
132 for (i
= 0; i
< TEST_COUNT
; i
++) {
133 v
[i
] = kmem_cache_zalloc(kmalloc_caches
+ size
, GFP_KERNEL
);
135 time2
= get_cycles();
136 time
= time2
- time1
;
138 printk(KERN_ALERT
"%d times kmem_cache_zalloc(%d) = \n", i
, 1 << size
);
139 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
140 printk(KERN_ALERT
"total time: %llu\n", time
);
141 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
142 printk(KERN_ALERT
"-> %llu cycles\n", time
);
144 time1
= get_cycles();
145 for (i
= 0; i
< TEST_COUNT
; i
++) {
146 kmem_cache_free(kmalloc_caches
+ size
, v
[i
]);
148 time2
= get_cycles();
149 time
= time2
- time1
;
151 printk(KERN_ALERT
"%i times kmem_cache_free = \n", i
);
152 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
153 printk(KERN_ALERT
"total time: %llu\n", time
);
154 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
155 printk(KERN_ALERT
"-> %llu cycles\n", time
);
158 printk(KERN_ALERT
"6. kmem_cache_zalloc: alloc/free test\n");
159 for (size
= 3; size
<= PAGE_SHIFT
; size
++) {
160 time1
= get_cycles();
161 for (i
= 0; i
< TEST_COUNT
; i
++) {
162 kmem_cache_free(kmalloc_caches
+ size
,
163 kmem_cache_zalloc(kmalloc_caches
+ size
,
166 time2
= get_cycles();
167 time
= time2
- time1
;
169 printk(KERN_ALERT
"%d times kmem_cache_zalloc(%d)/kmem_cache_free = \n", i
, 1 << size
);
170 printk(KERN_ALERT
"number of loops: %d\n", TEST_COUNT
);
171 printk(KERN_ALERT
"total time: %llu\n", time
);
172 time
= div_long_long_rem(time
, TEST_COUNT
, &rem
);
173 printk(KERN_ALERT
"-> %llu cycles\n", time
);
178 return -EAGAIN
; /* Fail will directly unload the module */
181 static void slub_test_exit(void)
183 printk(KERN_ALERT
"test exit\n");
186 module_init(slub_test_init
)
187 module_exit(slub_test_exit
)
189 MODULE_LICENSE("GPL");
190 MODULE_AUTHOR("Mathieu Desnoyers");
191 MODULE_DESCRIPTION("SLUB test");
This page took 0.037338 seconds and 4 git commands to generate.