mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-26 03:09:34 +03:00
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:
parent
79b31f3601
commit
c19c06f3b0
@ -24,30 +24,32 @@ extern "C" {
|
|||||||
#define KM_FLAGS __GFP_BITS_MASK
|
#define KM_FLAGS __GFP_BITS_MASK
|
||||||
|
|
||||||
#ifdef DEBUG_KMEM
|
#ifdef DEBUG_KMEM
|
||||||
extern atomic_t kmem_alloc_used;
|
extern atomic64_t kmem_alloc_used;
|
||||||
extern unsigned int kmem_alloc_max;
|
extern unsigned long kmem_alloc_max;
|
||||||
extern atomic_t vmem_alloc_used;
|
extern atomic64_t vmem_alloc_used;
|
||||||
extern unsigned int vmem_alloc_max;
|
extern unsigned long vmem_alloc_max;
|
||||||
|
extern int kmem_warning_flag;
|
||||||
|
|
||||||
#define __kmem_alloc(size, flags, allocator) \
|
#define __kmem_alloc(size, flags, allocator) \
|
||||||
({ void *_ptr_; \
|
({ void *_ptr_; \
|
||||||
\
|
\
|
||||||
/* Marked unlikely because we should never be doing this */ \
|
/* Marked unlikely because we should never be doing this */ \
|
||||||
if (unlikely((size) > (PAGE_SIZE * 2))) \
|
if (unlikely((size) > (PAGE_SIZE * 2)) && kmem_warning_flag) \
|
||||||
printk("Warning: kmem_alloc(%d, 0x%x) large alloc at %s:%d " \
|
printk("Warning: kmem_alloc(%d, 0x%x) large alloc at %s:%d " \
|
||||||
"(%d/%d)\n", (int)(size), (int)(flags), \
|
"(%ld/%ld)\n", (int)(size), (int)(flags), \
|
||||||
__FILE__, __LINE__, \
|
__FILE__, __LINE__, \
|
||||||
atomic_read(&kmem_alloc_used), kmem_alloc_max); \
|
atomic64_read(&kmem_alloc_used), kmem_alloc_max); \
|
||||||
\
|
\
|
||||||
_ptr_ = (void *)allocator((size), (flags)); \
|
_ptr_ = (void *)allocator((size), (flags)); \
|
||||||
if (_ptr_ == NULL) { \
|
if (_ptr_ == NULL) { \
|
||||||
printk("Warning: kmem_alloc(%d, 0x%x) failed at %s:%d " \
|
printk("Warning: kmem_alloc(%d, 0x%x) failed at %s:%d " \
|
||||||
"(%d/%d)\n", (int)(size), (int)(flags), \
|
"(%ld/%ld)\n", (int)(size), (int)(flags), \
|
||||||
__FILE__, __LINE__, \
|
__FILE__, __LINE__, \
|
||||||
atomic_read(&kmem_alloc_used), kmem_alloc_max); \
|
atomic64_read(&kmem_alloc_used), kmem_alloc_max); \
|
||||||
atomic_add((size), &kmem_alloc_used); \
|
} else { \
|
||||||
if (unlikely(atomic_read(&kmem_alloc_used) > kmem_alloc_max)) \
|
atomic64_add((size), &kmem_alloc_used); \
|
||||||
kmem_alloc_max = atomic_read(&kmem_alloc_used); \
|
if (unlikely(atomic64_read(&kmem_alloc_used)>kmem_alloc_max)) \
|
||||||
|
kmem_alloc_max = atomic64_read(&kmem_alloc_used); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
_ptr_; \
|
_ptr_; \
|
||||||
@ -59,7 +61,7 @@ extern unsigned int vmem_alloc_max;
|
|||||||
#define kmem_free(ptr, size) \
|
#define kmem_free(ptr, size) \
|
||||||
({ \
|
({ \
|
||||||
BUG_ON(!(ptr) || (size) < 0); \
|
BUG_ON(!(ptr) || (size) < 0); \
|
||||||
atomic_sub((size), &kmem_alloc_used); \
|
atomic64_sub((size), &kmem_alloc_used); \
|
||||||
memset(ptr, 0x5a, (size)); /* Poison */ \
|
memset(ptr, 0x5a, (size)); /* Poison */ \
|
||||||
kfree(ptr); \
|
kfree(ptr); \
|
||||||
})
|
})
|
||||||
@ -72,12 +74,13 @@ extern unsigned int vmem_alloc_max;
|
|||||||
_ptr_ = (void *)vmalloc((size)); \
|
_ptr_ = (void *)vmalloc((size)); \
|
||||||
if (_ptr_ == NULL) { \
|
if (_ptr_ == NULL) { \
|
||||||
printk("Warning: vmem_alloc(%d, 0x%x) failed at %s:%d " \
|
printk("Warning: vmem_alloc(%d, 0x%x) failed at %s:%d " \
|
||||||
"(%d/%d)\n", (int)(size), (int)(flags), \
|
"(%ld/%ld)\n", (int)(size), (int)(flags), \
|
||||||
__FILE__, __LINE__, \
|
__FILE__, __LINE__, \
|
||||||
atomic_read(&vmem_alloc_used), vmem_alloc_max); \
|
atomic64_read(&vmem_alloc_used), vmem_alloc_max); \
|
||||||
atomic_add((size), &vmem_alloc_used); \
|
} else { \
|
||||||
if (unlikely(atomic_read(&vmem_alloc_used) > vmem_alloc_max)) \
|
atomic64_add((size), &vmem_alloc_used); \
|
||||||
vmem_alloc_max = atomic_read(&vmem_alloc_used); \
|
if (unlikely(atomic64_read(&vmem_alloc_used)>vmem_alloc_max)) \
|
||||||
|
vmem_alloc_max = atomic64_read(&vmem_alloc_used); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
_ptr_; \
|
_ptr_; \
|
||||||
@ -88,7 +91,7 @@ extern unsigned int vmem_alloc_max;
|
|||||||
#define vmem_free(ptr, size) \
|
#define vmem_free(ptr, size) \
|
||||||
({ \
|
({ \
|
||||||
BUG_ON(!(ptr) || (size) < 0); \
|
BUG_ON(!(ptr) || (size) < 0); \
|
||||||
atomic_sub((size), &vmem_alloc_used); \
|
atomic64_sub((size), &vmem_alloc_used); \
|
||||||
memset(ptr, 0x5a, (size)); /* Poison */ \
|
memset(ptr, 0x5a, (size)); /* Poison */ \
|
||||||
vfree(ptr); \
|
vfree(ptr); \
|
||||||
})
|
})
|
||||||
@ -186,6 +189,8 @@ typedef int (*kmem_constructor_t)(void *, void *, int);
|
|||||||
typedef void (*kmem_destructor_t)(void *, void *);
|
typedef void (*kmem_destructor_t)(void *, void *);
|
||||||
typedef void (*kmem_reclaim_t)(void *);
|
typedef void (*kmem_reclaim_t)(void *);
|
||||||
|
|
||||||
|
extern int kmem_set_warning(int flag);
|
||||||
|
|
||||||
extern kmem_cache_t *
|
extern kmem_cache_t *
|
||||||
__kmem_cache_create(char *name, size_t size, size_t align,
|
__kmem_cache_create(char *name, size_t size, size_t align,
|
||||||
kmem_constructor_t constructor,
|
kmem_constructor_t constructor,
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include <sys/sysmacros.h>
|
#include <sys/sysmacros.h>
|
||||||
#include <sys/vmsystm.h>
|
#include <sys/vmsystm.h>
|
||||||
#include <sys/vnode.h>
|
#include <sys/vnode.h>
|
||||||
|
#include <sys/kmem.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -66,12 +67,28 @@ static int __init spl_init(void)
|
|||||||
strcpy(hw_serial, "007f0100"); /* loopback */
|
strcpy(hw_serial, "007f0100"); /* loopback */
|
||||||
printk(KERN_INFO "spl: Loaded Solaris Porting Layer v%s\n", VERSION);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void spl_fini(void)
|
static void spl_fini(void)
|
||||||
{
|
{
|
||||||
vn_fini();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,16 +5,23 @@
|
|||||||
*/
|
*/
|
||||||
#ifdef DEBUG_KMEM
|
#ifdef DEBUG_KMEM
|
||||||
/* Shim layer memory accounting */
|
/* Shim layer memory accounting */
|
||||||
atomic_t kmem_alloc_used;
|
atomic64_t kmem_alloc_used;
|
||||||
unsigned int kmem_alloc_max;
|
unsigned long kmem_alloc_max = 0;
|
||||||
atomic_t vmem_alloc_used;
|
atomic64_t vmem_alloc_used;
|
||||||
unsigned int vmem_alloc_max;
|
unsigned long vmem_alloc_max = 0;
|
||||||
|
int kmem_warning_flag = 1;
|
||||||
|
|
||||||
EXPORT_SYMBOL(kmem_alloc_used);
|
EXPORT_SYMBOL(kmem_alloc_used);
|
||||||
EXPORT_SYMBOL(kmem_alloc_max);
|
EXPORT_SYMBOL(kmem_alloc_max);
|
||||||
EXPORT_SYMBOL(vmem_alloc_used);
|
EXPORT_SYMBOL(vmem_alloc_used);
|
||||||
EXPORT_SYMBOL(vmem_alloc_max);
|
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
|
#endif
|
||||||
|
EXPORT_SYMBOL(kmem_set_warning);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Slab allocation interfaces
|
* Slab allocation interfaces
|
||||||
@ -187,11 +194,17 @@ __kmem_cache_create(char *name, size_t size, size_t align,
|
|||||||
kmem_cache_t *cache;
|
kmem_cache_t *cache;
|
||||||
kmem_cache_cb_t *kcc;
|
kmem_cache_cb_t *kcc;
|
||||||
int shrinker_flag = 0;
|
int shrinker_flag = 0;
|
||||||
|
char *cache_name;
|
||||||
|
|
||||||
/* FIXME: - Option currently unsupported by shim layer */
|
/* FIXME: - Option currently unsupported by shim layer */
|
||||||
BUG_ON(vmp);
|
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_constructor,
|
||||||
kmem_cache_generic_destructor);
|
kmem_cache_generic_destructor);
|
||||||
if (cache == NULL)
|
if (cache == NULL)
|
||||||
@ -230,6 +243,7 @@ void
|
|||||||
__kmem_cache_destroy(kmem_cache_t *cache)
|
__kmem_cache_destroy(kmem_cache_t *cache)
|
||||||
{
|
{
|
||||||
kmem_cache_cb_t *kcc;
|
kmem_cache_cb_t *kcc;
|
||||||
|
char *name;
|
||||||
|
|
||||||
spin_lock(&kmem_cache_cb_lock);
|
spin_lock(&kmem_cache_cb_lock);
|
||||||
kcc = kmem_cache_find_cache_cb(cache);
|
kcc = kmem_cache_find_cache_cb(cache);
|
||||||
@ -237,8 +251,10 @@ __kmem_cache_destroy(kmem_cache_t *cache)
|
|||||||
if (kcc == NULL)
|
if (kcc == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
name = (char *)kmem_cache_name(cache);
|
||||||
kmem_cache_destroy(cache);
|
kmem_cache_destroy(cache);
|
||||||
kmem_cache_remove_cache_cb(kcc);
|
kmem_cache_remove_cache_cb(kcc);
|
||||||
|
kfree(name);
|
||||||
|
|
||||||
/* Unregister generic shrinker on removal of all caches */
|
/* Unregister generic shrinker on removal of all caches */
|
||||||
spin_lock(&kmem_cache_cb_lock);
|
spin_lock(&kmem_cache_cb_lock);
|
||||||
|
@ -35,6 +35,10 @@ splat_kmem_test1(struct file *file, void *arg)
|
|||||||
int size = PAGE_SIZE;
|
int size = PAGE_SIZE;
|
||||||
int i, count, rc = 0;
|
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))) {
|
while ((!rc) && (size <= (PAGE_SIZE * 32))) {
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
@ -57,6 +61,8 @@ splat_kmem_test1(struct file *file, void *arg)
|
|||||||
size *= 2;
|
size *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kmem_set_warning(1);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,6 +73,10 @@ splat_kmem_test2(struct file *file, void *arg)
|
|||||||
int size = PAGE_SIZE;
|
int size = PAGE_SIZE;
|
||||||
int i, j, count, rc = 0;
|
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))) {
|
while ((!rc) && (size <= (PAGE_SIZE * 32))) {
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
@ -101,6 +111,8 @@ splat_kmem_test2(struct file *file, void *arg)
|
|||||||
size *= 2;
|
size *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
kmem_set_warning(1);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user