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