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>.
8 * This file is part of the SPL, Solaris Porting Layer.
9 * For details, see <http://github.com/behlendorf/spl/>.
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.
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
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 (SPL) Kmem Implementation.
25 \*****************************************************************************/
29 #ifdef DEBUG_SUBSYSTEM
30 # undef DEBUG_SUBSYSTEM
33 #define DEBUG_SUBSYSTEM S_KMEM
36 * The minimum amount of memory measured in pages to be free at all
37 * times on the system. This is similar to Linux's zone->pages_min
38 * multipled by the number of zones and is sized based on that.
41 EXPORT_SYMBOL(minfree
);
44 * The desired amount of memory measured in pages to be free at all
45 * times on the system. This is similar to Linux's zone->pages_low
46 * multipled by the number of zones and is sized based on that.
47 * Assuming all zones are being used roughly equally, when we drop
48 * below this threshold async page reclamation is triggered.
51 EXPORT_SYMBOL(desfree
);
54 * When above this amount of memory measures in pages the system is
55 * determined to have enough free memory. This is similar to Linux's
56 * zone->pages_high multipled by the number of zones and is sized based
57 * on that. Assuming all zones are being used roughly equally, when
58 * async page reclamation reaches this threshold it stops.
61 EXPORT_SYMBOL(lotsfree
);
63 /* Unused always 0 in this implementation */
65 EXPORT_SYMBOL(needfree
);
67 pgcnt_t swapfs_minfree
= 0;
68 EXPORT_SYMBOL(swapfs_minfree
);
70 pgcnt_t swapfs_reserve
= 0;
71 EXPORT_SYMBOL(swapfs_reserve
);
73 vmem_t
*heap_arena
= NULL
;
74 EXPORT_SYMBOL(heap_arena
);
76 vmem_t
*zio_alloc_arena
= NULL
;
77 EXPORT_SYMBOL(zio_alloc_arena
);
79 vmem_t
*zio_arena
= NULL
;
80 EXPORT_SYMBOL(zio_arena
);
82 #ifndef HAVE_GET_VMALLOC_INFO
83 get_vmalloc_info_t get_vmalloc_info_fn
= SYMBOL_POISON
;
84 EXPORT_SYMBOL(get_vmalloc_info_fn
);
85 #endif /* HAVE_GET_VMALLOC_INFO */
87 #ifdef HAVE_PGDAT_HELPERS
88 # ifndef HAVE_FIRST_ONLINE_PGDAT
89 first_online_pgdat_t first_online_pgdat_fn
= SYMBOL_POISON
;
90 EXPORT_SYMBOL(first_online_pgdat_fn
);
91 # endif /* HAVE_FIRST_ONLINE_PGDAT */
93 # ifndef HAVE_NEXT_ONLINE_PGDAT
94 next_online_pgdat_t next_online_pgdat_fn
= SYMBOL_POISON
;
95 EXPORT_SYMBOL(next_online_pgdat_fn
);
96 # endif /* HAVE_NEXT_ONLINE_PGDAT */
98 # ifndef HAVE_NEXT_ZONE
99 next_zone_t next_zone_fn
= SYMBOL_POISON
;
100 EXPORT_SYMBOL(next_zone_fn
);
101 # endif /* HAVE_NEXT_ZONE */
103 #else /* HAVE_PGDAT_HELPERS */
105 # ifndef HAVE_PGDAT_LIST
106 struct pglist_data
*pgdat_list_addr
= SYMBOL_POISON
;
107 EXPORT_SYMBOL(pgdat_list_addr
);
108 # endif /* HAVE_PGDAT_LIST */
110 #endif /* HAVE_PGDAT_HELPERS */
112 #ifdef NEED_GET_ZONE_COUNTS
113 # ifndef HAVE_GET_ZONE_COUNTS
114 get_zone_counts_t get_zone_counts_fn
= SYMBOL_POISON
;
115 EXPORT_SYMBOL(get_zone_counts_fn
);
116 # endif /* HAVE_GET_ZONE_COUNTS */
119 spl_global_page_state(spl_zone_stat_item_t item
)
121 unsigned long active
;
122 unsigned long inactive
;
125 get_zone_counts(&active
, &inactive
, &free
);
127 case SPL_NR_FREE_PAGES
: return free
;
128 case SPL_NR_INACTIVE
: return inactive
;
129 case SPL_NR_ACTIVE
: return active
;
130 default: ASSERT(0); /* Unsupported */
136 # ifdef HAVE_GLOBAL_PAGE_STATE
138 spl_global_page_state(spl_zone_stat_item_t item
)
140 unsigned long pages
= 0;
143 case SPL_NR_FREE_PAGES
:
144 # ifdef HAVE_ZONE_STAT_ITEM_NR_FREE_PAGES
145 pages
+= global_page_state(NR_FREE_PAGES
);
148 case SPL_NR_INACTIVE
:
149 # ifdef HAVE_ZONE_STAT_ITEM_NR_INACTIVE
150 pages
+= global_page_state(NR_INACTIVE
);
152 # ifdef HAVE_ZONE_STAT_ITEM_NR_INACTIVE_ANON
153 pages
+= global_page_state(NR_INACTIVE_ANON
);
155 # ifdef HAVE_ZONE_STAT_ITEM_NR_INACTIVE_FILE
156 pages
+= global_page_state(NR_INACTIVE_FILE
);
160 # ifdef HAVE_ZONE_STAT_ITEM_NR_ACTIVE
161 pages
+= global_page_state(NR_ACTIVE
);
163 # ifdef HAVE_ZONE_STAT_ITEM_NR_ACTIVE_ANON
164 pages
+= global_page_state(NR_ACTIVE_ANON
);
166 # ifdef HAVE_ZONE_STAT_ITEM_NR_ACTIVE_FILE
167 pages
+= global_page_state(NR_ACTIVE_FILE
);
171 ASSERT(0); /* Unsupported */
177 # error "Both global_page_state() and get_zone_counts() unavailable"
178 # endif /* HAVE_GLOBAL_PAGE_STATE */
179 #endif /* NEED_GET_ZONE_COUNTS */
180 EXPORT_SYMBOL(spl_global_page_state
);
183 spl_kmem_availrmem(void)
185 /* The amount of easily available memory */
186 return (spl_global_page_state(SPL_NR_FREE_PAGES
) +
187 spl_global_page_state(SPL_NR_INACTIVE
));
189 EXPORT_SYMBOL(spl_kmem_availrmem
);
192 vmem_size(vmem_t
*vmp
, int typemask
)
194 struct vmalloc_info vmi
;
198 ASSERT(typemask
& (VMEM_ALLOC
| VMEM_FREE
));
200 get_vmalloc_info(&vmi
);
201 if (typemask
& VMEM_ALLOC
)
202 size
+= (size_t)vmi
.used
;
204 if (typemask
& VMEM_FREE
)
205 size
+= (size_t)(VMALLOC_TOTAL
- vmi
.used
);
209 EXPORT_SYMBOL(vmem_size
);
216 EXPORT_SYMBOL(kmem_debugging
);
218 #ifndef HAVE_KVASPRINTF
219 /* Simplified asprintf. */
220 char *kvasprintf(gfp_t gfp
, const char *fmt
, va_list ap
)
227 len
= vsnprintf(NULL
, 0, fmt
, aq
);
230 p
= kmalloc(len
+1, gfp
);
234 vsnprintf(p
, len
+1, fmt
, ap
);
238 EXPORT_SYMBOL(kvasprintf
);
239 #endif /* HAVE_KVASPRINTF */
242 kmem_asprintf(const char *fmt
, ...)
249 ptr
= kvasprintf(GFP_KERNEL
, fmt
, args
);
250 } while (ptr
== NULL
);
255 EXPORT_SYMBOL(kmem_asprintf
);
258 * Memory allocation interfaces and debugging for basic kmem_*
259 * and vmem_* style memory allocation. When DEBUG_KMEM is enabled
260 * the SPL will keep track of the total memory allocated, and
261 * report any memory leaked when the module is unloaded.
265 /* Shim layer memory accounting */
266 # ifdef HAVE_ATOMIC64_T
267 atomic64_t kmem_alloc_used
= ATOMIC64_INIT(0);
268 unsigned long long kmem_alloc_max
= 0;
269 atomic64_t vmem_alloc_used
= ATOMIC64_INIT(0);
270 unsigned long long vmem_alloc_max
= 0;
272 atomic_t kmem_alloc_used
= ATOMIC_INIT(0);
273 unsigned long long kmem_alloc_max
= 0;
274 atomic_t vmem_alloc_used
= ATOMIC_INIT(0);
275 unsigned long long vmem_alloc_max
= 0;
278 EXPORT_SYMBOL(kmem_alloc_used
);
279 EXPORT_SYMBOL(kmem_alloc_max
);
280 EXPORT_SYMBOL(vmem_alloc_used
);
281 EXPORT_SYMBOL(vmem_alloc_max
);
283 /* When DEBUG_KMEM_TRACKING is enabled not only will total bytes be tracked
284 * but also the location of every alloc and free. When the SPL module is
285 * unloaded a list of all leaked addresses and where they were allocated
286 * will be dumped to the console. Enabling this feature has a significant
287 * impact on performance but it makes finding memory leaks straight forward.
289 * Not surprisingly with debugging enabled the xmem_locks are very highly
290 * contended particularly on xfree(). If we want to run with this detailed
291 * debugging enabled for anything other than debugging we need to minimize
292 * the contention by moving to a lock per xmem_table entry model.
294 # ifdef DEBUG_KMEM_TRACKING
296 # define KMEM_HASH_BITS 10
297 # define KMEM_TABLE_SIZE (1 << KMEM_HASH_BITS)
299 # define VMEM_HASH_BITS 10
300 # define VMEM_TABLE_SIZE (1 << VMEM_HASH_BITS)
302 typedef struct kmem_debug
{
303 struct hlist_node kd_hlist
; /* Hash node linkage */
304 struct list_head kd_list
; /* List of all allocations */
305 void *kd_addr
; /* Allocation pointer */
306 size_t kd_size
; /* Allocation size */
307 const char *kd_func
; /* Allocation function */
308 int kd_line
; /* Allocation line */
311 spinlock_t kmem_lock
;
312 struct hlist_head kmem_table
[KMEM_TABLE_SIZE
];
313 struct list_head kmem_list
;
315 spinlock_t vmem_lock
;
316 struct hlist_head vmem_table
[VMEM_TABLE_SIZE
];
317 struct list_head vmem_list
;
319 EXPORT_SYMBOL(kmem_lock
);
320 EXPORT_SYMBOL(kmem_table
);
321 EXPORT_SYMBOL(kmem_list
);
323 EXPORT_SYMBOL(vmem_lock
);
324 EXPORT_SYMBOL(vmem_table
);
325 EXPORT_SYMBOL(vmem_list
);
330 * Slab allocation interfaces
332 * While the Linux slab implementation was inspired by the Solaris
333 * implemenation I cannot use it to emulate the Solaris APIs. I
334 * require two features which are not provided by the Linux slab.
336 * 1) Constructors AND destructors. Recent versions of the Linux
337 * kernel have removed support for destructors. This is a deal
338 * breaker for the SPL which contains particularly expensive
339 * initializers for mutex's, condition variables, etc. We also
340 * require a minimal level of cleanup for these data types unlike
341 * many Linux data type which do need to be explicitly destroyed.
343 * 2) Virtual address space backed slab. Callers of the Solaris slab
344 * expect it to work well for both small are very large allocations.
345 * Because of memory fragmentation the Linux slab which is backed
346 * by kmalloc'ed memory performs very badly when confronted with
347 * large numbers of large allocations. Basing the slab on the
348 * virtual address space removes the need for contigeous pages
349 * and greatly improve performance for large allocations.
351 * For these reasons, the SPL has its own slab implementation with
352 * the needed features. It is not as highly optimized as either the
353 * Solaris or Linux slabs, but it should get me most of what is
354 * needed until it can be optimized or obsoleted by another approach.
356 * One serious concern I do have about this method is the relatively
357 * small virtual address space on 32bit arches. This will seriously
358 * constrain the size of the slab caches and their performance.
360 * XXX: Improve the partial slab list by carefully maintaining a
361 * strict ordering of fullest to emptiest slabs based on
362 * the slab reference count. This gaurentees the when freeing
363 * slabs back to the system we need only linearly traverse the
364 * last N slabs in the list to discover all the freeable slabs.
366 * XXX: NUMA awareness for optionally allocating memory close to a
367 * particular core. This can be adventageous if you know the slab
368 * object will be short lived and primarily accessed from one core.
370 * XXX: Slab coloring may also yield performance improvements and would
371 * be desirable to implement.
374 struct list_head spl_kmem_cache_list
; /* List of caches */
375 struct rw_semaphore spl_kmem_cache_sem
; /* Cache list lock */
377 static int spl_cache_flush(spl_kmem_cache_t
*skc
,
378 spl_kmem_magazine_t
*skm
, int flush
);
380 #ifdef HAVE_SET_SHRINKER
381 static struct shrinker
*spl_kmem_cache_shrinker
;
383 static int spl_kmem_cache_generic_shrinker(int nr_to_scan
,
384 unsigned int gfp_mask
);
385 static struct shrinker spl_kmem_cache_shrinker
= {
386 .shrink
= spl_kmem_cache_generic_shrinker
,
387 .seeks
= KMC_DEFAULT_SEEKS
,
392 # ifdef DEBUG_KMEM_TRACKING
394 static kmem_debug_t
*
395 kmem_del_init(spinlock_t
*lock
, struct hlist_head
*table
, int bits
,
398 struct hlist_head
*head
;
399 struct hlist_node
*node
;
400 struct kmem_debug
*p
;
404 spin_lock_irqsave(lock
, flags
);
406 head
= &table
[hash_ptr(addr
, bits
)];
407 hlist_for_each_entry_rcu(p
, node
, head
, kd_hlist
) {
408 if (p
->kd_addr
== addr
) {
409 hlist_del_init(&p
->kd_hlist
);
410 list_del_init(&p
->kd_list
);
411 spin_unlock_irqrestore(lock
, flags
);
416 spin_unlock_irqrestore(lock
, flags
);
422 kmem_alloc_track(size_t size
, int flags
, const char *func
, int line
,
423 int node_alloc
, int node
)
427 unsigned long irq_flags
;
430 dptr
= (kmem_debug_t
*) kmalloc_nofail(sizeof(kmem_debug_t
),
431 flags
& ~__GFP_ZERO
);
434 CWARN("kmem_alloc(%ld, 0x%x) debug failed\n",
435 sizeof(kmem_debug_t
), flags
);
437 /* Marked unlikely because we should never be doing this,
438 * we tolerate to up 2 pages but a single page is best. */
439 if (unlikely((size
> PAGE_SIZE
*2) && !(flags
& KM_NODEBUG
))) {
440 CWARN("Large kmem_alloc(%llu, 0x%x) (%lld/%llu)\n",
441 (unsigned long long) size
, flags
,
442 kmem_alloc_used_read(), kmem_alloc_max
);
443 spl_debug_dumpstack(NULL
);
446 /* We use kstrdup() below because the string pointed to by
447 * __FUNCTION__ might not be available by the time we want
448 * to print it since the module might have been unloaded. */
449 dptr
->kd_func
= kstrdup(func
, flags
& ~__GFP_ZERO
);
450 if (unlikely(dptr
->kd_func
== NULL
)) {
452 CWARN("kstrdup() failed in kmem_alloc(%llu, 0x%x) "
453 "(%lld/%llu)\n", (unsigned long long) size
, flags
,
454 kmem_alloc_used_read(), kmem_alloc_max
);
458 /* Use the correct allocator */
460 ASSERT(!(flags
& __GFP_ZERO
));
461 ptr
= kmalloc_node_nofail(size
, flags
, node
);
462 } else if (flags
& __GFP_ZERO
) {
463 ptr
= kzalloc_nofail(size
, flags
& ~__GFP_ZERO
);
465 ptr
= kmalloc_nofail(size
, flags
);
468 if (unlikely(ptr
== NULL
)) {
469 kfree(dptr
->kd_func
);
471 CWARN("kmem_alloc(%llu, 0x%x) failed (%lld/%llu)\n",
472 (unsigned long long) size
, flags
,
473 kmem_alloc_used_read(), kmem_alloc_max
);
477 kmem_alloc_used_add(size
);
478 if (unlikely(kmem_alloc_used_read() > kmem_alloc_max
))
479 kmem_alloc_max
= kmem_alloc_used_read();
481 INIT_HLIST_NODE(&dptr
->kd_hlist
);
482 INIT_LIST_HEAD(&dptr
->kd_list
);
485 dptr
->kd_size
= size
;
486 dptr
->kd_line
= line
;
488 spin_lock_irqsave(&kmem_lock
, irq_flags
);
489 hlist_add_head_rcu(&dptr
->kd_hlist
,
490 &kmem_table
[hash_ptr(ptr
, KMEM_HASH_BITS
)]);
491 list_add_tail(&dptr
->kd_list
, &kmem_list
);
492 spin_unlock_irqrestore(&kmem_lock
, irq_flags
);
494 CDEBUG_LIMIT(D_INFO
, "kmem_alloc(%llu, 0x%x) = %p "
495 "(%lld/%llu)\n", (unsigned long long) size
, flags
,
496 ptr
, kmem_alloc_used_read(),
502 EXPORT_SYMBOL(kmem_alloc_track
);
505 kmem_free_track(void *ptr
, size_t size
)
510 ASSERTF(ptr
|| size
> 0, "ptr: %p, size: %llu", ptr
,
511 (unsigned long long) size
);
513 dptr
= kmem_del_init(&kmem_lock
, kmem_table
, KMEM_HASH_BITS
, ptr
);
515 ASSERT(dptr
); /* Must exist in hash due to kmem_alloc() */
517 /* Size must match */
518 ASSERTF(dptr
->kd_size
== size
, "kd_size (%llu) != size (%llu), "
519 "kd_func = %s, kd_line = %d\n", (unsigned long long) dptr
->kd_size
,
520 (unsigned long long) size
, dptr
->kd_func
, dptr
->kd_line
);
522 kmem_alloc_used_sub(size
);
523 CDEBUG_LIMIT(D_INFO
, "kmem_free(%p, %llu) (%lld/%llu)\n", ptr
,
524 (unsigned long long) size
, kmem_alloc_used_read(),
527 kfree(dptr
->kd_func
);
529 memset(dptr
, 0x5a, sizeof(kmem_debug_t
));
532 memset(ptr
, 0x5a, size
);
537 EXPORT_SYMBOL(kmem_free_track
);
540 vmem_alloc_track(size_t size
, int flags
, const char *func
, int line
)
544 unsigned long irq_flags
;
547 ASSERT(flags
& KM_SLEEP
);
549 dptr
= (kmem_debug_t
*) kmalloc_nofail(sizeof(kmem_debug_t
),
550 flags
& ~__GFP_ZERO
);
552 CWARN("vmem_alloc(%ld, 0x%x) debug failed\n",
553 sizeof(kmem_debug_t
), flags
);
555 /* We use kstrdup() below because the string pointed to by
556 * __FUNCTION__ might not be available by the time we want
557 * to print it, since the module might have been unloaded. */
558 dptr
->kd_func
= kstrdup(func
, flags
& ~__GFP_ZERO
);
559 if (unlikely(dptr
->kd_func
== NULL
)) {
561 CWARN("kstrdup() failed in vmem_alloc(%llu, 0x%x) "
562 "(%lld/%llu)\n", (unsigned long long) size
, flags
,
563 vmem_alloc_used_read(), vmem_alloc_max
);
567 ptr
= __vmalloc(size
, (flags
| __GFP_HIGHMEM
) & ~__GFP_ZERO
,
570 if (unlikely(ptr
== NULL
)) {
571 kfree(dptr
->kd_func
);
573 CWARN("vmem_alloc(%llu, 0x%x) failed (%lld/%llu)\n",
574 (unsigned long long) size
, flags
,
575 vmem_alloc_used_read(), vmem_alloc_max
);
579 if (flags
& __GFP_ZERO
)
580 memset(ptr
, 0, size
);
582 vmem_alloc_used_add(size
);
583 if (unlikely(vmem_alloc_used_read() > vmem_alloc_max
))
584 vmem_alloc_max
= vmem_alloc_used_read();
586 INIT_HLIST_NODE(&dptr
->kd_hlist
);
587 INIT_LIST_HEAD(&dptr
->kd_list
);
590 dptr
->kd_size
= size
;
591 dptr
->kd_line
= line
;
593 spin_lock_irqsave(&vmem_lock
, irq_flags
);
594 hlist_add_head_rcu(&dptr
->kd_hlist
,
595 &vmem_table
[hash_ptr(ptr
, VMEM_HASH_BITS
)]);
596 list_add_tail(&dptr
->kd_list
, &vmem_list
);
597 spin_unlock_irqrestore(&vmem_lock
, irq_flags
);
599 CDEBUG_LIMIT(D_INFO
, "vmem_alloc(%llu, 0x%x) = %p "
600 "(%lld/%llu)\n", (unsigned long long) size
, flags
,
601 ptr
, vmem_alloc_used_read(),
607 EXPORT_SYMBOL(vmem_alloc_track
);
610 vmem_free_track(void *ptr
, size_t size
)
615 ASSERTF(ptr
|| size
> 0, "ptr: %p, size: %llu", ptr
,
616 (unsigned long long) size
);
618 dptr
= kmem_del_init(&vmem_lock
, vmem_table
, VMEM_HASH_BITS
, ptr
);
619 ASSERT(dptr
); /* Must exist in hash due to vmem_alloc() */
621 /* Size must match */
622 ASSERTF(dptr
->kd_size
== size
, "kd_size (%llu) != size (%llu), "
623 "kd_func = %s, kd_line = %d\n", (unsigned long long) dptr
->kd_size
,
624 (unsigned long long) size
, dptr
->kd_func
, dptr
->kd_line
);
626 vmem_alloc_used_sub(size
);
627 CDEBUG_LIMIT(D_INFO
, "vmem_free(%p, %llu) (%lld/%llu)\n", ptr
,
628 (unsigned long long) size
, vmem_alloc_used_read(),
631 kfree(dptr
->kd_func
);
633 memset(dptr
, 0x5a, sizeof(kmem_debug_t
));
636 memset(ptr
, 0x5a, size
);
641 EXPORT_SYMBOL(vmem_free_track
);
643 # else /* DEBUG_KMEM_TRACKING */
646 kmem_alloc_debug(size_t size
, int flags
, const char *func
, int line
,
647 int node_alloc
, int node
)
652 /* Marked unlikely because we should never be doing this,
653 * we tolerate to up 2 pages but a single page is best. */
654 if (unlikely((size
> PAGE_SIZE
* 2) && !(flags
& KM_NODEBUG
))) {
655 CWARN("Large kmem_alloc(%llu, 0x%x) (%lld/%llu)\n",
656 (unsigned long long) size
, flags
,
657 kmem_alloc_used_read(), kmem_alloc_max
);
658 spl_debug_dumpstack(NULL
);
661 /* Use the correct allocator */
663 ASSERT(!(flags
& __GFP_ZERO
));
664 ptr
= kmalloc_node_nofail(size
, flags
, node
);
665 } else if (flags
& __GFP_ZERO
) {
666 ptr
= kzalloc_nofail(size
, flags
& (~__GFP_ZERO
));
668 ptr
= kmalloc_nofail(size
, flags
);
672 CWARN("kmem_alloc(%llu, 0x%x) failed (%lld/%llu)\n",
673 (unsigned long long) size
, flags
,
674 kmem_alloc_used_read(), kmem_alloc_max
);
676 kmem_alloc_used_add(size
);
677 if (unlikely(kmem_alloc_used_read() > kmem_alloc_max
))
678 kmem_alloc_max
= kmem_alloc_used_read();
680 CDEBUG_LIMIT(D_INFO
, "kmem_alloc(%llu, 0x%x) = %p "
681 "(%lld/%llu)\n", (unsigned long long) size
, flags
, ptr
,
682 kmem_alloc_used_read(), kmem_alloc_max
);
686 EXPORT_SYMBOL(kmem_alloc_debug
);
689 kmem_free_debug(void *ptr
, size_t size
)
693 ASSERTF(ptr
|| size
> 0, "ptr: %p, size: %llu", ptr
,
694 (unsigned long long) size
);
696 kmem_alloc_used_sub(size
);
697 CDEBUG_LIMIT(D_INFO
, "kmem_free(%p, %llu) (%lld/%llu)\n", ptr
,
698 (unsigned long long) size
, kmem_alloc_used_read(),
701 memset(ptr
, 0x5a, size
);
706 EXPORT_SYMBOL(kmem_free_debug
);
709 vmem_alloc_debug(size_t size
, int flags
, const char *func
, int line
)
714 ASSERT(flags
& KM_SLEEP
);
716 ptr
= __vmalloc(size
, (flags
| __GFP_HIGHMEM
) & ~__GFP_ZERO
,
719 CWARN("vmem_alloc(%llu, 0x%x) failed (%lld/%llu)\n",
720 (unsigned long long) size
, flags
,
721 vmem_alloc_used_read(), vmem_alloc_max
);
723 if (flags
& __GFP_ZERO
)
724 memset(ptr
, 0, size
);
726 vmem_alloc_used_add(size
);
727 if (unlikely(vmem_alloc_used_read() > vmem_alloc_max
))
728 vmem_alloc_max
= vmem_alloc_used_read();
730 CDEBUG_LIMIT(D_INFO
, "vmem_alloc(%llu, 0x%x) = %p "
731 "(%lld/%llu)\n", (unsigned long long) size
, flags
, ptr
,
732 vmem_alloc_used_read(), vmem_alloc_max
);
737 EXPORT_SYMBOL(vmem_alloc_debug
);
740 vmem_free_debug(void *ptr
, size_t size
)
744 ASSERTF(ptr
|| size
> 0, "ptr: %p, size: %llu", ptr
,
745 (unsigned long long) size
);
747 vmem_alloc_used_sub(size
);
748 CDEBUG_LIMIT(D_INFO
, "vmem_free(%p, %llu) (%lld/%llu)\n", ptr
,
749 (unsigned long long) size
, vmem_alloc_used_read(),
752 memset(ptr
, 0x5a, size
);
757 EXPORT_SYMBOL(vmem_free_debug
);
759 # endif /* DEBUG_KMEM_TRACKING */
760 #endif /* DEBUG_KMEM */
763 kv_alloc(spl_kmem_cache_t
*skc
, int size
, int flags
)
769 if (skc
->skc_flags
& KMC_KMEM
)
770 ptr
= (void *)__get_free_pages(flags
, get_order(size
));
772 ptr
= __vmalloc(size
, flags
| __GFP_HIGHMEM
, PAGE_KERNEL
);
774 /* Resulting allocated memory will be page aligned */
775 ASSERT(IS_P2ALIGNED(ptr
, PAGE_SIZE
));
781 kv_free(spl_kmem_cache_t
*skc
, void *ptr
, int size
)
783 ASSERT(IS_P2ALIGNED(ptr
, PAGE_SIZE
));
786 if (skc
->skc_flags
& KMC_KMEM
)
787 free_pages((unsigned long)ptr
, get_order(size
));
793 * Required space for each aligned sks.
795 static inline uint32_t
796 spl_sks_size(spl_kmem_cache_t
*skc
)
798 return P2ROUNDUP_TYPED(sizeof(spl_kmem_slab_t
),
799 skc
->skc_obj_align
, uint32_t);
803 * Required space for each aligned object.
805 static inline uint32_t
806 spl_obj_size(spl_kmem_cache_t
*skc
)
808 uint32_t align
= skc
->skc_obj_align
;
810 return P2ROUNDUP_TYPED(skc
->skc_obj_size
, align
, uint32_t) +
811 P2ROUNDUP_TYPED(sizeof(spl_kmem_obj_t
), align
, uint32_t);
815 * Lookup the spl_kmem_object_t for an object given that object.
817 static inline spl_kmem_obj_t
*
818 spl_sko_from_obj(spl_kmem_cache_t
*skc
, void *obj
)
820 return obj
+ P2ROUNDUP_TYPED(skc
->skc_obj_size
,
821 skc
->skc_obj_align
, uint32_t);
825 * Required space for each offslab object taking in to account alignment
826 * restrictions and the power-of-two requirement of kv_alloc().
828 static inline uint32_t
829 spl_offslab_size(spl_kmem_cache_t
*skc
)
831 return 1UL << (highbit(spl_obj_size(skc
)) + 1);
835 * It's important that we pack the spl_kmem_obj_t structure and the
836 * actual objects in to one large address space to minimize the number
837 * of calls to the allocator. It is far better to do a few large
838 * allocations and then subdivide it ourselves. Now which allocator
839 * we use requires balancing a few trade offs.
841 * For small objects we use kmem_alloc() because as long as you are
842 * only requesting a small number of pages (ideally just one) its cheap.
843 * However, when you start requesting multiple pages with kmem_alloc()
844 * it gets increasingly expensive since it requires contigeous pages.
845 * For this reason we shift to vmem_alloc() for slabs of large objects
846 * which removes the need for contigeous pages. We do not use
847 * vmem_alloc() in all cases because there is significant locking
848 * overhead in __get_vm_area_node(). This function takes a single
849 * global lock when aquiring an available virtual address range which
850 * serializes all vmem_alloc()'s for all slab caches. Using slightly
851 * different allocation functions for small and large objects should
852 * give us the best of both worlds.
854 * KMC_ONSLAB KMC_OFFSLAB
856 * +------------------------+ +-----------------+
857 * | spl_kmem_slab_t --+-+ | | spl_kmem_slab_t |---+-+
858 * | skc_obj_size <-+ | | +-----------------+ | |
859 * | spl_kmem_obj_t | | | |
860 * | skc_obj_size <---+ | +-----------------+ | |
861 * | spl_kmem_obj_t | | | skc_obj_size | <-+ |
862 * | ... v | | spl_kmem_obj_t | |
863 * +------------------------+ +-----------------+ v
865 static spl_kmem_slab_t
*
866 spl_slab_alloc(spl_kmem_cache_t
*skc
, int flags
)
868 spl_kmem_slab_t
*sks
;
869 spl_kmem_obj_t
*sko
, *n
;
871 uint32_t obj_size
, offslab_size
= 0;
874 base
= kv_alloc(skc
, skc
->skc_slab_size
, flags
);
878 sks
= (spl_kmem_slab_t
*)base
;
879 sks
->sks_magic
= SKS_MAGIC
;
880 sks
->sks_objs
= skc
->skc_slab_objs
;
881 sks
->sks_age
= jiffies
;
882 sks
->sks_cache
= skc
;
883 INIT_LIST_HEAD(&sks
->sks_list
);
884 INIT_LIST_HEAD(&sks
->sks_free_list
);
886 obj_size
= spl_obj_size(skc
);
888 if (skc
->skc_flags
* KMC_OFFSLAB
)
889 offslab_size
= spl_offslab_size(skc
);
891 for (i
= 0; i
< sks
->sks_objs
; i
++) {
892 if (skc
->skc_flags
& KMC_OFFSLAB
) {
893 obj
= kv_alloc(skc
, offslab_size
, flags
);
895 GOTO(out
, rc
= -ENOMEM
);
897 obj
= base
+ spl_sks_size(skc
) + (i
* obj_size
);
900 ASSERT(IS_P2ALIGNED(obj
, skc
->skc_obj_align
));
901 sko
= spl_sko_from_obj(skc
, obj
);
903 sko
->sko_magic
= SKO_MAGIC
;
905 INIT_LIST_HEAD(&sko
->sko_list
);
906 list_add_tail(&sko
->sko_list
, &sks
->sks_free_list
);
909 list_for_each_entry(sko
, &sks
->sks_free_list
, sko_list
)
911 skc
->skc_ctor(sko
->sko_addr
, skc
->skc_private
, flags
);
914 if (skc
->skc_flags
& KMC_OFFSLAB
)
915 list_for_each_entry_safe(sko
, n
, &sks
->sks_free_list
,
917 kv_free(skc
, sko
->sko_addr
, offslab_size
);
919 kv_free(skc
, base
, skc
->skc_slab_size
);
927 * Remove a slab from complete or partial list, it must be called with
928 * the 'skc->skc_lock' held but the actual free must be performed
929 * outside the lock to prevent deadlocking on vmem addresses.
932 spl_slab_free(spl_kmem_slab_t
*sks
,
933 struct list_head
*sks_list
, struct list_head
*sko_list
)
935 spl_kmem_cache_t
*skc
;
938 ASSERT(sks
->sks_magic
== SKS_MAGIC
);
939 ASSERT(sks
->sks_ref
== 0);
941 skc
= sks
->sks_cache
;
942 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
943 ASSERT(spin_is_locked(&skc
->skc_lock
));
946 * Update slab/objects counters in the cache, then remove the
947 * slab from the skc->skc_partial_list. Finally add the slab
948 * and all its objects in to the private work lists where the
949 * destructors will be called and the memory freed to the system.
951 skc
->skc_obj_total
-= sks
->sks_objs
;
952 skc
->skc_slab_total
--;
953 list_del(&sks
->sks_list
);
954 list_add(&sks
->sks_list
, sks_list
);
955 list_splice_init(&sks
->sks_free_list
, sko_list
);
961 * Traverses all the partial slabs attached to a cache and free those
962 * which which are currently empty, and have not been touched for
963 * skc_delay seconds to avoid thrashing. The count argument is
964 * passed to optionally cap the number of slabs reclaimed, a count
965 * of zero means try and reclaim everything. When flag is set we
966 * always free an available slab regardless of age.
969 spl_slab_reclaim(spl_kmem_cache_t
*skc
, int count
, int flag
)
971 spl_kmem_slab_t
*sks
, *m
;
972 spl_kmem_obj_t
*sko
, *n
;
980 * Move empty slabs and objects which have not been touched in
981 * skc_delay seconds on to private lists to be freed outside
982 * the spin lock. This delay time is important to avoid thrashing
983 * however when flag is set the delay will not be used.
985 spin_lock(&skc
->skc_lock
);
986 list_for_each_entry_safe_reverse(sks
,m
,&skc
->skc_partial_list
,sks_list
){
988 * All empty slabs are at the end of skc->skc_partial_list,
989 * therefore once a non-empty slab is found we can stop
990 * scanning. Additionally, stop when reaching the target
991 * reclaim 'count' if a non-zero threshhold is given.
993 if ((sks
->sks_ref
> 0) || (count
&& i
> count
))
996 if (time_after(jiffies
,sks
->sks_age
+skc
->skc_delay
*HZ
)||flag
) {
997 spl_slab_free(sks
, &sks_list
, &sko_list
);
1001 spin_unlock(&skc
->skc_lock
);
1004 * The following two loops ensure all the object destructors are
1005 * run, any offslab objects are freed, and the slabs themselves
1006 * are freed. This is all done outside the skc->skc_lock since
1007 * this allows the destructor to sleep, and allows us to perform
1008 * a conditional reschedule when a freeing a large number of
1009 * objects and slabs back to the system.
1011 if (skc
->skc_flags
& KMC_OFFSLAB
)
1012 size
= spl_offslab_size(skc
);
1014 list_for_each_entry_safe(sko
, n
, &sko_list
, sko_list
) {
1015 ASSERT(sko
->sko_magic
== SKO_MAGIC
);
1018 skc
->skc_dtor(sko
->sko_addr
, skc
->skc_private
);
1020 if (skc
->skc_flags
& KMC_OFFSLAB
)
1021 kv_free(skc
, sko
->sko_addr
, size
);
1026 list_for_each_entry_safe(sks
, m
, &sks_list
, sks_list
) {
1027 ASSERT(sks
->sks_magic
== SKS_MAGIC
);
1028 kv_free(skc
, sks
, skc
->skc_slab_size
);
1036 * Called regularly on all caches to age objects out of the magazines
1037 * which have not been access in skc->skc_delay seconds. This prevents
1038 * idle magazines from holding memory which might be better used by
1039 * other caches or parts of the system. The delay is present to
1040 * prevent thrashing the magazine.
1043 spl_magazine_age(void *data
)
1045 spl_kmem_magazine_t
*skm
=
1046 spl_get_work_data(data
, spl_kmem_magazine_t
, skm_work
.work
);
1047 spl_kmem_cache_t
*skc
= skm
->skm_cache
;
1048 int i
= smp_processor_id();
1050 ASSERT(skm
->skm_magic
== SKM_MAGIC
);
1051 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1052 ASSERT(skc
->skc_mag
[i
] == skm
);
1054 if (skm
->skm_avail
> 0 &&
1055 time_after(jiffies
, skm
->skm_age
+ skc
->skc_delay
* HZ
))
1056 (void)spl_cache_flush(skc
, skm
, skm
->skm_refill
);
1058 if (!test_bit(KMC_BIT_DESTROY
, &skc
->skc_flags
))
1059 schedule_delayed_work_on(i
, &skm
->skm_work
,
1060 skc
->skc_delay
/ 3 * HZ
);
1064 * Called regularly to keep a downward pressure on the size of idle
1065 * magazines and to release free slabs from the cache. This function
1066 * never calls the registered reclaim function, that only occures
1067 * under memory pressure or with a direct call to spl_kmem_reap().
1070 spl_cache_age(void *data
)
1072 spl_kmem_cache_t
*skc
=
1073 spl_get_work_data(data
, spl_kmem_cache_t
, skc_work
.work
);
1075 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1076 spl_slab_reclaim(skc
, skc
->skc_reap
, 0);
1078 if (!test_bit(KMC_BIT_DESTROY
, &skc
->skc_flags
))
1079 schedule_delayed_work(&skc
->skc_work
, skc
->skc_delay
/ 3 * HZ
);
1083 * Size a slab based on the size of each aligned object plus spl_kmem_obj_t.
1084 * When on-slab we want to target SPL_KMEM_CACHE_OBJ_PER_SLAB. However,
1085 * for very small objects we may end up with more than this so as not
1086 * to waste space in the minimal allocation of a single page. Also for
1087 * very large objects we may use as few as SPL_KMEM_CACHE_OBJ_PER_SLAB_MIN,
1088 * lower than this and we will fail.
1091 spl_slab_size(spl_kmem_cache_t
*skc
, uint32_t *objs
, uint32_t *size
)
1093 uint32_t sks_size
, obj_size
, max_size
;
1095 if (skc
->skc_flags
& KMC_OFFSLAB
) {
1096 *objs
= SPL_KMEM_CACHE_OBJ_PER_SLAB
;
1097 *size
= sizeof(spl_kmem_slab_t
);
1099 sks_size
= spl_sks_size(skc
);
1100 obj_size
= spl_obj_size(skc
);
1102 if (skc
->skc_flags
& KMC_KMEM
)
1103 max_size
= ((uint32_t)1 << (MAX_ORDER
-3)) * PAGE_SIZE
;
1105 max_size
= (32 * 1024 * 1024);
1107 /* Power of two sized slab */
1108 for (*size
= PAGE_SIZE
; *size
<= max_size
; *size
*= 2) {
1109 *objs
= (*size
- sks_size
) / obj_size
;
1110 if (*objs
>= SPL_KMEM_CACHE_OBJ_PER_SLAB
)
1115 * Unable to satisfy target objects per slab, fall back to
1116 * allocating a maximally sized slab and assuming it can
1117 * contain the minimum objects count use it. If not fail.
1120 *objs
= (*size
- sks_size
) / obj_size
;
1121 if (*objs
>= SPL_KMEM_CACHE_OBJ_PER_SLAB_MIN
)
1129 * Make a guess at reasonable per-cpu magazine size based on the size of
1130 * each object and the cost of caching N of them in each magazine. Long
1131 * term this should really adapt based on an observed usage heuristic.
1134 spl_magazine_size(spl_kmem_cache_t
*skc
)
1136 uint32_t obj_size
= spl_obj_size(skc
);
1140 /* Per-magazine sizes below assume a 4Kib page size */
1141 if (obj_size
> (PAGE_SIZE
* 256))
1142 size
= 4; /* Minimum 4Mib per-magazine */
1143 else if (obj_size
> (PAGE_SIZE
* 32))
1144 size
= 16; /* Minimum 2Mib per-magazine */
1145 else if (obj_size
> (PAGE_SIZE
))
1146 size
= 64; /* Minimum 256Kib per-magazine */
1147 else if (obj_size
> (PAGE_SIZE
/ 4))
1148 size
= 128; /* Minimum 128Kib per-magazine */
1156 * Allocate a per-cpu magazine to assoicate with a specific core.
1158 static spl_kmem_magazine_t
*
1159 spl_magazine_alloc(spl_kmem_cache_t
*skc
, int node
)
1161 spl_kmem_magazine_t
*skm
;
1162 int size
= sizeof(spl_kmem_magazine_t
) +
1163 sizeof(void *) * skc
->skc_mag_size
;
1166 skm
= kmem_alloc_node(size
, KM_SLEEP
, node
);
1168 skm
->skm_magic
= SKM_MAGIC
;
1170 skm
->skm_size
= skc
->skc_mag_size
;
1171 skm
->skm_refill
= skc
->skc_mag_refill
;
1172 skm
->skm_cache
= skc
;
1173 spl_init_delayed_work(&skm
->skm_work
, spl_magazine_age
, skm
);
1174 skm
->skm_age
= jiffies
;
1181 * Free a per-cpu magazine assoicated with a specific core.
1184 spl_magazine_free(spl_kmem_magazine_t
*skm
)
1186 int size
= sizeof(spl_kmem_magazine_t
) +
1187 sizeof(void *) * skm
->skm_size
;
1190 ASSERT(skm
->skm_magic
== SKM_MAGIC
);
1191 ASSERT(skm
->skm_avail
== 0);
1193 kmem_free(skm
, size
);
1198 * Create all pre-cpu magazines of reasonable sizes.
1201 spl_magazine_create(spl_kmem_cache_t
*skc
)
1206 skc
->skc_mag_size
= spl_magazine_size(skc
);
1207 skc
->skc_mag_refill
= (skc
->skc_mag_size
+ 1) / 2;
1209 for_each_online_cpu(i
) {
1210 skc
->skc_mag
[i
] = spl_magazine_alloc(skc
, cpu_to_node(i
));
1211 if (!skc
->skc_mag
[i
]) {
1212 for (i
--; i
>= 0; i
--)
1213 spl_magazine_free(skc
->skc_mag
[i
]);
1219 /* Only after everything is allocated schedule magazine work */
1220 for_each_online_cpu(i
)
1221 schedule_delayed_work_on(i
, &skc
->skc_mag
[i
]->skm_work
,
1222 skc
->skc_delay
/ 3 * HZ
);
1228 * Destroy all pre-cpu magazines.
1231 spl_magazine_destroy(spl_kmem_cache_t
*skc
)
1233 spl_kmem_magazine_t
*skm
;
1237 for_each_online_cpu(i
) {
1238 skm
= skc
->skc_mag
[i
];
1239 (void)spl_cache_flush(skc
, skm
, skm
->skm_avail
);
1240 spl_magazine_free(skm
);
1247 * Create a object cache based on the following arguments:
1249 * size cache object size
1250 * align cache object alignment
1251 * ctor cache object constructor
1252 * dtor cache object destructor
1253 * reclaim cache object reclaim
1254 * priv cache private data for ctor/dtor/reclaim
1255 * vmp unused must be NULL
1257 * KMC_NOTOUCH Disable cache object aging (unsupported)
1258 * KMC_NODEBUG Disable debugging (unsupported)
1259 * KMC_NOMAGAZINE Disable magazine (unsupported)
1260 * KMC_NOHASH Disable hashing (unsupported)
1261 * KMC_QCACHE Disable qcache (unsupported)
1262 * KMC_KMEM Force kmem backed cache
1263 * KMC_VMEM Force vmem backed cache
1264 * KMC_OFFSLAB Locate objects off the slab
1267 spl_kmem_cache_create(char *name
, size_t size
, size_t align
,
1268 spl_kmem_ctor_t ctor
,
1269 spl_kmem_dtor_t dtor
,
1270 spl_kmem_reclaim_t reclaim
,
1271 void *priv
, void *vmp
, int flags
)
1273 spl_kmem_cache_t
*skc
;
1274 int rc
, kmem_flags
= KM_SLEEP
;
1277 ASSERTF(!(flags
& KMC_NOMAGAZINE
), "Bad KMC_NOMAGAZINE (%x)\n", flags
);
1278 ASSERTF(!(flags
& KMC_NOHASH
), "Bad KMC_NOHASH (%x)\n", flags
);
1279 ASSERTF(!(flags
& KMC_QCACHE
), "Bad KMC_QCACHE (%x)\n", flags
);
1280 ASSERT(vmp
== NULL
);
1282 /* We may be called when there is a non-zero preempt_count or
1283 * interrupts are disabled is which case we must not sleep.
1285 if (current_thread_info()->preempt_count
|| irqs_disabled())
1286 kmem_flags
= KM_NOSLEEP
;
1288 /* Allocate memry for a new cache an initialize it. Unfortunately,
1289 * this usually ends up being a large allocation of ~32k because
1290 * we need to allocate enough memory for the worst case number of
1291 * cpus in the magazine, skc_mag[NR_CPUS]. Because of this we
1292 * explicitly pass KM_NODEBUG to suppress the kmem warning */
1293 skc
= (spl_kmem_cache_t
*)kmem_zalloc(sizeof(*skc
),
1294 kmem_flags
| KM_NODEBUG
);
1298 skc
->skc_magic
= SKC_MAGIC
;
1299 skc
->skc_name_size
= strlen(name
) + 1;
1300 skc
->skc_name
= (char *)kmem_alloc(skc
->skc_name_size
, kmem_flags
);
1301 if (skc
->skc_name
== NULL
) {
1302 kmem_free(skc
, sizeof(*skc
));
1305 strncpy(skc
->skc_name
, name
, skc
->skc_name_size
);
1307 skc
->skc_ctor
= ctor
;
1308 skc
->skc_dtor
= dtor
;
1309 skc
->skc_reclaim
= reclaim
;
1310 skc
->skc_private
= priv
;
1312 skc
->skc_flags
= flags
;
1313 skc
->skc_obj_size
= size
;
1314 skc
->skc_obj_align
= SPL_KMEM_CACHE_ALIGN
;
1315 skc
->skc_delay
= SPL_KMEM_CACHE_DELAY
;
1316 skc
->skc_reap
= SPL_KMEM_CACHE_REAP
;
1317 atomic_set(&skc
->skc_ref
, 0);
1319 INIT_LIST_HEAD(&skc
->skc_list
);
1320 INIT_LIST_HEAD(&skc
->skc_complete_list
);
1321 INIT_LIST_HEAD(&skc
->skc_partial_list
);
1322 spin_lock_init(&skc
->skc_lock
);
1323 skc
->skc_slab_fail
= 0;
1324 skc
->skc_slab_create
= 0;
1325 skc
->skc_slab_destroy
= 0;
1326 skc
->skc_slab_total
= 0;
1327 skc
->skc_slab_alloc
= 0;
1328 skc
->skc_slab_max
= 0;
1329 skc
->skc_obj_total
= 0;
1330 skc
->skc_obj_alloc
= 0;
1331 skc
->skc_obj_max
= 0;
1334 VERIFY(ISP2(align
));
1335 VERIFY3U(align
, >=, SPL_KMEM_CACHE_ALIGN
); /* Min alignment */
1336 VERIFY3U(align
, <=, PAGE_SIZE
); /* Max alignment */
1337 skc
->skc_obj_align
= align
;
1340 /* If none passed select a cache type based on object size */
1341 if (!(skc
->skc_flags
& (KMC_KMEM
| KMC_VMEM
))) {
1342 if (spl_obj_size(skc
) < (PAGE_SIZE
/ 8))
1343 skc
->skc_flags
|= KMC_KMEM
;
1345 skc
->skc_flags
|= KMC_VMEM
;
1348 rc
= spl_slab_size(skc
, &skc
->skc_slab_objs
, &skc
->skc_slab_size
);
1352 rc
= spl_magazine_create(skc
);
1356 spl_init_delayed_work(&skc
->skc_work
, spl_cache_age
, skc
);
1357 schedule_delayed_work(&skc
->skc_work
, skc
->skc_delay
/ 3 * HZ
);
1359 down_write(&spl_kmem_cache_sem
);
1360 list_add_tail(&skc
->skc_list
, &spl_kmem_cache_list
);
1361 up_write(&spl_kmem_cache_sem
);
1365 kmem_free(skc
->skc_name
, skc
->skc_name_size
);
1366 kmem_free(skc
, sizeof(*skc
));
1369 EXPORT_SYMBOL(spl_kmem_cache_create
);
1372 * Destroy a cache and all objects assoicated with the cache.
1375 spl_kmem_cache_destroy(spl_kmem_cache_t
*skc
)
1377 DECLARE_WAIT_QUEUE_HEAD(wq
);
1381 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1383 down_write(&spl_kmem_cache_sem
);
1384 list_del_init(&skc
->skc_list
);
1385 up_write(&spl_kmem_cache_sem
);
1387 /* Cancel any and wait for any pending delayed work */
1388 ASSERT(!test_and_set_bit(KMC_BIT_DESTROY
, &skc
->skc_flags
));
1389 cancel_delayed_work(&skc
->skc_work
);
1390 for_each_online_cpu(i
)
1391 cancel_delayed_work(&skc
->skc_mag
[i
]->skm_work
);
1393 flush_scheduled_work();
1395 /* Wait until all current callers complete, this is mainly
1396 * to catch the case where a low memory situation triggers a
1397 * cache reaping action which races with this destroy. */
1398 wait_event(wq
, atomic_read(&skc
->skc_ref
) == 0);
1400 spl_magazine_destroy(skc
);
1401 spl_slab_reclaim(skc
, 0, 1);
1402 spin_lock(&skc
->skc_lock
);
1404 /* Validate there are no objects in use and free all the
1405 * spl_kmem_slab_t, spl_kmem_obj_t, and object buffers. */
1406 ASSERT3U(skc
->skc_slab_alloc
, ==, 0);
1407 ASSERT3U(skc
->skc_obj_alloc
, ==, 0);
1408 ASSERT3U(skc
->skc_slab_total
, ==, 0);
1409 ASSERT3U(skc
->skc_obj_total
, ==, 0);
1410 ASSERT(list_empty(&skc
->skc_complete_list
));
1412 kmem_free(skc
->skc_name
, skc
->skc_name_size
);
1413 spin_unlock(&skc
->skc_lock
);
1415 kmem_free(skc
, sizeof(*skc
));
1419 EXPORT_SYMBOL(spl_kmem_cache_destroy
);
1422 * Allocate an object from a slab attached to the cache. This is used to
1423 * repopulate the per-cpu magazine caches in batches when they run low.
1426 spl_cache_obj(spl_kmem_cache_t
*skc
, spl_kmem_slab_t
*sks
)
1428 spl_kmem_obj_t
*sko
;
1430 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1431 ASSERT(sks
->sks_magic
== SKS_MAGIC
);
1432 ASSERT(spin_is_locked(&skc
->skc_lock
));
1434 sko
= list_entry(sks
->sks_free_list
.next
, spl_kmem_obj_t
, sko_list
);
1435 ASSERT(sko
->sko_magic
== SKO_MAGIC
);
1436 ASSERT(sko
->sko_addr
!= NULL
);
1438 /* Remove from sks_free_list */
1439 list_del_init(&sko
->sko_list
);
1441 sks
->sks_age
= jiffies
;
1443 skc
->skc_obj_alloc
++;
1445 /* Track max obj usage statistics */
1446 if (skc
->skc_obj_alloc
> skc
->skc_obj_max
)
1447 skc
->skc_obj_max
= skc
->skc_obj_alloc
;
1449 /* Track max slab usage statistics */
1450 if (sks
->sks_ref
== 1) {
1451 skc
->skc_slab_alloc
++;
1453 if (skc
->skc_slab_alloc
> skc
->skc_slab_max
)
1454 skc
->skc_slab_max
= skc
->skc_slab_alloc
;
1457 return sko
->sko_addr
;
1461 * No available objects on any slabsi, create a new slab. Since this
1462 * is an expensive operation we do it without holding the spinlock and
1463 * only briefly aquire it when we link in the fully allocated and
1466 static spl_kmem_slab_t
*
1467 spl_cache_grow(spl_kmem_cache_t
*skc
, int flags
)
1469 spl_kmem_slab_t
*sks
;
1472 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1477 * Before allocating a new slab check if the slab is being reaped.
1478 * If it is there is a good chance we can wait until it finishes
1479 * and then use one of the newly freed but not aged-out slabs.
1481 if (test_bit(KMC_BIT_REAPING
, &skc
->skc_flags
)) {
1483 GOTO(out
, sks
= NULL
);
1486 /* Allocate a new slab for the cache */
1487 sks
= spl_slab_alloc(skc
, flags
| __GFP_NORETRY
| KM_NODEBUG
);
1489 GOTO(out
, sks
= NULL
);
1491 /* Link the new empty slab in to the end of skc_partial_list. */
1492 spin_lock(&skc
->skc_lock
);
1493 skc
->skc_slab_total
++;
1494 skc
->skc_obj_total
+= sks
->sks_objs
;
1495 list_add_tail(&sks
->sks_list
, &skc
->skc_partial_list
);
1496 spin_unlock(&skc
->skc_lock
);
1498 local_irq_disable();
1504 * Refill a per-cpu magazine with objects from the slabs for this
1505 * cache. Ideally the magazine can be repopulated using existing
1506 * objects which have been released, however if we are unable to
1507 * locate enough free objects new slabs of objects will be created.
1510 spl_cache_refill(spl_kmem_cache_t
*skc
, spl_kmem_magazine_t
*skm
, int flags
)
1512 spl_kmem_slab_t
*sks
;
1516 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1517 ASSERT(skm
->skm_magic
== SKM_MAGIC
);
1519 refill
= MIN(skm
->skm_refill
, skm
->skm_size
- skm
->skm_avail
);
1520 spin_lock(&skc
->skc_lock
);
1522 while (refill
> 0) {
1523 /* No slabs available we may need to grow the cache */
1524 if (list_empty(&skc
->skc_partial_list
)) {
1525 spin_unlock(&skc
->skc_lock
);
1527 sks
= spl_cache_grow(skc
, flags
);
1531 /* Rescheduled to different CPU skm is not local */
1532 if (skm
!= skc
->skc_mag
[smp_processor_id()])
1535 /* Potentially rescheduled to the same CPU but
1536 * allocations may have occured from this CPU while
1537 * we were sleeping so recalculate max refill. */
1538 refill
= MIN(refill
, skm
->skm_size
- skm
->skm_avail
);
1540 spin_lock(&skc
->skc_lock
);
1544 /* Grab the next available slab */
1545 sks
= list_entry((&skc
->skc_partial_list
)->next
,
1546 spl_kmem_slab_t
, sks_list
);
1547 ASSERT(sks
->sks_magic
== SKS_MAGIC
);
1548 ASSERT(sks
->sks_ref
< sks
->sks_objs
);
1549 ASSERT(!list_empty(&sks
->sks_free_list
));
1551 /* Consume as many objects as needed to refill the requested
1552 * cache. We must also be careful not to overfill it. */
1553 while (sks
->sks_ref
< sks
->sks_objs
&& refill
-- > 0 && ++rc
) {
1554 ASSERT(skm
->skm_avail
< skm
->skm_size
);
1555 ASSERT(rc
< skm
->skm_size
);
1556 skm
->skm_objs
[skm
->skm_avail
++]=spl_cache_obj(skc
,sks
);
1559 /* Move slab to skc_complete_list when full */
1560 if (sks
->sks_ref
== sks
->sks_objs
) {
1561 list_del(&sks
->sks_list
);
1562 list_add(&sks
->sks_list
, &skc
->skc_complete_list
);
1566 spin_unlock(&skc
->skc_lock
);
1568 /* Returns the number of entries added to cache */
1573 * Release an object back to the slab from which it came.
1576 spl_cache_shrink(spl_kmem_cache_t
*skc
, void *obj
)
1578 spl_kmem_slab_t
*sks
= NULL
;
1579 spl_kmem_obj_t
*sko
= NULL
;
1582 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1583 ASSERT(spin_is_locked(&skc
->skc_lock
));
1585 sko
= spl_sko_from_obj(skc
, obj
);
1586 ASSERT(sko
->sko_magic
== SKO_MAGIC
);
1587 sks
= sko
->sko_slab
;
1588 ASSERT(sks
->sks_magic
== SKS_MAGIC
);
1589 ASSERT(sks
->sks_cache
== skc
);
1590 list_add(&sko
->sko_list
, &sks
->sks_free_list
);
1592 sks
->sks_age
= jiffies
;
1594 skc
->skc_obj_alloc
--;
1596 /* Move slab to skc_partial_list when no longer full. Slabs
1597 * are added to the head to keep the partial list is quasi-full
1598 * sorted order. Fuller at the head, emptier at the tail. */
1599 if (sks
->sks_ref
== (sks
->sks_objs
- 1)) {
1600 list_del(&sks
->sks_list
);
1601 list_add(&sks
->sks_list
, &skc
->skc_partial_list
);
1604 /* Move emply slabs to the end of the partial list so
1605 * they can be easily found and freed during reclamation. */
1606 if (sks
->sks_ref
== 0) {
1607 list_del(&sks
->sks_list
);
1608 list_add_tail(&sks
->sks_list
, &skc
->skc_partial_list
);
1609 skc
->skc_slab_alloc
--;
1616 * Release a batch of objects from a per-cpu magazine back to their
1617 * respective slabs. This occurs when we exceed the magazine size,
1618 * are under memory pressure, when the cache is idle, or during
1619 * cache cleanup. The flush argument contains the number of entries
1620 * to remove from the magazine.
1623 spl_cache_flush(spl_kmem_cache_t
*skc
, spl_kmem_magazine_t
*skm
, int flush
)
1625 int i
, count
= MIN(flush
, skm
->skm_avail
);
1628 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1629 ASSERT(skm
->skm_magic
== SKM_MAGIC
);
1632 * XXX: Currently we simply return objects from the magazine to
1633 * the slabs in fifo order. The ideal thing to do from a memory
1634 * fragmentation standpoint is to cheaply determine the set of
1635 * objects in the magazine which will result in the largest
1636 * number of free slabs if released from the magazine.
1638 spin_lock(&skc
->skc_lock
);
1639 for (i
= 0; i
< count
; i
++)
1640 spl_cache_shrink(skc
, skm
->skm_objs
[i
]);
1642 skm
->skm_avail
-= count
;
1643 memmove(skm
->skm_objs
, &(skm
->skm_objs
[count
]),
1644 sizeof(void *) * skm
->skm_avail
);
1646 spin_unlock(&skc
->skc_lock
);
1652 * Allocate an object from the per-cpu magazine, or if the magazine
1653 * is empty directly allocate from a slab and repopulate the magazine.
1656 spl_kmem_cache_alloc(spl_kmem_cache_t
*skc
, int flags
)
1658 spl_kmem_magazine_t
*skm
;
1659 unsigned long irq_flags
;
1663 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1664 ASSERT(!test_bit(KMC_BIT_DESTROY
, &skc
->skc_flags
));
1665 ASSERT(flags
& KM_SLEEP
);
1666 atomic_inc(&skc
->skc_ref
);
1667 local_irq_save(irq_flags
);
1670 /* Safe to update per-cpu structure without lock, but
1671 * in the restart case we must be careful to reaquire
1672 * the local magazine since this may have changed
1673 * when we need to grow the cache. */
1674 skm
= skc
->skc_mag
[smp_processor_id()];
1675 ASSERTF(skm
->skm_magic
== SKM_MAGIC
, "%x != %x: %s/%p/%p %x/%x/%x\n",
1676 skm
->skm_magic
, SKM_MAGIC
, skc
->skc_name
, skc
, skm
,
1677 skm
->skm_size
, skm
->skm_refill
, skm
->skm_avail
);
1679 if (likely(skm
->skm_avail
)) {
1680 /* Object available in CPU cache, use it */
1681 obj
= skm
->skm_objs
[--skm
->skm_avail
];
1682 skm
->skm_age
= jiffies
;
1684 /* Per-CPU cache empty, directly allocate from
1685 * the slab and refill the per-CPU cache. */
1686 (void)spl_cache_refill(skc
, skm
, flags
);
1687 GOTO(restart
, obj
= NULL
);
1690 local_irq_restore(irq_flags
);
1692 ASSERT(IS_P2ALIGNED(obj
, skc
->skc_obj_align
));
1694 /* Pre-emptively migrate object to CPU L1 cache */
1696 atomic_dec(&skc
->skc_ref
);
1700 EXPORT_SYMBOL(spl_kmem_cache_alloc
);
1703 * Free an object back to the local per-cpu magazine, there is no
1704 * guarantee that this is the same magazine the object was originally
1705 * allocated from. We may need to flush entire from the magazine
1706 * back to the slabs to make space.
1709 spl_kmem_cache_free(spl_kmem_cache_t
*skc
, void *obj
)
1711 spl_kmem_magazine_t
*skm
;
1712 unsigned long flags
;
1715 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1716 ASSERT(!test_bit(KMC_BIT_DESTROY
, &skc
->skc_flags
));
1717 atomic_inc(&skc
->skc_ref
);
1718 local_irq_save(flags
);
1720 /* Safe to update per-cpu structure without lock, but
1721 * no remote memory allocation tracking is being performed
1722 * it is entirely possible to allocate an object from one
1723 * CPU cache and return it to another. */
1724 skm
= skc
->skc_mag
[smp_processor_id()];
1725 ASSERT(skm
->skm_magic
== SKM_MAGIC
);
1727 /* Per-CPU cache full, flush it to make space */
1728 if (unlikely(skm
->skm_avail
>= skm
->skm_size
))
1729 (void)spl_cache_flush(skc
, skm
, skm
->skm_refill
);
1731 /* Available space in cache, use it */
1732 skm
->skm_objs
[skm
->skm_avail
++] = obj
;
1734 local_irq_restore(flags
);
1735 atomic_dec(&skc
->skc_ref
);
1739 EXPORT_SYMBOL(spl_kmem_cache_free
);
1742 * The generic shrinker function for all caches. Under linux a shrinker
1743 * may not be tightly coupled with a slab cache. In fact linux always
1744 * systematically trys calling all registered shrinker callbacks which
1745 * report that they contain unused objects. Because of this we only
1746 * register one shrinker function in the shim layer for all slab caches.
1747 * We always attempt to shrink all caches when this generic shrinker
1748 * is called. The shrinker should return the number of free objects
1749 * in the cache when called with nr_to_scan == 0 but not attempt to
1750 * free any objects. When nr_to_scan > 0 it is a request that nr_to_scan
1751 * objects should be freed, because Solaris semantics are to free
1752 * all available objects we may free more objects than requested.
1755 spl_kmem_cache_generic_shrinker(int nr_to_scan
, unsigned int gfp_mask
)
1757 spl_kmem_cache_t
*skc
;
1760 down_read(&spl_kmem_cache_sem
);
1761 list_for_each_entry(skc
, &spl_kmem_cache_list
, skc_list
) {
1763 spl_kmem_cache_reap_now(skc
);
1766 * Presume everything alloc'ed in reclaimable, this ensures
1767 * we are called again with nr_to_scan > 0 so can try and
1768 * reclaim. The exact number is not important either so
1769 * we forgo taking this already highly contented lock.
1771 unused
+= skc
->skc_obj_alloc
;
1773 up_read(&spl_kmem_cache_sem
);
1775 return (unused
* sysctl_vfs_cache_pressure
) / 100;
1779 * Call the registered reclaim function for a cache. Depending on how
1780 * many and which objects are released it may simply repopulate the
1781 * local magazine which will then need to age-out. Objects which cannot
1782 * fit in the magazine we will be released back to their slabs which will
1783 * also need to age out before being release. This is all just best
1784 * effort and we do not want to thrash creating and destroying slabs.
1787 spl_kmem_cache_reap_now(spl_kmem_cache_t
*skc
)
1791 ASSERT(skc
->skc_magic
== SKC_MAGIC
);
1792 ASSERT(!test_bit(KMC_BIT_DESTROY
, &skc
->skc_flags
));
1794 /* Prevent concurrent cache reaping when contended */
1795 if (test_and_set_bit(KMC_BIT_REAPING
, &skc
->skc_flags
)) {
1800 atomic_inc(&skc
->skc_ref
);
1802 if (skc
->skc_reclaim
)
1803 skc
->skc_reclaim(skc
->skc_private
);
1805 spl_slab_reclaim(skc
, skc
->skc_reap
, 0);
1806 clear_bit(KMC_BIT_REAPING
, &skc
->skc_flags
);
1807 atomic_dec(&skc
->skc_ref
);
1811 EXPORT_SYMBOL(spl_kmem_cache_reap_now
);
1814 * Reap all free slabs from all registered caches.
1819 spl_kmem_cache_generic_shrinker(KMC_REAP_CHUNK
, GFP_KERNEL
);
1821 EXPORT_SYMBOL(spl_kmem_reap
);
1823 #if defined(DEBUG_KMEM) && defined(DEBUG_KMEM_TRACKING)
1825 spl_sprintf_addr(kmem_debug_t
*kd
, char *str
, int len
, int min
)
1827 int size
= ((len
- 1) < kd
->kd_size
) ? (len
- 1) : kd
->kd_size
;
1830 ASSERT(str
!= NULL
&& len
>= 17);
1831 memset(str
, 0, len
);
1833 /* Check for a fully printable string, and while we are at
1834 * it place the printable characters in the passed buffer. */
1835 for (i
= 0; i
< size
; i
++) {
1836 str
[i
] = ((char *)(kd
->kd_addr
))[i
];
1837 if (isprint(str
[i
])) {
1840 /* Minimum number of printable characters found
1841 * to make it worthwhile to print this as ascii. */
1851 sprintf(str
, "%02x%02x%02x%02x%02x%02x%02x%02x",
1852 *((uint8_t *)kd
->kd_addr
),
1853 *((uint8_t *)kd
->kd_addr
+ 2),
1854 *((uint8_t *)kd
->kd_addr
+ 4),
1855 *((uint8_t *)kd
->kd_addr
+ 6),
1856 *((uint8_t *)kd
->kd_addr
+ 8),
1857 *((uint8_t *)kd
->kd_addr
+ 10),
1858 *((uint8_t *)kd
->kd_addr
+ 12),
1859 *((uint8_t *)kd
->kd_addr
+ 14));
1866 spl_kmem_init_tracking(struct list_head
*list
, spinlock_t
*lock
, int size
)
1871 spin_lock_init(lock
);
1872 INIT_LIST_HEAD(list
);
1874 for (i
= 0; i
< size
; i
++)
1875 INIT_HLIST_HEAD(&kmem_table
[i
]);
1881 spl_kmem_fini_tracking(struct list_head
*list
, spinlock_t
*lock
)
1883 unsigned long flags
;
1888 spin_lock_irqsave(lock
, flags
);
1889 if (!list_empty(list
))
1890 printk(KERN_WARNING
"%-16s %-5s %-16s %s:%s\n", "address",
1891 "size", "data", "func", "line");
1893 list_for_each_entry(kd
, list
, kd_list
)
1894 printk(KERN_WARNING
"%p %-5d %-16s %s:%d\n", kd
->kd_addr
,
1895 (int)kd
->kd_size
, spl_sprintf_addr(kd
, str
, 17, 8),
1896 kd
->kd_func
, kd
->kd_line
);
1898 spin_unlock_irqrestore(lock
, flags
);
1901 #else /* DEBUG_KMEM && DEBUG_KMEM_TRACKING */
1902 #define spl_kmem_init_tracking(list, lock, size)
1903 #define spl_kmem_fini_tracking(list, lock)
1904 #endif /* DEBUG_KMEM && DEBUG_KMEM_TRACKING */
1907 spl_kmem_init_globals(void)
1911 /* For now all zones are includes, it may be wise to restrict
1912 * this to normal and highmem zones if we see problems. */
1913 for_each_zone(zone
) {
1915 if (!populated_zone(zone
))
1918 minfree
+= min_wmark_pages(zone
);
1919 desfree
+= low_wmark_pages(zone
);
1920 lotsfree
+= high_wmark_pages(zone
);
1923 /* Solaris default values */
1924 swapfs_minfree
= MAX(2*1024*1024 >> PAGE_SHIFT
, physmem
>> 3);
1925 swapfs_reserve
= MIN(4*1024*1024 >> PAGE_SHIFT
, physmem
>> 4);
1929 * Called at module init when it is safe to use spl_kallsyms_lookup_name()
1932 spl_kmem_init_kallsyms_lookup(void)
1934 #ifndef HAVE_GET_VMALLOC_INFO
1935 get_vmalloc_info_fn
= (get_vmalloc_info_t
)
1936 spl_kallsyms_lookup_name("get_vmalloc_info");
1937 if (!get_vmalloc_info_fn
) {
1938 printk(KERN_ERR
"Error: Unknown symbol get_vmalloc_info\n");
1941 #endif /* HAVE_GET_VMALLOC_INFO */
1943 #ifdef HAVE_PGDAT_HELPERS
1944 # ifndef HAVE_FIRST_ONLINE_PGDAT
1945 first_online_pgdat_fn
= (first_online_pgdat_t
)
1946 spl_kallsyms_lookup_name("first_online_pgdat");
1947 if (!first_online_pgdat_fn
) {
1948 printk(KERN_ERR
"Error: Unknown symbol first_online_pgdat\n");
1951 # endif /* HAVE_FIRST_ONLINE_PGDAT */
1953 # ifndef HAVE_NEXT_ONLINE_PGDAT
1954 next_online_pgdat_fn
= (next_online_pgdat_t
)
1955 spl_kallsyms_lookup_name("next_online_pgdat");
1956 if (!next_online_pgdat_fn
) {
1957 printk(KERN_ERR
"Error: Unknown symbol next_online_pgdat\n");
1960 # endif /* HAVE_NEXT_ONLINE_PGDAT */
1962 # ifndef HAVE_NEXT_ZONE
1963 next_zone_fn
= (next_zone_t
)
1964 spl_kallsyms_lookup_name("next_zone");
1965 if (!next_zone_fn
) {
1966 printk(KERN_ERR
"Error: Unknown symbol next_zone\n");
1969 # endif /* HAVE_NEXT_ZONE */
1971 #else /* HAVE_PGDAT_HELPERS */
1973 # ifndef HAVE_PGDAT_LIST
1974 pgdat_list_addr
= *(struct pglist_data
**)
1975 spl_kallsyms_lookup_name("pgdat_list");
1976 if (!pgdat_list_addr
) {
1977 printk(KERN_ERR
"Error: Unknown symbol pgdat_list\n");
1980 # endif /* HAVE_PGDAT_LIST */
1981 #endif /* HAVE_PGDAT_HELPERS */
1983 #if defined(NEED_GET_ZONE_COUNTS) && !defined(HAVE_GET_ZONE_COUNTS)
1984 get_zone_counts_fn
= (get_zone_counts_t
)
1985 spl_kallsyms_lookup_name("get_zone_counts");
1986 if (!get_zone_counts_fn
) {
1987 printk(KERN_ERR
"Error: Unknown symbol get_zone_counts\n");
1990 #endif /* NEED_GET_ZONE_COUNTS && !HAVE_GET_ZONE_COUNTS */
1993 * It is now safe to initialize the global tunings which rely on
1994 * the use of the for_each_zone() macro. This macro in turns
1995 * depends on the *_pgdat symbols which are now available.
1997 spl_kmem_init_globals();
2008 init_rwsem(&spl_kmem_cache_sem
);
2009 INIT_LIST_HEAD(&spl_kmem_cache_list
);
2011 #ifdef HAVE_SET_SHRINKER
2012 spl_kmem_cache_shrinker
= set_shrinker(KMC_DEFAULT_SEEKS
,
2013 spl_kmem_cache_generic_shrinker
);
2014 if (spl_kmem_cache_shrinker
== NULL
)
2015 RETURN(rc
= -ENOMEM
);
2017 register_shrinker(&spl_kmem_cache_shrinker
);
2021 kmem_alloc_used_set(0);
2022 vmem_alloc_used_set(0);
2024 spl_kmem_init_tracking(&kmem_list
, &kmem_lock
, KMEM_TABLE_SIZE
);
2025 spl_kmem_init_tracking(&vmem_list
, &vmem_lock
, VMEM_TABLE_SIZE
);
2034 /* Display all unreclaimed memory addresses, including the
2035 * allocation size and the first few bytes of what's located
2036 * at that address to aid in debugging. Performance is not
2037 * a serious concern here since it is module unload time. */
2038 if (kmem_alloc_used_read() != 0)
2039 CWARN("kmem leaked %ld/%ld bytes\n",
2040 kmem_alloc_used_read(), kmem_alloc_max
);
2043 if (vmem_alloc_used_read() != 0)
2044 CWARN("vmem leaked %ld/%ld bytes\n",
2045 vmem_alloc_used_read(), vmem_alloc_max
);
2047 spl_kmem_fini_tracking(&kmem_list
, &kmem_lock
);
2048 spl_kmem_fini_tracking(&vmem_list
, &vmem_lock
);
2049 #endif /* DEBUG_KMEM */
2052 #ifdef HAVE_SET_SHRINKER
2053 remove_shrinker(spl_kmem_cache_shrinker
);
2055 unregister_shrinker(&spl_kmem_cache_shrinker
);