]> git.proxmox.com Git - mirror_spl.git/blob - module/splat/splat-kmem.c
81f748bb6256d2a52709670730e9bbfa85b6c2c0
[mirror_spl.git] / module / splat / splat-kmem.c
1 /*****************************************************************************\
2 * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
3 * Copyright (C) 2007 The Regents of the University of California.
4 * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
5 * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
6 * UCRL-CODE-235197
7 *
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://zfsonlinux.org/>.
10 *
11 * The SPL is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 *
16 * The SPL is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 * for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23 *****************************************************************************
24 * Solaris Porting LAyer Tests (SPLAT) Kmem Tests.
25 \*****************************************************************************/
26
27 #include <sys/kmem.h>
28 #include <sys/kmem_cache.h>
29 #include <sys/vmem.h>
30 #include <sys/thread.h>
31 #include <sys/vmsystm.h>
32 #include "splat-internal.h"
33
34 #define SPLAT_KMEM_NAME "kmem"
35 #define SPLAT_KMEM_DESC "Kernel Malloc/Slab Tests"
36
37 #define SPLAT_KMEM_TEST1_ID 0x0101
38 #define SPLAT_KMEM_TEST1_NAME "kmem_alloc"
39 #define SPLAT_KMEM_TEST1_DESC "Memory allocation test (kmem_alloc)"
40
41 #define SPLAT_KMEM_TEST2_ID 0x0102
42 #define SPLAT_KMEM_TEST2_NAME "kmem_zalloc"
43 #define SPLAT_KMEM_TEST2_DESC "Memory allocation test (kmem_zalloc)"
44
45 #define SPLAT_KMEM_TEST3_ID 0x0103
46 #define SPLAT_KMEM_TEST3_NAME "vmem_alloc"
47 #define SPLAT_KMEM_TEST3_DESC "Memory allocation test (vmem_alloc)"
48
49 #define SPLAT_KMEM_TEST4_ID 0x0104
50 #define SPLAT_KMEM_TEST4_NAME "vmem_zalloc"
51 #define SPLAT_KMEM_TEST4_DESC "Memory allocation test (vmem_zalloc)"
52
53 #define SPLAT_KMEM_TEST5_ID 0x0105
54 #define SPLAT_KMEM_TEST5_NAME "slab_small"
55 #define SPLAT_KMEM_TEST5_DESC "Slab ctor/dtor test (small)"
56
57 #define SPLAT_KMEM_TEST6_ID 0x0106
58 #define SPLAT_KMEM_TEST6_NAME "slab_large"
59 #define SPLAT_KMEM_TEST6_DESC "Slab ctor/dtor test (large)"
60
61 #define SPLAT_KMEM_TEST7_ID 0x0107
62 #define SPLAT_KMEM_TEST7_NAME "slab_align"
63 #define SPLAT_KMEM_TEST7_DESC "Slab alignment test"
64
65 #define SPLAT_KMEM_TEST8_ID 0x0108
66 #define SPLAT_KMEM_TEST8_NAME "slab_reap"
67 #define SPLAT_KMEM_TEST8_DESC "Slab reaping test"
68
69 #define SPLAT_KMEM_TEST9_ID 0x0109
70 #define SPLAT_KMEM_TEST9_NAME "slab_age"
71 #define SPLAT_KMEM_TEST9_DESC "Slab aging test"
72
73 #define SPLAT_KMEM_TEST10_ID 0x010a
74 #define SPLAT_KMEM_TEST10_NAME "slab_lock"
75 #define SPLAT_KMEM_TEST10_DESC "Slab locking test"
76
77 #if 0
78 #define SPLAT_KMEM_TEST11_ID 0x010b
79 #define SPLAT_KMEM_TEST11_NAME "slab_overcommit"
80 #define SPLAT_KMEM_TEST11_DESC "Slab memory overcommit test"
81 #endif
82
83 #define SPLAT_KMEM_TEST13_ID 0x010d
84 #define SPLAT_KMEM_TEST13_NAME "slab_reclaim"
85 #define SPLAT_KMEM_TEST13_DESC "Slab direct memory reclaim test"
86
87 #define SPLAT_KMEM_ALLOC_COUNT 10
88 #define SPLAT_VMEM_ALLOC_COUNT 10
89
90
91 static int
92 splat_kmem_test1(struct file *file, void *arg)
93 {
94 void *ptr[SPLAT_KMEM_ALLOC_COUNT];
95 int size = PAGE_SIZE;
96 int i, count, rc = 0;
97
98 while ((!rc) && (size <= spl_kmem_alloc_warn)) {
99 count = 0;
100
101 for (i = 0; i < SPLAT_KMEM_ALLOC_COUNT; i++) {
102 ptr[i] = kmem_alloc(size, KM_SLEEP);
103 if (ptr[i])
104 count++;
105 }
106
107 for (i = 0; i < SPLAT_KMEM_ALLOC_COUNT; i++)
108 if (ptr[i])
109 kmem_free(ptr[i], size);
110
111 splat_vprint(file, SPLAT_KMEM_TEST1_NAME,
112 "%d byte allocations, %d/%d successful\n",
113 size, count, SPLAT_KMEM_ALLOC_COUNT);
114 if (count != SPLAT_KMEM_ALLOC_COUNT)
115 rc = -ENOMEM;
116
117 size *= 2;
118 }
119
120 return rc;
121 }
122
123 static int
124 splat_kmem_test2(struct file *file, void *arg)
125 {
126 void *ptr[SPLAT_KMEM_ALLOC_COUNT];
127 int size = PAGE_SIZE;
128 int i, j, count, rc = 0;
129
130 while ((!rc) && (size <= spl_kmem_alloc_warn)) {
131 count = 0;
132
133 for (i = 0; i < SPLAT_KMEM_ALLOC_COUNT; i++) {
134 ptr[i] = kmem_zalloc(size, KM_SLEEP);
135 if (ptr[i])
136 count++;
137 }
138
139 /* Ensure buffer has been zero filled */
140 for (i = 0; i < SPLAT_KMEM_ALLOC_COUNT; i++) {
141 for (j = 0; j < size; j++) {
142 if (((char *)ptr[i])[j] != '\0') {
143 splat_vprint(file,SPLAT_KMEM_TEST2_NAME,
144 "%d-byte allocation was "
145 "not zeroed\n", size);
146 rc = -EFAULT;
147 }
148 }
149 }
150
151 for (i = 0; i < SPLAT_KMEM_ALLOC_COUNT; i++)
152 if (ptr[i])
153 kmem_free(ptr[i], size);
154
155 splat_vprint(file, SPLAT_KMEM_TEST2_NAME,
156 "%d byte allocations, %d/%d successful\n",
157 size, count, SPLAT_KMEM_ALLOC_COUNT);
158 if (count != SPLAT_KMEM_ALLOC_COUNT)
159 rc = -ENOMEM;
160
161 size *= 2;
162 }
163
164 return rc;
165 }
166
167 static int
168 splat_kmem_test3(struct file *file, void *arg)
169 {
170 void *ptr[SPLAT_VMEM_ALLOC_COUNT];
171 int size = PAGE_SIZE;
172 int i, count, rc = 0;
173
174 /*
175 * Test up to 4x the maximum kmem_alloc() size to ensure both
176 * the kmem_alloc() and vmem_alloc() call paths are used.
177 */
178 while ((!rc) && (size <= (4 * spl_kmem_alloc_max))) {
179 count = 0;
180
181 for (i = 0; i < SPLAT_VMEM_ALLOC_COUNT; i++) {
182 ptr[i] = vmem_alloc(size, KM_SLEEP);
183 if (ptr[i])
184 count++;
185 }
186
187 for (i = 0; i < SPLAT_VMEM_ALLOC_COUNT; i++)
188 if (ptr[i])
189 vmem_free(ptr[i], size);
190
191 splat_vprint(file, SPLAT_KMEM_TEST3_NAME,
192 "%d byte allocations, %d/%d successful\n",
193 size, count, SPLAT_VMEM_ALLOC_COUNT);
194 if (count != SPLAT_VMEM_ALLOC_COUNT)
195 rc = -ENOMEM;
196
197 size *= 2;
198 }
199
200 return rc;
201 }
202
203 static int
204 splat_kmem_test4(struct file *file, void *arg)
205 {
206 void *ptr[SPLAT_VMEM_ALLOC_COUNT];
207 int size = PAGE_SIZE;
208 int i, j, count, rc = 0;
209
210 /*
211 * Test up to 4x the maximum kmem_zalloc() size to ensure both
212 * the kmem_zalloc() and vmem_zalloc() call paths are used.
213 */
214 while ((!rc) && (size <= (4 * spl_kmem_alloc_max))) {
215 count = 0;
216
217 for (i = 0; i < SPLAT_VMEM_ALLOC_COUNT; i++) {
218 ptr[i] = vmem_zalloc(size, KM_SLEEP);
219 if (ptr[i])
220 count++;
221 }
222
223 /* Ensure buffer has been zero filled */
224 for (i = 0; i < SPLAT_VMEM_ALLOC_COUNT; i++) {
225 for (j = 0; j < size; j++) {
226 if (((char *)ptr[i])[j] != '\0') {
227 splat_vprint(file, SPLAT_KMEM_TEST4_NAME,
228 "%d-byte allocation was "
229 "not zeroed\n", size);
230 rc = -EFAULT;
231 }
232 }
233 }
234
235 for (i = 0; i < SPLAT_VMEM_ALLOC_COUNT; i++)
236 if (ptr[i])
237 vmem_free(ptr[i], size);
238
239 splat_vprint(file, SPLAT_KMEM_TEST4_NAME,
240 "%d byte allocations, %d/%d successful\n",
241 size, count, SPLAT_VMEM_ALLOC_COUNT);
242 if (count != SPLAT_VMEM_ALLOC_COUNT)
243 rc = -ENOMEM;
244
245 size *= 2;
246 }
247
248 return rc;
249 }
250
251 #define SPLAT_KMEM_TEST_MAGIC 0x004488CCUL
252 #define SPLAT_KMEM_CACHE_NAME "kmem_test"
253 #define SPLAT_KMEM_OBJ_COUNT 1024
254 #define SPLAT_KMEM_OBJ_RECLAIM 32 /* objects */
255 #define SPLAT_KMEM_THREADS 32
256
257 #define KCP_FLAG_READY 0x01
258
259 typedef struct kmem_cache_data {
260 unsigned long kcd_magic;
261 struct list_head kcd_node;
262 int kcd_flag;
263 char kcd_buf[0];
264 } kmem_cache_data_t;
265
266 typedef struct kmem_cache_thread {
267 spinlock_t kct_lock;
268 int kct_id;
269 struct list_head kct_list;
270 } kmem_cache_thread_t;
271
272 typedef struct kmem_cache_priv {
273 unsigned long kcp_magic;
274 struct file *kcp_file;
275 kmem_cache_t *kcp_cache;
276 spinlock_t kcp_lock;
277 wait_queue_head_t kcp_ctl_waitq;
278 wait_queue_head_t kcp_thr_waitq;
279 int kcp_flags;
280 int kcp_kct_count;
281 kmem_cache_thread_t *kcp_kct[SPLAT_KMEM_THREADS];
282 int kcp_size;
283 int kcp_align;
284 int kcp_count;
285 int kcp_alloc;
286 int kcp_rc;
287 } kmem_cache_priv_t;
288
289 static kmem_cache_priv_t *
290 splat_kmem_cache_test_kcp_alloc(struct file *file, char *name,
291 int size, int align, int alloc)
292 {
293 kmem_cache_priv_t *kcp;
294
295 kcp = kmem_zalloc(sizeof(kmem_cache_priv_t), KM_SLEEP);
296 if (!kcp)
297 return NULL;
298
299 kcp->kcp_magic = SPLAT_KMEM_TEST_MAGIC;
300 kcp->kcp_file = file;
301 kcp->kcp_cache = NULL;
302 spin_lock_init(&kcp->kcp_lock);
303 init_waitqueue_head(&kcp->kcp_ctl_waitq);
304 init_waitqueue_head(&kcp->kcp_thr_waitq);
305 kcp->kcp_flags = 0;
306 kcp->kcp_kct_count = -1;
307 kcp->kcp_size = size;
308 kcp->kcp_align = align;
309 kcp->kcp_count = 0;
310 kcp->kcp_alloc = alloc;
311 kcp->kcp_rc = 0;
312
313 return kcp;
314 }
315
316 static void
317 splat_kmem_cache_test_kcp_free(kmem_cache_priv_t *kcp)
318 {
319 kmem_free(kcp, sizeof(kmem_cache_priv_t));
320 }
321
322 static kmem_cache_thread_t *
323 splat_kmem_cache_test_kct_alloc(kmem_cache_priv_t *kcp, int id)
324 {
325 kmem_cache_thread_t *kct;
326
327 ASSERT3S(id, <, SPLAT_KMEM_THREADS);
328 ASSERT(kcp->kcp_kct[id] == NULL);
329
330 kct = kmem_zalloc(sizeof(kmem_cache_thread_t), KM_SLEEP);
331 if (!kct)
332 return NULL;
333
334 spin_lock_init(&kct->kct_lock);
335 kct->kct_id = id;
336 INIT_LIST_HEAD(&kct->kct_list);
337
338 spin_lock(&kcp->kcp_lock);
339 kcp->kcp_kct[id] = kct;
340 spin_unlock(&kcp->kcp_lock);
341
342 return kct;
343 }
344
345 static void
346 splat_kmem_cache_test_kct_free(kmem_cache_priv_t *kcp,
347 kmem_cache_thread_t *kct)
348 {
349 spin_lock(&kcp->kcp_lock);
350 kcp->kcp_kct[kct->kct_id] = NULL;
351 spin_unlock(&kcp->kcp_lock);
352
353 kmem_free(kct, sizeof(kmem_cache_thread_t));
354 }
355
356 static void
357 splat_kmem_cache_test_kcd_free(kmem_cache_priv_t *kcp,
358 kmem_cache_thread_t *kct)
359 {
360 kmem_cache_data_t *kcd;
361
362 spin_lock(&kct->kct_lock);
363 while (!list_empty(&kct->kct_list)) {
364 kcd = list_entry(kct->kct_list.next,
365 kmem_cache_data_t, kcd_node);
366 list_del(&kcd->kcd_node);
367 spin_unlock(&kct->kct_lock);
368
369 kmem_cache_free(kcp->kcp_cache, kcd);
370
371 spin_lock(&kct->kct_lock);
372 }
373 spin_unlock(&kct->kct_lock);
374 }
375
376 static int
377 splat_kmem_cache_test_kcd_alloc(kmem_cache_priv_t *kcp,
378 kmem_cache_thread_t *kct, int count)
379 {
380 kmem_cache_data_t *kcd;
381 int i;
382
383 for (i = 0; i < count; i++) {
384 kcd = kmem_cache_alloc(kcp->kcp_cache, KM_SLEEP);
385 if (kcd == NULL) {
386 splat_kmem_cache_test_kcd_free(kcp, kct);
387 return -ENOMEM;
388 }
389
390 spin_lock(&kct->kct_lock);
391 list_add_tail(&kcd->kcd_node, &kct->kct_list);
392 spin_unlock(&kct->kct_lock);
393 }
394
395 return 0;
396 }
397
398 static void
399 splat_kmem_cache_test_debug(struct file *file, char *name,
400 kmem_cache_priv_t *kcp)
401 {
402 int j;
403
404 splat_vprint(file, name, "%s cache objects %d",
405 kcp->kcp_cache->skc_name, kcp->kcp_count);
406
407 if (kcp->kcp_cache->skc_flags & (KMC_KMEM | KMC_VMEM)) {
408 splat_vprint(file, name, ", slabs %u/%u objs %u/%u",
409 (unsigned)kcp->kcp_cache->skc_slab_alloc,
410 (unsigned)kcp->kcp_cache->skc_slab_total,
411 (unsigned)kcp->kcp_cache->skc_obj_alloc,
412 (unsigned)kcp->kcp_cache->skc_obj_total);
413
414 if (!(kcp->kcp_cache->skc_flags & KMC_NOMAGAZINE)) {
415 splat_vprint(file, name, "%s", "mags");
416
417 for_each_online_cpu(j)
418 splat_print(file, "%u/%u ",
419 kcp->kcp_cache->skc_mag[j]->skm_avail,
420 kcp->kcp_cache->skc_mag[j]->skm_size);
421 }
422 }
423
424 splat_print(file, "%s\n", "");
425 }
426
427 static int
428 splat_kmem_cache_test_constructor(void *ptr, void *priv, int flags)
429 {
430 kmem_cache_priv_t *kcp = (kmem_cache_priv_t *)priv;
431 kmem_cache_data_t *kcd = (kmem_cache_data_t *)ptr;
432
433 if (kcd && kcp) {
434 kcd->kcd_magic = kcp->kcp_magic;
435 INIT_LIST_HEAD(&kcd->kcd_node);
436 kcd->kcd_flag = 1;
437 memset(kcd->kcd_buf, 0xaa, kcp->kcp_size - (sizeof *kcd));
438 kcp->kcp_count++;
439 }
440
441 return 0;
442 }
443
444 static void
445 splat_kmem_cache_test_destructor(void *ptr, void *priv)
446 {
447 kmem_cache_priv_t *kcp = (kmem_cache_priv_t *)priv;
448 kmem_cache_data_t *kcd = (kmem_cache_data_t *)ptr;
449
450 if (kcd && kcp) {
451 kcd->kcd_magic = 0;
452 kcd->kcd_flag = 0;
453 memset(kcd->kcd_buf, 0xbb, kcp->kcp_size - (sizeof *kcd));
454 kcp->kcp_count--;
455 }
456
457 return;
458 }
459
460 /*
461 * Generic reclaim function which assumes that all objects may
462 * be reclaimed at any time. We free a small percentage of the
463 * objects linked off the kcp or kct[] every time we are called.
464 */
465 static void
466 splat_kmem_cache_test_reclaim(void *priv)
467 {
468 kmem_cache_priv_t *kcp = (kmem_cache_priv_t *)priv;
469 kmem_cache_thread_t *kct;
470 kmem_cache_data_t *kcd;
471 LIST_HEAD(reclaim);
472 int i, count;
473
474 ASSERT(kcp->kcp_magic == SPLAT_KMEM_TEST_MAGIC);
475
476 /* For each kct thread reclaim some objects */
477 spin_lock(&kcp->kcp_lock);
478 for (i = 0; i < SPLAT_KMEM_THREADS; i++) {
479 kct = kcp->kcp_kct[i];
480 if (!kct)
481 continue;
482
483 spin_unlock(&kcp->kcp_lock);
484 spin_lock(&kct->kct_lock);
485
486 count = SPLAT_KMEM_OBJ_RECLAIM;
487 while (count > 0 && !list_empty(&kct->kct_list)) {
488 kcd = list_entry(kct->kct_list.next,
489 kmem_cache_data_t, kcd_node);
490 list_del(&kcd->kcd_node);
491 list_add(&kcd->kcd_node, &reclaim);
492 count--;
493 }
494
495 spin_unlock(&kct->kct_lock);
496 spin_lock(&kcp->kcp_lock);
497 }
498 spin_unlock(&kcp->kcp_lock);
499
500 /* Freed outside the spin lock */
501 while (!list_empty(&reclaim)) {
502 kcd = list_entry(reclaim.next, kmem_cache_data_t, kcd_node);
503 list_del(&kcd->kcd_node);
504 kmem_cache_free(kcp->kcp_cache, kcd);
505 }
506
507 return;
508 }
509
510 static int
511 splat_kmem_cache_test_threads(kmem_cache_priv_t *kcp, int threads)
512 {
513 int rc;
514
515 spin_lock(&kcp->kcp_lock);
516 rc = (kcp->kcp_kct_count == threads);
517 spin_unlock(&kcp->kcp_lock);
518
519 return rc;
520 }
521
522 static int
523 splat_kmem_cache_test_flags(kmem_cache_priv_t *kcp, int flags)
524 {
525 int rc;
526
527 spin_lock(&kcp->kcp_lock);
528 rc = (kcp->kcp_flags & flags);
529 spin_unlock(&kcp->kcp_lock);
530
531 return rc;
532 }
533
534 static void
535 splat_kmem_cache_test_thread(void *arg)
536 {
537 kmem_cache_priv_t *kcp = (kmem_cache_priv_t *)arg;
538 kmem_cache_thread_t *kct;
539 int rc = 0, id;
540
541 ASSERT(kcp->kcp_magic == SPLAT_KMEM_TEST_MAGIC);
542
543 /* Assign thread ids */
544 spin_lock(&kcp->kcp_lock);
545 if (kcp->kcp_kct_count == -1)
546 kcp->kcp_kct_count = 0;
547
548 id = kcp->kcp_kct_count;
549 kcp->kcp_kct_count++;
550 spin_unlock(&kcp->kcp_lock);
551
552 kct = splat_kmem_cache_test_kct_alloc(kcp, id);
553 if (!kct) {
554 rc = -ENOMEM;
555 goto out;
556 }
557
558 /* Wait for all threads to have started and report they are ready */
559 if (kcp->kcp_kct_count == SPLAT_KMEM_THREADS)
560 wake_up(&kcp->kcp_ctl_waitq);
561
562 wait_event(kcp->kcp_thr_waitq,
563 splat_kmem_cache_test_flags(kcp, KCP_FLAG_READY));
564
565 /* Create and destroy objects */
566 rc = splat_kmem_cache_test_kcd_alloc(kcp, kct, kcp->kcp_alloc);
567 splat_kmem_cache_test_kcd_free(kcp, kct);
568 out:
569 if (kct)
570 splat_kmem_cache_test_kct_free(kcp, kct);
571
572 spin_lock(&kcp->kcp_lock);
573 if (!kcp->kcp_rc)
574 kcp->kcp_rc = rc;
575
576 if ((--kcp->kcp_kct_count) == 0)
577 wake_up(&kcp->kcp_ctl_waitq);
578
579 spin_unlock(&kcp->kcp_lock);
580
581 thread_exit();
582 }
583
584 static int
585 splat_kmem_cache_test(struct file *file, void *arg, char *name,
586 int size, int align, int flags)
587 {
588 kmem_cache_priv_t *kcp;
589 kmem_cache_data_t *kcd = NULL;
590 int rc = 0, max;
591
592 kcp = splat_kmem_cache_test_kcp_alloc(file, name, size, align, 0);
593 if (!kcp) {
594 splat_vprint(file, name, "Unable to create '%s'\n", "kcp");
595 return -ENOMEM;
596 }
597
598 kcp->kcp_cache =
599 kmem_cache_create(SPLAT_KMEM_CACHE_NAME,
600 kcp->kcp_size, kcp->kcp_align,
601 splat_kmem_cache_test_constructor,
602 splat_kmem_cache_test_destructor,
603 NULL, kcp, NULL, flags);
604 if (!kcp->kcp_cache) {
605 splat_vprint(file, name,
606 "Unable to create '%s'\n",
607 SPLAT_KMEM_CACHE_NAME);
608 rc = -ENOMEM;
609 goto out_free;
610 }
611
612 kcd = kmem_cache_alloc(kcp->kcp_cache, KM_SLEEP);
613 if (!kcd) {
614 splat_vprint(file, name,
615 "Unable to allocate from '%s'\n",
616 SPLAT_KMEM_CACHE_NAME);
617 rc = -EINVAL;
618 goto out_free;
619 }
620
621 if (!kcd->kcd_flag) {
622 splat_vprint(file, name,
623 "Failed to run contructor for '%s'\n",
624 SPLAT_KMEM_CACHE_NAME);
625 rc = -EINVAL;
626 goto out_free;
627 }
628
629 if (kcd->kcd_magic != kcp->kcp_magic) {
630 splat_vprint(file, name,
631 "Failed to pass private data to constructor "
632 "for '%s'\n", SPLAT_KMEM_CACHE_NAME);
633 rc = -EINVAL;
634 goto out_free;
635 }
636
637 max = kcp->kcp_count;
638 kmem_cache_free(kcp->kcp_cache, kcd);
639
640 /* Destroy the entire cache which will force destructors to
641 * run and we can verify one was called for every object */
642 kmem_cache_destroy(kcp->kcp_cache);
643 if (kcp->kcp_count) {
644 splat_vprint(file, name,
645 "Failed to run destructor on all slab objects "
646 "for '%s'\n", SPLAT_KMEM_CACHE_NAME);
647 rc = -EINVAL;
648 }
649
650 splat_kmem_cache_test_kcp_free(kcp);
651 splat_vprint(file, name,
652 "Successfully ran ctors/dtors for %d elements in '%s'\n",
653 max, SPLAT_KMEM_CACHE_NAME);
654
655 return rc;
656
657 out_free:
658 if (kcd)
659 kmem_cache_free(kcp->kcp_cache, kcd);
660
661 if (kcp->kcp_cache)
662 kmem_cache_destroy(kcp->kcp_cache);
663
664 splat_kmem_cache_test_kcp_free(kcp);
665
666 return rc;
667 }
668
669 static int
670 splat_kmem_cache_thread_test(struct file *file, void *arg, char *name,
671 int size, int alloc, int max_time)
672 {
673 kmem_cache_priv_t *kcp;
674 kthread_t *thr;
675 struct timespec start, stop, delta;
676 char cache_name[32];
677 int i, rc = 0;
678
679 kcp = splat_kmem_cache_test_kcp_alloc(file, name, size, 0, alloc);
680 if (!kcp) {
681 splat_vprint(file, name, "Unable to create '%s'\n", "kcp");
682 return -ENOMEM;
683 }
684
685 (void)snprintf(cache_name, 32, "%s-%d-%d",
686 SPLAT_KMEM_CACHE_NAME, size, alloc);
687 kcp->kcp_cache =
688 kmem_cache_create(cache_name, kcp->kcp_size, 0,
689 splat_kmem_cache_test_constructor,
690 splat_kmem_cache_test_destructor,
691 splat_kmem_cache_test_reclaim,
692 kcp, NULL, 0);
693 if (!kcp->kcp_cache) {
694 splat_vprint(file, name, "Unable to create '%s'\n", cache_name);
695 rc = -ENOMEM;
696 goto out_kcp;
697 }
698
699 getnstimeofday(&start);
700
701 for (i = 0; i < SPLAT_KMEM_THREADS; i++) {
702 thr = thread_create(NULL, 0,
703 splat_kmem_cache_test_thread,
704 kcp, 0, &p0, TS_RUN, minclsyspri);
705 if (thr == NULL) {
706 rc = -ESRCH;
707 goto out_cache;
708 }
709 }
710
711 /* Sleep until all threads have started, then set the ready
712 * flag and wake them all up for maximum concurrency. */
713 wait_event(kcp->kcp_ctl_waitq,
714 splat_kmem_cache_test_threads(kcp, SPLAT_KMEM_THREADS));
715
716 spin_lock(&kcp->kcp_lock);
717 kcp->kcp_flags |= KCP_FLAG_READY;
718 spin_unlock(&kcp->kcp_lock);
719 wake_up_all(&kcp->kcp_thr_waitq);
720
721 /* Sleep until all thread have finished */
722 wait_event(kcp->kcp_ctl_waitq, splat_kmem_cache_test_threads(kcp, 0));
723
724 getnstimeofday(&stop);
725 delta = timespec_sub(stop, start);
726
727 splat_vprint(file, name,
728 "%-22s %2ld.%09ld\t"
729 "%lu/%lu/%lu\t%lu/%lu/%lu\n",
730 kcp->kcp_cache->skc_name,
731 delta.tv_sec, delta.tv_nsec,
732 (unsigned long)kcp->kcp_cache->skc_slab_total,
733 (unsigned long)kcp->kcp_cache->skc_slab_max,
734 (unsigned long)(kcp->kcp_alloc *
735 SPLAT_KMEM_THREADS /
736 SPL_KMEM_CACHE_OBJ_PER_SLAB),
737 (unsigned long)kcp->kcp_cache->skc_obj_total,
738 (unsigned long)kcp->kcp_cache->skc_obj_max,
739 (unsigned long)(kcp->kcp_alloc *
740 SPLAT_KMEM_THREADS));
741
742 if (delta.tv_sec >= max_time)
743 rc = -ETIME;
744
745 if (!rc && kcp->kcp_rc)
746 rc = kcp->kcp_rc;
747
748 out_cache:
749 kmem_cache_destroy(kcp->kcp_cache);
750 out_kcp:
751 splat_kmem_cache_test_kcp_free(kcp);
752 return rc;
753 }
754
755 /* Validate small object cache behavior for dynamic/kmem/vmem caches */
756 static int
757 splat_kmem_test5(struct file *file, void *arg)
758 {
759 char *name = SPLAT_KMEM_TEST5_NAME;
760 int rc;
761
762 /* On slab (default + kmem + vmem) */
763 rc = splat_kmem_cache_test(file, arg, name, 128, 0, 0);
764 if (rc)
765 return rc;
766
767 rc = splat_kmem_cache_test(file, arg, name, 128, 0, KMC_KMEM);
768 if (rc)
769 return rc;
770
771 rc = splat_kmem_cache_test(file, arg, name, 128, 0, KMC_VMEM);
772 if (rc)
773 return rc;
774
775 /* Off slab (default + kmem + vmem) */
776 rc = splat_kmem_cache_test(file, arg, name, 128, 0, KMC_OFFSLAB);
777 if (rc)
778 return rc;
779
780 rc = splat_kmem_cache_test(file, arg, name, 128, 0,
781 KMC_KMEM | KMC_OFFSLAB);
782 if (rc)
783 return rc;
784
785 rc = splat_kmem_cache_test(file, arg, name, 128, 0,
786 KMC_VMEM | KMC_OFFSLAB);
787
788 return rc;
789 }
790
791 /*
792 * Validate large object cache behavior for dynamic/kmem/vmem caches
793 */
794 static int
795 splat_kmem_test6(struct file *file, void *arg)
796 {
797 char *name = SPLAT_KMEM_TEST6_NAME;
798 int rc;
799
800 /* On slab (default + kmem + vmem) */
801 rc = splat_kmem_cache_test(file, arg, name, 256*1024, 0, 0);
802 if (rc)
803 return rc;
804
805 rc = splat_kmem_cache_test(file, arg, name, 64*1024, 0, KMC_KMEM);
806 if (rc)
807 return rc;
808
809 rc = splat_kmem_cache_test(file, arg, name, 1024*1024, 0, KMC_VMEM);
810 if (rc)
811 return rc;
812
813 rc = splat_kmem_cache_test(file, arg, name, 16*1024*1024, 0, KMC_VMEM);
814 if (rc)
815 return rc;
816
817 /* Off slab (default + kmem + vmem) */
818 rc = splat_kmem_cache_test(file, arg, name, 256*1024, 0, KMC_OFFSLAB);
819 if (rc)
820 return rc;
821
822 rc = splat_kmem_cache_test(file, arg, name, 64*1024, 0,
823 KMC_KMEM | KMC_OFFSLAB);
824 if (rc)
825 return rc;
826
827 rc = splat_kmem_cache_test(file, arg, name, 1024*1024, 0,
828 KMC_VMEM | KMC_OFFSLAB);
829 if (rc)
830 return rc;
831
832 rc = splat_kmem_cache_test(file, arg, name, 16*1024*1024, 0,
833 KMC_VMEM | KMC_OFFSLAB);
834
835 return rc;
836 }
837
838 /*
839 * Validate object alignment cache behavior for caches
840 */
841 static int
842 splat_kmem_test7(struct file *file, void *arg)
843 {
844 char *name = SPLAT_KMEM_TEST7_NAME;
845 int i, rc;
846
847 for (i = SPL_KMEM_CACHE_ALIGN; i <= PAGE_SIZE; i *= 2) {
848 rc = splat_kmem_cache_test(file, arg, name, 157, i, 0);
849 if (rc)
850 return rc;
851
852 rc = splat_kmem_cache_test(file, arg, name, 157, i,
853 KMC_OFFSLAB);
854 if (rc)
855 return rc;
856 }
857
858 return rc;
859 }
860
861 /*
862 * Validate kmem_cache_reap() by requesting the slab cache free any objects
863 * it can. For a few reasons this may not immediately result in more free
864 * memory even if objects are freed. First off, due to fragmentation we
865 * may not be able to reclaim any slabs. Secondly, even if we do we fully
866 * clear some slabs we will not want to immediately reclaim all of them
867 * because we may contend with cache allocations and thrash. What we want
868 * to see is the slab size decrease more gradually as it becomes clear they
869 * will not be needed. This should be achievable in less than a minute.
870 * If it takes longer than this something has gone wrong.
871 */
872 static int
873 splat_kmem_test8(struct file *file, void *arg)
874 {
875 kmem_cache_priv_t *kcp;
876 kmem_cache_thread_t *kct;
877 unsigned int spl_kmem_cache_expire_old;
878 int i, rc = 0;
879
880 /* Enable cache aging just for this test if it is disabled */
881 spl_kmem_cache_expire_old = spl_kmem_cache_expire;
882 spl_kmem_cache_expire = KMC_EXPIRE_AGE;
883
884 kcp = splat_kmem_cache_test_kcp_alloc(file, SPLAT_KMEM_TEST8_NAME,
885 256, 0, 0);
886 if (!kcp) {
887 splat_vprint(file, SPLAT_KMEM_TEST8_NAME,
888 "Unable to create '%s'\n", "kcp");
889 rc = -ENOMEM;
890 goto out;
891 }
892
893 kcp->kcp_cache =
894 kmem_cache_create(SPLAT_KMEM_CACHE_NAME, kcp->kcp_size, 0,
895 splat_kmem_cache_test_constructor,
896 splat_kmem_cache_test_destructor,
897 splat_kmem_cache_test_reclaim,
898 kcp, NULL, 0);
899 if (!kcp->kcp_cache) {
900 splat_vprint(file, SPLAT_KMEM_TEST8_NAME,
901 "Unable to create '%s'\n", SPLAT_KMEM_CACHE_NAME);
902 rc = -ENOMEM;
903 goto out_kcp;
904 }
905
906 kct = splat_kmem_cache_test_kct_alloc(kcp, 0);
907 if (!kct) {
908 splat_vprint(file, SPLAT_KMEM_TEST8_NAME,
909 "Unable to create '%s'\n", "kct");
910 rc = -ENOMEM;
911 goto out_cache;
912 }
913
914 rc = splat_kmem_cache_test_kcd_alloc(kcp, kct, SPLAT_KMEM_OBJ_COUNT);
915 if (rc) {
916 splat_vprint(file, SPLAT_KMEM_TEST8_NAME, "Unable to "
917 "allocate from '%s'\n", SPLAT_KMEM_CACHE_NAME);
918 goto out_kct;
919 }
920
921 /* Force reclaim every 1/10 a second for 60 seconds. */
922 for (i = 0; i < 600; i++) {
923 kmem_cache_reap_now(kcp->kcp_cache);
924 splat_kmem_cache_test_debug(file, SPLAT_KMEM_TEST8_NAME, kcp);
925
926 if (kcp->kcp_count == 0)
927 break;
928
929 set_current_state(TASK_INTERRUPTIBLE);
930 schedule_timeout(HZ / 10);
931 }
932
933 if (kcp->kcp_count == 0) {
934 splat_vprint(file, SPLAT_KMEM_TEST8_NAME,
935 "Successfully created %d objects "
936 "in cache %s and reclaimed them\n",
937 SPLAT_KMEM_OBJ_COUNT, SPLAT_KMEM_CACHE_NAME);
938 } else {
939 splat_vprint(file, SPLAT_KMEM_TEST8_NAME,
940 "Failed to reclaim %u/%d objects from cache %s\n",
941 (unsigned)kcp->kcp_count,
942 SPLAT_KMEM_OBJ_COUNT, SPLAT_KMEM_CACHE_NAME);
943 rc = -ENOMEM;
944 }
945
946 /* Cleanup our mess (for failure case of time expiring) */
947 splat_kmem_cache_test_kcd_free(kcp, kct);
948 out_kct:
949 splat_kmem_cache_test_kct_free(kcp, kct);
950 out_cache:
951 kmem_cache_destroy(kcp->kcp_cache);
952 out_kcp:
953 splat_kmem_cache_test_kcp_free(kcp);
954 out:
955 spl_kmem_cache_expire = spl_kmem_cache_expire_old;
956
957 return rc;
958 }
959
960 /* Test cache aging, we have allocated a large number of objects thus
961 * creating a large number of slabs and then free'd them all. However,
962 * since there should be little memory pressure at the moment those
963 * slabs have not been freed. What we want to see is the slab size
964 * decrease gradually as it becomes clear they will not be be needed.
965 * This should be achievable in less than minute. If it takes longer
966 * than this something has gone wrong.
967 */
968 static int
969 splat_kmem_test9(struct file *file, void *arg)
970 {
971 kmem_cache_priv_t *kcp;
972 kmem_cache_thread_t *kct;
973 unsigned int spl_kmem_cache_expire_old;
974 int i, rc = 0, count = SPLAT_KMEM_OBJ_COUNT * 128;
975
976 /* Enable cache aging just for this test if it is disabled */
977 spl_kmem_cache_expire_old = spl_kmem_cache_expire;
978 spl_kmem_cache_expire = KMC_EXPIRE_AGE;
979
980 kcp = splat_kmem_cache_test_kcp_alloc(file, SPLAT_KMEM_TEST9_NAME,
981 256, 0, 0);
982 if (!kcp) {
983 splat_vprint(file, SPLAT_KMEM_TEST9_NAME,
984 "Unable to create '%s'\n", "kcp");
985 rc = -ENOMEM;
986 goto out;
987 }
988
989 kcp->kcp_cache =
990 kmem_cache_create(SPLAT_KMEM_CACHE_NAME, kcp->kcp_size, 0,
991 splat_kmem_cache_test_constructor,
992 splat_kmem_cache_test_destructor,
993 NULL, kcp, NULL, 0);
994 if (!kcp->kcp_cache) {
995 splat_vprint(file, SPLAT_KMEM_TEST9_NAME,
996 "Unable to create '%s'\n", SPLAT_KMEM_CACHE_NAME);
997 rc = -ENOMEM;
998 goto out_kcp;
999 }
1000
1001 kct = splat_kmem_cache_test_kct_alloc(kcp, 0);
1002 if (!kct) {
1003 splat_vprint(file, SPLAT_KMEM_TEST8_NAME,
1004 "Unable to create '%s'\n", "kct");
1005 rc = -ENOMEM;
1006 goto out_cache;
1007 }
1008
1009 rc = splat_kmem_cache_test_kcd_alloc(kcp, kct, count);
1010 if (rc) {
1011 splat_vprint(file, SPLAT_KMEM_TEST9_NAME, "Unable to "
1012 "allocate from '%s'\n", SPLAT_KMEM_CACHE_NAME);
1013 goto out_kct;
1014 }
1015
1016 splat_kmem_cache_test_kcd_free(kcp, kct);
1017
1018 for (i = 0; i < 60; i++) {
1019 splat_kmem_cache_test_debug(file, SPLAT_KMEM_TEST9_NAME, kcp);
1020
1021 if (kcp->kcp_count == 0)
1022 break;
1023
1024 set_current_state(TASK_INTERRUPTIBLE);
1025 schedule_timeout(HZ);
1026 }
1027
1028 if (kcp->kcp_count == 0) {
1029 splat_vprint(file, SPLAT_KMEM_TEST9_NAME,
1030 "Successfully created %d objects "
1031 "in cache %s and reclaimed them\n",
1032 count, SPLAT_KMEM_CACHE_NAME);
1033 } else {
1034 splat_vprint(file, SPLAT_KMEM_TEST9_NAME,
1035 "Failed to reclaim %u/%d objects from cache %s\n",
1036 (unsigned)kcp->kcp_count, count,
1037 SPLAT_KMEM_CACHE_NAME);
1038 rc = -ENOMEM;
1039 }
1040
1041 out_kct:
1042 splat_kmem_cache_test_kct_free(kcp, kct);
1043 out_cache:
1044 kmem_cache_destroy(kcp->kcp_cache);
1045 out_kcp:
1046 splat_kmem_cache_test_kcp_free(kcp);
1047 out:
1048 spl_kmem_cache_expire = spl_kmem_cache_expire_old;
1049
1050 return rc;
1051 }
1052
1053 /*
1054 * This test creates N threads with a shared kmem cache. They then all
1055 * concurrently allocate and free from the cache to stress the locking and
1056 * concurrent cache performance. If any one test takes longer than 5
1057 * seconds to complete it is treated as a failure and may indicate a
1058 * performance regression. On my test system no one test takes more
1059 * than 1 second to complete so a 5x slowdown likely a problem.
1060 */
1061 static int
1062 splat_kmem_test10(struct file *file, void *arg)
1063 {
1064 uint64_t size, alloc, rc = 0;
1065
1066 for (size = 32; size <= 1024*1024; size *= 2) {
1067
1068 splat_vprint(file, SPLAT_KMEM_TEST10_NAME, "%-22s %s", "name",
1069 "time (sec)\tslabs \tobjs \thash\n");
1070 splat_vprint(file, SPLAT_KMEM_TEST10_NAME, "%-22s %s", "",
1071 " \ttot/max/calc\ttot/max/calc\n");
1072
1073 for (alloc = 1; alloc <= 1024; alloc *= 2) {
1074
1075 /* Skip tests which exceed 1/2 of physical memory. */
1076 if (size * alloc * SPLAT_KMEM_THREADS > physmem / 2)
1077 continue;
1078
1079 rc = splat_kmem_cache_thread_test(file, arg,
1080 SPLAT_KMEM_TEST10_NAME, size, alloc, 5);
1081 if (rc)
1082 break;
1083 }
1084 }
1085
1086 return rc;
1087 }
1088
1089 #if 0
1090 /*
1091 * This test creates N threads with a shared kmem cache which overcommits
1092 * memory by 4x. This makes it impossible for the slab to satify the
1093 * thread requirements without having its reclaim hook run which will
1094 * free objects back for use. This behavior is triggered by the linum VM
1095 * detecting a low memory condition on the node and invoking the shrinkers.
1096 * This should allow all the threads to complete while avoiding deadlock
1097 * and for the most part out of memory events. This is very tough on the
1098 * system so it is possible the test app may get oom'ed. This particular
1099 * test has proven troublesome on 32-bit archs with limited virtual
1100 * address space so it only run on 64-bit systems.
1101 */
1102 static int
1103 splat_kmem_test11(struct file *file, void *arg)
1104 {
1105 uint64_t size, alloc, rc;
1106
1107 size = 8 * 1024;
1108 alloc = ((4 * physmem * PAGE_SIZE) / size) / SPLAT_KMEM_THREADS;
1109
1110 splat_vprint(file, SPLAT_KMEM_TEST11_NAME, "%-22s %s", "name",
1111 "time (sec)\tslabs \tobjs \thash\n");
1112 splat_vprint(file, SPLAT_KMEM_TEST11_NAME, "%-22s %s", "",
1113 " \ttot/max/calc\ttot/max/calc\n");
1114
1115 rc = splat_kmem_cache_thread_test(file, arg,
1116 SPLAT_KMEM_TEST11_NAME, size, alloc, 60);
1117
1118 return rc;
1119 }
1120 #endif
1121
1122 typedef struct dummy_page {
1123 struct list_head dp_list;
1124 char dp_pad[PAGE_SIZE - sizeof(struct list_head)];
1125 } dummy_page_t;
1126
1127 /*
1128 * This test is designed to verify that direct reclaim is functioning as
1129 * expected. We allocate a large number of objects thus creating a large
1130 * number of slabs. We then apply memory pressure and expect that the
1131 * direct reclaim path can easily recover those slabs. The registered
1132 * reclaim function will free the objects and the slab shrinker will call
1133 * it repeatedly until at least a single slab can be freed.
1134 *
1135 * Note it may not be possible to reclaim every last slab via direct reclaim
1136 * without a failure because the shrinker_rwsem may be contended. For this
1137 * reason, quickly reclaiming 3/4 of the slabs is considered a success.
1138 *
1139 * This should all be possible within 10 seconds. For reference, on a
1140 * system with 2G of memory this test takes roughly 0.2 seconds to run.
1141 * It may take longer on larger memory systems but should still easily
1142 * complete in the alloted 10 seconds.
1143 */
1144 static int
1145 splat_kmem_test13(struct file *file, void *arg)
1146 {
1147 kmem_cache_priv_t *kcp;
1148 kmem_cache_thread_t *kct;
1149 dummy_page_t *dp;
1150 struct list_head list;
1151 struct timespec start, stop, delta = { 0, 0 };
1152 int size, count, slabs, fails = 0;
1153 int i, rc = 0, max_time = 10;
1154
1155 size = 128 * 1024;
1156 count = ((physmem * PAGE_SIZE) / 4 / size);
1157
1158 kcp = splat_kmem_cache_test_kcp_alloc(file, SPLAT_KMEM_TEST13_NAME,
1159 size, 0, 0);
1160 if (!kcp) {
1161 splat_vprint(file, SPLAT_KMEM_TEST13_NAME,
1162 "Unable to create '%s'\n", "kcp");
1163 rc = -ENOMEM;
1164 goto out;
1165 }
1166
1167 kcp->kcp_cache =
1168 kmem_cache_create(SPLAT_KMEM_CACHE_NAME, kcp->kcp_size, 0,
1169 splat_kmem_cache_test_constructor,
1170 splat_kmem_cache_test_destructor,
1171 splat_kmem_cache_test_reclaim,
1172 kcp, NULL, 0);
1173 if (!kcp->kcp_cache) {
1174 splat_vprint(file, SPLAT_KMEM_TEST13_NAME,
1175 "Unable to create '%s'\n", SPLAT_KMEM_CACHE_NAME);
1176 rc = -ENOMEM;
1177 goto out_kcp;
1178 }
1179
1180 kct = splat_kmem_cache_test_kct_alloc(kcp, 0);
1181 if (!kct) {
1182 splat_vprint(file, SPLAT_KMEM_TEST13_NAME,
1183 "Unable to create '%s'\n", "kct");
1184 rc = -ENOMEM;
1185 goto out_cache;
1186 }
1187
1188 rc = splat_kmem_cache_test_kcd_alloc(kcp, kct, count);
1189 if (rc) {
1190 splat_vprint(file, SPLAT_KMEM_TEST13_NAME, "Unable to "
1191 "allocate from '%s'\n", SPLAT_KMEM_CACHE_NAME);
1192 goto out_kct;
1193 }
1194
1195 i = 0;
1196 slabs = kcp->kcp_cache->skc_slab_total;
1197 INIT_LIST_HEAD(&list);
1198 getnstimeofday(&start);
1199
1200 /* Apply memory pressure */
1201 while (kcp->kcp_cache->skc_slab_total > (slabs >> 2)) {
1202
1203 if ((i % 10000) == 0)
1204 splat_kmem_cache_test_debug(
1205 file, SPLAT_KMEM_TEST13_NAME, kcp);
1206
1207 getnstimeofday(&stop);
1208 delta = timespec_sub(stop, start);
1209 if (delta.tv_sec >= max_time) {
1210 splat_vprint(file, SPLAT_KMEM_TEST13_NAME,
1211 "Failed to reclaim 3/4 of cache in %ds, "
1212 "%u/%u slabs remain\n", max_time,
1213 (unsigned)kcp->kcp_cache->skc_slab_total,
1214 slabs);
1215 rc = -ETIME;
1216 break;
1217 }
1218
1219 dp = (dummy_page_t *)__get_free_page(GFP_KERNEL);
1220 if (!dp) {
1221 fails++;
1222 splat_vprint(file, SPLAT_KMEM_TEST13_NAME,
1223 "Failed (%d) to allocate page with %u "
1224 "slabs still in the cache\n", fails,
1225 (unsigned)kcp->kcp_cache->skc_slab_total);
1226 continue;
1227 }
1228
1229 list_add(&dp->dp_list, &list);
1230 i++;
1231 }
1232
1233 if (rc == 0)
1234 splat_vprint(file, SPLAT_KMEM_TEST13_NAME,
1235 "Successfully created %u slabs and with %d alloc "
1236 "failures reclaimed 3/4 of them in %d.%03ds\n",
1237 slabs, fails,
1238 (int)delta.tv_sec, (int)delta.tv_nsec / 1000000);
1239
1240 /* Release memory pressure pages */
1241 while (!list_empty(&list)) {
1242 dp = list_entry(list.next, dummy_page_t, dp_list);
1243 list_del_init(&dp->dp_list);
1244 free_page((unsigned long)dp);
1245 }
1246
1247 /* Release remaining kmem cache objects */
1248 splat_kmem_cache_test_kcd_free(kcp, kct);
1249 out_kct:
1250 splat_kmem_cache_test_kct_free(kcp, kct);
1251 out_cache:
1252 kmem_cache_destroy(kcp->kcp_cache);
1253 out_kcp:
1254 splat_kmem_cache_test_kcp_free(kcp);
1255 out:
1256 return rc;
1257 }
1258
1259 splat_subsystem_t *
1260 splat_kmem_init(void)
1261 {
1262 splat_subsystem_t *sub;
1263
1264 sub = kmalloc(sizeof(*sub), GFP_KERNEL);
1265 if (sub == NULL)
1266 return NULL;
1267
1268 memset(sub, 0, sizeof(*sub));
1269 strncpy(sub->desc.name, SPLAT_KMEM_NAME, SPLAT_NAME_SIZE);
1270 strncpy(sub->desc.desc, SPLAT_KMEM_DESC, SPLAT_DESC_SIZE);
1271 INIT_LIST_HEAD(&sub->subsystem_list);
1272 INIT_LIST_HEAD(&sub->test_list);
1273 spin_lock_init(&sub->test_lock);
1274 sub->desc.id = SPLAT_SUBSYSTEM_KMEM;
1275
1276 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST1_NAME, SPLAT_KMEM_TEST1_DESC,
1277 SPLAT_KMEM_TEST1_ID, splat_kmem_test1);
1278 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST2_NAME, SPLAT_KMEM_TEST2_DESC,
1279 SPLAT_KMEM_TEST2_ID, splat_kmem_test2);
1280 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST3_NAME, SPLAT_KMEM_TEST3_DESC,
1281 SPLAT_KMEM_TEST3_ID, splat_kmem_test3);
1282 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST4_NAME, SPLAT_KMEM_TEST4_DESC,
1283 SPLAT_KMEM_TEST4_ID, splat_kmem_test4);
1284 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST5_NAME, SPLAT_KMEM_TEST5_DESC,
1285 SPLAT_KMEM_TEST5_ID, splat_kmem_test5);
1286 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST6_NAME, SPLAT_KMEM_TEST6_DESC,
1287 SPLAT_KMEM_TEST6_ID, splat_kmem_test6);
1288 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST7_NAME, SPLAT_KMEM_TEST7_DESC,
1289 SPLAT_KMEM_TEST7_ID, splat_kmem_test7);
1290 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST8_NAME, SPLAT_KMEM_TEST8_DESC,
1291 SPLAT_KMEM_TEST8_ID, splat_kmem_test8);
1292 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST9_NAME, SPLAT_KMEM_TEST9_DESC,
1293 SPLAT_KMEM_TEST9_ID, splat_kmem_test9);
1294 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST10_NAME, SPLAT_KMEM_TEST10_DESC,
1295 SPLAT_KMEM_TEST10_ID, splat_kmem_test10);
1296 #if 0
1297 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST11_NAME, SPLAT_KMEM_TEST11_DESC,
1298 SPLAT_KMEM_TEST11_ID, splat_kmem_test11);
1299 #endif
1300 SPLAT_TEST_INIT(sub, SPLAT_KMEM_TEST13_NAME, SPLAT_KMEM_TEST13_DESC,
1301 SPLAT_KMEM_TEST13_ID, splat_kmem_test13);
1302
1303 return sub;
1304 }
1305
1306 void
1307 splat_kmem_fini(splat_subsystem_t *sub)
1308 {
1309 ASSERT(sub);
1310 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST13_ID);
1311 #if 0
1312 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST11_ID);
1313 #endif
1314 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST10_ID);
1315 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST9_ID);
1316 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST8_ID);
1317 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST7_ID);
1318 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST6_ID);
1319 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST5_ID);
1320 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST4_ID);
1321 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST3_ID);
1322 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST2_ID);
1323 SPLAT_TEST_FINI(sub, SPLAT_KMEM_TEST1_ID);
1324
1325 kfree(sub);
1326 }
1327
1328 int
1329 splat_kmem_id(void) {
1330 return SPLAT_SUBSYSTEM_KMEM;
1331 }