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