8 #include "sys/list_head.h"
19 #define KMEM_CREATE(objtype) \
20 kmem_cache_create(#objtype, sizeof(objtype), alignof(objtype), GFP_KERNEL, NULL, NULL)
23 #define KMEM_CREATE_CTOR(objtype, ctor) \
24 kmem_cache_create(#objtype, sizeof(objtype), alignof(objtype), GFP_KERNEL, (kmem_fun_t)(ctor), NULL)
94 #ifdef ENABLE_CACHE_TRACE
103 void *pr_kmem_cache_alloc(
const char *file,
const char *fun,
int line,
kmem_cache_t *cachep,
gfp_t flags);
110 void pr_kmem_cache_free(
const char *file,
const char *fun,
int line,
void *addr);
113 #define kmem_cache_alloc(...) pr_kmem_cache_alloc(__FILE__, __func__, __LINE__, __VA_ARGS__)
116 #define kmem_cache_free(...) pr_kmem_cache_free(__FILE__, __func__, __LINE__, __VA_ARGS__)
132 #ifdef ENABLE_ALLOC_TRACE
140 void *pr_kmalloc(
const char *file,
const char *fun,
int line,
unsigned int size);
147 void pr_kfree(
const char *file,
const char *fun,
int line,
void *addr);
150 #define kmalloc(...) pr_kmalloc(__FILE__, __func__, __LINE__, __VA_ARGS__)
153 #define kfree(...) pr_kfree(__FILE__, __func__, __LINE__, __VA_ARGS__)
160 void *
kmalloc(
unsigned int size);
164 void kfree(
void *ptr);
List of Get Free Pages (GFP) Flags.
unsigned int gfp_t
Type used for GFP_FLAGS.
Definition: gfp.h:9
void kmem_cache_free(void *addr)
Frees an object previously allocated from a kmem_cache_t.
Definition: slab.c:539
void kfree(void *ptr)
Frees memory allocated by kmalloc or kmem_cache_alloc.
Definition: slab.c:616
void * kmem_cache_alloc(kmem_cache_t *cachep, gfp_t flags)
Allocates an object from the specified kmem_cache_t.
Definition: slab.c:474
void * kmalloc(unsigned int size)
Allocates memory of the specified size using kmalloc.
Definition: slab.c:588
struct kmem_cache_t kmem_cache_t
Stores the information of a cache.
int kmem_cache_init(void)
Initializes the kernel memory cache system.
Definition: slab.c:370
void(* kmem_fun_t)(void *)
Type of function used as constructor/destructor for cache creation and destruction.
Definition: slab.h:16
unsigned int slab_flags_t
Type for slab flags.
Definition: slab.h:13
kmem_cache_t * kmem_cache_create(const char *name, unsigned int size, unsigned int align, slab_flags_t flags, kmem_fun_t ctor, kmem_fun_t dtor)
Creates a new kmem_cache structure.
Definition: slab.c:409
int kmem_cache_destroy(kmem_cache_t *cachep)
Destroys a specified kmem_cache structure.
Definition: slab.c:437
Stores the information of a cache.
Definition: slab.h:27
list_head slabs_partial
Handler for the partial slabs list.
Definition: slab.h:53
unsigned int object_size
Size of the objects contained in the cache.
Definition: slab.h:35
unsigned int free_num
The number of free slabs.
Definition: slab.h:41
unsigned int gfp_order
The order for getting free pages.
Definition: slab.h:45
kmem_fun_t dtor
Destructor for the elements.
Definition: slab.h:49
unsigned int size
Size of the cache.
Definition: slab.h:33
list_head slabs_full
Handler for the full slabs list.
Definition: slab.h:51
unsigned int align
Alignment requirement of the type of objects.
Definition: slab.h:37
slab_flags_t flags
The Get Free Pages (GFP) flags.
Definition: slab.h:43
list_head cache_list
Handler for placing it inside a lists of caches.
Definition: slab.h:29
unsigned int total_num
The total number of slabs.
Definition: slab.h:39
list_head slabs_free
Handler for the free slabs list.
Definition: slab.h:55
const char * name
Name of the cache.
Definition: slab.h:31
kmem_fun_t ctor
Constructor for the elements.
Definition: slab.h:47