9 #undef DEBUG_KMEM_UNIMPLEMENTED
11 #include <linux/module.h>
12 #include <linux/slab.h>
14 #include <linux/spinlock.h>
16 * Memory allocation interfaces
18 #define KM_SLEEP GFP_KERNEL
19 #define KM_NOSLEEP GFP_ATOMIC
20 #undef KM_PANIC /* No linux analog */
21 #define KM_PUSHPAGE (GFP_KERNEL | GFP_HIGH)
22 #define KM_VMFLAGS GFP_LEVEL_MASK
23 #define KM_FLAGS __GFP_BITS_MASK
26 /* Shim layer memory accounting */
27 extern atomic_t kmem_alloc_used
;
28 extern unsigned int kmem_alloc_max
;
32 #define __kmem_alloc(size, flags, allocator) \
35 /* Marked unlikely because we should never be doing this */ \
36 if (unlikely((size) > (PAGE_SIZE * 2))) \
37 printk("Warning: kmem_alloc(%d, 0x%x) large alloc at %s:%d " \
38 "(%d/%d)\n", (int)(size), (int)(flags), \
40 atomic_read(&kmem_alloc_used), kmem_alloc_max); \
42 _ptr_ = (void *)allocator((size), (flags)); \
43 if (_ptr_ == NULL) { \
44 printk("Warning: kmem_alloc(%d, 0x%x) failed at %s:%d " \
45 "(%d/%d)\n", (int)(size), (int)(flags), \
47 atomic_read(&kmem_alloc_used), kmem_alloc_max); \
48 atomic_add((size), &kmem_alloc_used); \
49 if (unlikely(atomic_read(&kmem_alloc_used) > kmem_alloc_max)) \
50 kmem_alloc_max = atomic_read(&kmem_alloc_used); \
56 #define kmem_alloc(size, flags) __kmem_alloc(size, flags, kmalloc)
57 #define kmem_zalloc(size, flags) __kmem_alloc(size, flags, kzalloc)
59 #define kmem_free(ptr, size) \
62 atomic_sub((size), &kmem_alloc_used); \
63 memset(ptr, 0x5a, (size)); /* Poison */ \
65 (ptr) = (void *)0xdeadbeef; \
71 #define kmem_alloc(size, flags) kmalloc(size, flags)
72 #define kmem_zalloc(size, flags) kzalloc(size, flags)
73 #define kmem_free(ptr, size) kfree(ptr)
75 #endif /* DEBUG_KMEM */
78 #ifdef DEBUG_KMEM_UNIMPLEMENTED
79 static __inline__
void *
80 kmem_alloc_tryhard(size_t size
, size_t *alloc_size
, int kmflags
)
82 #error "kmem_alloc_tryhard() not implemented"
84 #endif /* DEBUG_KMEM_UNIMPLEMENTED */
87 * Slab allocation interfaces
89 #undef KMC_NOTOUCH /* No linux analog */
90 #define KMC_NODEBUG 0x00000000 /* Default beahvior */
91 #define KMC_NOMAGAZINE /* No linux analog */
92 #define KMC_NOHASH /* No linux analog */
93 #define KMC_QCACHE /* No linux analog */
95 #define KMC_REAP_CHUNK 256
96 #define KMC_DEFAULT_SEEKS DEFAULT_SEEKS
98 /* Defined by linux slab.h
99 * typedef struct kmem_cache_s kmem_cache_t;
103 * extern int kmem_ready;
104 * extern pgcnt_t kmem_reapahead;
107 #ifdef DEBUG_KMEM_UNIMPLEMENTED
108 static __inline__
void kmem_init(void) {
109 #error "kmem_init() not implemented"
112 static __inline__
void kmem_thread_init(void) {
113 #error "kmem_thread_init() not implemented"
116 static __inline__
void kmem_mp_init(void) {
117 #error "kmem_mp_init() not implemented"
120 static __inline__
void kmem_reap_idspace(void) {
121 #error "kmem_reap_idspace() not implemented"
124 static __inline__
size_t kmem_avail(void) {
125 #error "kmem_avail() not implemented"
128 static __inline__
size_t kmem_maxavail(void) {
129 #error "kmem_maxavail() not implemented"
132 static __inline__
uint64_t kmem_cache_stat(kmem_cache_t
*cache
) {
133 #error "kmem_cache_stat() not implemented"
135 #endif /* DEBUG_KMEM_UNIMPLEMENTED */
137 /* XXX - Used by arc.c to adjust its memory footprint. We may want
138 * to use this hook in the future to adjust behavior based on
139 * debug levels. For now it's safe to always return 0.
141 static __inline__
int
147 typedef int (*kmem_constructor_t
)(void *, void *, int);
148 typedef void (*kmem_destructor_t
)(void *, void *);
149 typedef void (*kmem_reclaim_t
)(void *);
151 extern kmem_cache_t
*
152 __kmem_cache_create(char *name
, size_t size
, size_t align
,
153 kmem_constructor_t constructor
,
154 kmem_destructor_t destructor
,
155 kmem_reclaim_t reclaim
,
156 void *priv
, void *vmp
, int flags
);
159 extern __kmem_cache_destroy(kmem_cache_t
*cache
);
162 extern __kmem_reap(void);
164 #define kmem_cache_create(name,size,align,ctor,dtor,rclm,priv,vmp,flags) \
165 __kmem_cache_create(name,size,align,ctor,dtor,rclm,priv,vmp,flags)
166 #define kmem_cache_destroy(cache) __kmem_cache_destroy(cache)
167 #define kmem_cache_alloc(cache, flags) kmem_cache_alloc(cache, flags)
168 #define kmem_cache_free(cache, ptr) kmem_cache_free(cache, ptr)
169 #define kmem_cache_reap_now(cache) kmem_cache_shrink(cache)
170 #define kmem_reap() __kmem_reap()
176 #endif /* _SPL_KMEM_H */