diff options
author | behlendo <behlendo@7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c> | 2008-03-14 20:56:26 +0000 |
---|---|---|
committer | behlendo <behlendo@7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c> | 2008-03-14 20:56:26 +0000 |
commit | c19c06f3b05a220cb638050c0e06578a09ad64ad (patch) | |
tree | 1e5b3f9fc76225a6b87672239de8f93fe9639d6b /modules | |
parent | 79b31f3601af530f64b3f2ae87233b3fa5271df1 (diff) |
Fix kmem memory accounting
Adjust kmem slab interface to make a copy of the slab name before
passing it on to the linux slab (we free it latter too)
git-svn-id: https://outreach.scidac.gov/svn/spl/trunk@47 7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c
Diffstat (limited to 'modules')
-rw-r--r-- | modules/spl/spl-generic.c | 17 | ||||
-rw-r--r-- | modules/spl/spl-kmem.c | 26 | ||||
-rw-r--r-- | modules/splat/splat-kmem.c | 12 |
3 files changed, 50 insertions, 5 deletions
diff --git a/modules/spl/spl-generic.c b/modules/spl/spl-generic.c index cae4223f3..9f48dd1a5 100644 --- a/modules/spl/spl-generic.c +++ b/modules/spl/spl-generic.c @@ -1,6 +1,7 @@ #include <sys/sysmacros.h> #include <sys/vmsystm.h> #include <sys/vnode.h> +#include <sys/kmem.h> #include "config.h" /* @@ -66,12 +67,28 @@ static int __init spl_init(void) strcpy(hw_serial, "007f0100"); /* loopback */ printk(KERN_INFO "spl: Loaded Solaris Porting Layer v%s\n", VERSION); +#ifdef DEBUG_KMEM + atomic64_set(&kmem_alloc_used, 0); + atomic64_set(&vmem_alloc_used, 0); +#endif + return 0; } static void spl_fini(void) { vn_fini(); + +#ifdef DEBUG_KMEM + if (atomic64_read(&kmem_alloc_used) != 0) + printk("Warning: kmem leaked %ld/%ld bytes\n", + atomic_read(&kmem_alloc_used), kmem_alloc_max); + + if (atomic64_read(&vmem_alloc_used) != 0) + printk("Warning: vmem leaked %ld/%ld bytes\n", + atomic_read(&vmem_alloc_used), vmem_alloc_max); +#endif + return; } diff --git a/modules/spl/spl-kmem.c b/modules/spl/spl-kmem.c index d3cb2c93a..c8808105b 100644 --- a/modules/spl/spl-kmem.c +++ b/modules/spl/spl-kmem.c @@ -5,16 +5,23 @@ */ #ifdef DEBUG_KMEM /* Shim layer memory accounting */ -atomic_t kmem_alloc_used; -unsigned int kmem_alloc_max; -atomic_t vmem_alloc_used; -unsigned int vmem_alloc_max; +atomic64_t kmem_alloc_used; +unsigned long kmem_alloc_max = 0; +atomic64_t vmem_alloc_used; +unsigned long vmem_alloc_max = 0; +int kmem_warning_flag = 1; EXPORT_SYMBOL(kmem_alloc_used); EXPORT_SYMBOL(kmem_alloc_max); EXPORT_SYMBOL(vmem_alloc_used); EXPORT_SYMBOL(vmem_alloc_max); +EXPORT_SYMBOL(kmem_warning_flag); + +int kmem_set_warning(int flag) { return (kmem_warning_flag = !!flag); } +#else +int kmem_set_warning(int flag) { return 0; } #endif +EXPORT_SYMBOL(kmem_set_warning); /* * Slab allocation interfaces @@ -187,11 +194,17 @@ __kmem_cache_create(char *name, size_t size, size_t align, kmem_cache_t *cache; kmem_cache_cb_t *kcc; int shrinker_flag = 0; + char *cache_name; /* FIXME: - Option currently unsupported by shim layer */ BUG_ON(vmp); - cache = kmem_cache_create(name, size, align, flags, + cache_name = kzalloc(strlen(name) + 1, GFP_KERNEL); + if (cache_name == NULL) + return NULL; + + strcpy(cache_name, name); + cache = kmem_cache_create(cache_name, size, align, flags, kmem_cache_generic_constructor, kmem_cache_generic_destructor); if (cache == NULL) @@ -230,6 +243,7 @@ void __kmem_cache_destroy(kmem_cache_t *cache) { kmem_cache_cb_t *kcc; + char *name; spin_lock(&kmem_cache_cb_lock); kcc = kmem_cache_find_cache_cb(cache); @@ -237,8 +251,10 @@ __kmem_cache_destroy(kmem_cache_t *cache) if (kcc == NULL) return; + name = (char *)kmem_cache_name(cache); kmem_cache_destroy(cache); kmem_cache_remove_cache_cb(kcc); + kfree(name); /* Unregister generic shrinker on removal of all caches */ spin_lock(&kmem_cache_cb_lock); diff --git a/modules/splat/splat-kmem.c b/modules/splat/splat-kmem.c index 7115ca42c..f9f6964de 100644 --- a/modules/splat/splat-kmem.c +++ b/modules/splat/splat-kmem.c @@ -35,6 +35,10 @@ splat_kmem_test1(struct file *file, void *arg) int size = PAGE_SIZE; int i, count, rc = 0; + /* We are intentionally going to push kmem_alloc to its max + * allocation size, so suppress the console warnings for now */ + kmem_set_warning(0); + while ((!rc) && (size <= (PAGE_SIZE * 32))) { count = 0; @@ -57,6 +61,8 @@ splat_kmem_test1(struct file *file, void *arg) size *= 2; } + kmem_set_warning(1); + return rc; } @@ -67,6 +73,10 @@ splat_kmem_test2(struct file *file, void *arg) int size = PAGE_SIZE; int i, j, count, rc = 0; + /* We are intentionally going to push kmem_alloc to its max + * allocation size, so suppress the console warnings for now */ + kmem_set_warning(0); + while ((!rc) && (size <= (PAGE_SIZE * 32))) { count = 0; @@ -101,6 +111,8 @@ splat_kmem_test2(struct file *file, void *arg) size *= 2; } + kmem_set_warning(1); + return rc; } |