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
This commit is contained in:
behlendo
2008-03-14 20:56:26 +00:00
parent 79b31f3601
commit c19c06f3b0
4 changed files with 74 additions and 24 deletions
+17
View File
@@ -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;
}
+21 -5
View File
@@ -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);
+12
View File
@@ -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;
}