]>
git.proxmox.com Git - mirror_spl.git/blob - include/linux-kmem.h
1 #ifndef _SYS_LINUX_KMEM_H
2 #define _SYS_LINUX_KMEM_H
9 #undef DEBUG_KMEM_UNIMPLEMENTED
11 #include <linux/slab.h>
13 #include <linux/spinlock.h>
15 * Memory allocation interfaces
17 #define KM_SLEEP GFP_KERNEL
18 #define KM_NOSLEEP GFP_ATOMIC
19 #undef KM_PANIC /* No linux analog */
20 #define KM_PUSHPAGE (GFP_KERNEL | GFP_HIGH)
21 #define KM_VMFLAGS GFP_LEVEL_MASK
22 #define KM_FLAGS __GFP_BITS_MASK
25 /* Shim layer memory accounting */
26 extern atomic_t kmem_alloc_used
;
27 extern unsigned int kmem_alloc_max
;
31 #define __kmem_alloc(size, flags, allocator) \
34 /* Marked unlikely because we should never be doing this */ \
35 if (unlikely((size) > (PAGE_SIZE * 2))) \
36 printk("Warning: kmem_alloc(%d, 0x%x) large alloc at %s:%d " \
37 "(%d/%d)\n", (int)(size), (int)(flags), \
39 atomic_read(&kmem_alloc_used), kmem_alloc_max); \
41 _ptr_ = (void *)allocator((size), (flags)); \
42 if (_ptr_ == NULL) { \
43 printk("Warning: kmem_alloc(%d, 0x%x) failed at %s:%d " \
44 "(%d/%d)\n", (int)(size), (int)(flags), \
46 atomic_read(&kmem_alloc_used), kmem_alloc_max); \
47 atomic_add((size), &kmem_alloc_used); \
48 if (unlikely(atomic_read(&kmem_alloc_used) > kmem_alloc_max)) \
49 kmem_alloc_max = atomic_read(&kmem_alloc_used); \
55 #define kmem_alloc(size, flags) __kmem_alloc(size, flags, kmalloc)
56 #define kmem_zalloc(size, flags) __kmem_alloc(size, flags, kzalloc)
58 #define kmem_free(ptr, size) \
61 atomic_sub((size), &kmem_alloc_used); \
62 memset(ptr, 0x5a, (size)); /* Poison */ \
64 (ptr) = (void *)0xdeadbeef; \
70 #define kmem_alloc(size, flags) kmalloc(size, flags)
71 #define kmem_zalloc(size, flags) kzalloc(size, flags)
72 #define kmem_free(ptr, size) kfree(ptr)
74 #endif /* DEBUG_KMEM */
77 #ifdef DEBUG_KMEM_UNIMPLEMENTED
78 static __inline__
void *
79 kmem_alloc_tryhard(size_t size
, size_t *alloc_size
, int kmflags
)
81 #error "kmem_alloc_tryhard() not implemented"
83 #endif /* DEBUG_KMEM_UNIMPLEMENTED */
86 * Slab allocation interfaces
88 #undef KMC_NOTOUCH /* No linux analog */
89 #define KMC_NODEBUG 0x00000000 /* Default beahvior */
90 #define KMC_NOMAGAZINE /* No linux analog */
91 #define KMC_NOHASH /* No linux analog */
92 #define KMC_QCACHE /* No linux analog */
94 #define KMC_REAP_CHUNK 256
95 #define KMC_DEFAULT_SEEKS DEFAULT_SEEKS
97 /* Defined by linux slab.h
98 * typedef struct kmem_cache_s kmem_cache_t;
102 * extern int kmem_ready;
103 * extern pgcnt_t kmem_reapahead;
106 #ifdef DEBUG_KMEM_UNIMPLEMENTED
107 static __inline__
void kmem_init(void) {
108 #error "kmem_init() not implemented"
111 static __inline__
void kmem_thread_init(void) {
112 #error "kmem_thread_init() not implemented"
115 static __inline__
void kmem_mp_init(void) {
116 #error "kmem_mp_init() not implemented"
119 static __inline__
void kmem_reap_idspace(void) {
120 #error "kmem_reap_idspace() not implemented"
123 static __inline__
size_t kmem_avail(void) {
124 #error "kmem_avail() not implemented"
127 static __inline__
size_t kmem_maxavail(void) {
128 #error "kmem_maxavail() not implemented"
131 static __inline__
uint64_t kmem_cache_stat(kmem_cache_t
*cache
) {
132 #error "kmem_cache_stat() not implemented"
134 #endif /* DEBUG_KMEM_UNIMPLEMENTED */
136 /* XXX - Used by arc.c to adjust its memory footprint. We may want
137 * to use this hook in the future to adjust behavior based on
138 * debug levels. For now it's safe to always return 0.
140 static __inline__
int
146 typedef int (*kmem_constructor_t
)(void *, void *, int);
147 typedef void (*kmem_destructor_t
)(void *, void *);
148 typedef void (*kmem_reclaim_t
)(void *);
151 __kmem_cache_create(char *name
, size_t size
, size_t align
,
152 int (*constructor
)(void *, void *, int),
153 void (*destructor
)(void *, void *),
154 void (*reclaim
)(void *),
155 void *priv
, void *vmp
, int flags
);
158 __kmem_cache_destroy(kmem_cache_t
*cache
);
160 #define kmem_cache_create(name,size,align,ctor,dtor,rclm,priv,vmp,flags) \
161 __kmem_cache_create(name,size,align,ctor,dtor,rclm,priv,vmp,flags)
162 #define kmem_cache_destroy(cache) __kmem_cache_destroy(cache)
163 #define kmem_cache_alloc(cache, flags) kmem_cache_alloc(cache, flags)
164 #define kmem_cache_free(cache, ptr) kmem_cache_free(cache, ptr)
165 #define kmem_cache_reap_now(cache) kmem_cache_shrink(cache)
166 #define kmem_reap() __kmem_reap()
173 #endif /* _SYS_LINUX_KMEM_H */