MentOS
0.8.0
The Mentoring Operating System
|
Functions and structures for managing memory slabs. More...
Go to the source code of this file.
Classes | |
struct | kmem_cache_t |
Stores the information of a cache. More... | |
Macros | |
#define | KMEM_CREATE(objtype) kmem_cache_create(#objtype, sizeof(objtype), alignof(objtype), GFP_KERNEL, NULL, NULL) |
Create a new cache. | |
#define | KMEM_CREATE_CTOR(objtype, ctor) kmem_cache_create(#objtype, sizeof(objtype), alignof(objtype), GFP_KERNEL, (kmem_fun_t)(ctor), NULL) |
Creates a new cache and allows to specify the constructor. | |
Typedefs | |
typedef unsigned int | slab_flags_t |
Type for slab flags. | |
typedef void(* | kmem_fun_t) (void *) |
Type of function used as constructor/destructor for cache creation and destruction. | |
typedef struct kmem_cache_t | kmem_cache_t |
Stores the information of a cache. | |
Functions | |
int | kmem_cache_init (void) |
Initializes the kernel memory cache system. More... | |
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. More... | |
int | kmem_cache_destroy (kmem_cache_t *cachep) |
Destroys a specified kmem_cache structure. More... | |
void * | kmem_cache_alloc (kmem_cache_t *cachep, gfp_t flags) |
Allocates an object from the specified kmem_cache_t. More... | |
void | kmem_cache_free (void *addr) |
Frees an object previously allocated from a kmem_cache_t. More... | |
void * | kmalloc (unsigned int size) |
Allocates memory of the specified size using kmalloc. More... | |
void | kfree (void *ptr) |
Frees memory allocated by kmalloc or kmem_cache_alloc. More... | |
Functions and structures for managing memory slabs.
void kfree | ( | void * | ptr | ) |
Frees memory allocated by kmalloc or kmem_cache_alloc.
ptr | Pointer to the memory to free. |
void* kmalloc | ( | unsigned int | size | ) |
Allocates memory of the specified size using kmalloc.
size | Size of the memory to allocate. |
void* kmem_cache_alloc | ( | kmem_cache_t * | cachep, |
gfp_t | flags | ||
) |
Allocates an object from the specified kmem_cache_t.
cachep | Pointer to the cache from which to allocate the object. |
flags | Flags for the allocation (e.g., GFP_KERNEL). |
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.
This function allocates memory for a new cache and initializes it with the provided parameters. The cache is ready for use after this function returns.
name | Name of the cache. |
size | Size of each object in the cache. |
align | Alignment requirement for objects in the cache. |
flags | Flags for slab allocation. |
ctor | Constructor function for initializing objects (can be NULL). |
dtor | Destructor function for cleaning up objects (can be NULL). |
int kmem_cache_destroy | ( | kmem_cache_t * | cachep | ) |
Destroys a specified kmem_cache structure.
This function cleans up and frees all memory associated with the specified cache, including all associated slab pages. After calling this function, the cache should no longer be used.
cachep | Pointer to the kmem_cache_t structure to destroy. |
void kmem_cache_free | ( | void * | addr | ) |
Frees an object previously allocated from a kmem_cache_t.
addr | Pointer to the object to free. |
int kmem_cache_init | ( | void | ) |
Initializes the kernel memory cache system.
This function initializes the global cache list and creates the main cache for managing kmem_cache_t structures. It also creates caches for different order sizes for kmalloc allocations.