diff options
author | behlendo <behlendo@7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c> | 2008-03-14 19:04:41 +0000 |
---|---|---|
committer | behlendo <behlendo@7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c> | 2008-03-14 19:04:41 +0000 |
commit | 79b31f3601af530f64b3f2ae87233b3fa5271df1 (patch) | |
tree | afbbd0dda73ebc2a2b5d7b1c04c6504f53f2d863 /include/sys/kmem.h | |
parent | af828292e585781b2e186f47074a3e1a3baa5094 (diff) |
Fix KMEM_DEBUG support (enable by default)
Add vmem_alloc/vmem_free support (and test case)
Add missing time functions
git-svn-id: https://outreach.scidac.gov/svn/spl/trunk@46 7e1ea52c-4ff2-0310-8f11-9dd32ca42a1c
Diffstat (limited to 'include/sys/kmem.h')
-rw-r--r-- | include/sys/kmem.h | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/include/sys/kmem.h b/include/sys/kmem.h index c5e559cbd..2560b380a 100644 --- a/include/sys/kmem.h +++ b/include/sys/kmem.h @@ -5,11 +5,12 @@ extern "C" { #endif -#undef DEBUG_KMEM +#define DEBUG_KMEM #undef DEBUG_KMEM_UNIMPLEMENTED #include <linux/module.h> #include <linux/slab.h> +#include <linux/vmalloc.h> #include <linux/mm.h> #include <linux/spinlock.h> /* @@ -23,12 +24,11 @@ extern "C" { #define KM_FLAGS __GFP_BITS_MASK #ifdef DEBUG_KMEM -/* Shim layer memory accounting */ extern atomic_t kmem_alloc_used; extern unsigned int kmem_alloc_max; -#endif +extern atomic_t vmem_alloc_used; +extern unsigned int vmem_alloc_max; -#ifdef DEBUG_KMEM #define __kmem_alloc(size, flags, allocator) \ ({ void *_ptr_; \ \ @@ -58,13 +58,40 @@ extern unsigned int kmem_alloc_max; #define kmem_free(ptr, size) \ ({ \ - BUG_ON(!ptr || size < 0); \ + BUG_ON(!(ptr) || (size) < 0); \ atomic_sub((size), &kmem_alloc_used); \ memset(ptr, 0x5a, (size)); /* Poison */ \ kfree(ptr); \ - (ptr) = (void *)0xdeadbeef; \ }) +#define __vmem_alloc(size, flags) \ +({ void *_ptr_; \ + \ + BUG_ON(flags != KM_SLEEP); \ + \ + _ptr_ = (void *)vmalloc((size)); \ + if (_ptr_ == NULL) { \ + printk("Warning: vmem_alloc(%d, 0x%x) failed at %s:%d " \ + "(%d/%d)\n", (int)(size), (int)(flags), \ + __FILE__, __LINE__, \ + atomic_read(&vmem_alloc_used), vmem_alloc_max); \ + atomic_add((size), &vmem_alloc_used); \ + if (unlikely(atomic_read(&vmem_alloc_used) > vmem_alloc_max)) \ + vmem_alloc_max = atomic_read(&vmem_alloc_used); \ + } \ + \ + _ptr_; \ +}) + +#define vmem_alloc(size, flags) __vmem_alloc(size, flags) + +#define vmem_free(ptr, size) \ +({ \ + BUG_ON(!(ptr) || (size) < 0); \ + atomic_sub((size), &vmem_alloc_used); \ + memset(ptr, 0x5a, (size)); /* Poison */ \ + vfree(ptr); \ +}) #else @@ -72,10 +99,17 @@ extern unsigned int kmem_alloc_max; #define kmem_zalloc(size, flags) kzalloc(size, flags) #define kmem_free(ptr, size) \ ({ \ - BUG_ON(!ptr || size < 0); \ + BUG_ON(!(ptr) || (size) < 0); \ kfree(ptr); \ }) +#define vmem_alloc(size, flags) vmalloc(size) +#define vmem_free(ptr, size) \ +({ \ + BUG_ON(!(ptr) || (size) < 0); \ + vfree(ptr); \ +}) + #endif /* DEBUG_KMEM */ |