AquilaOS documentation
How it works, and its code
Loading...
Searching...
No Matches
kvmem.h
Go to the documentation of this file.
1#ifndef _MM_KVMEM_H
2#define _MM_KVMEM_H
3
4/* The kernel's memory allocator (mm/kvmem.c). Objects of up to SLAB_MAX
5 * bytes come from slabs (mm/slab.c), in sizes that are powers of two from
6 * SLAB_MIN. */
7#define SLAB_MIN 16
8#define SLAB_MAX 1024
9#define SLAB_CLASSES 7
10
11struct slab;
12
15 const char *name;
16 const char *desc;
17 size_t nr; /* how many objects it has */
18 size_t total; /* their size, in bytes */
19 struct qnode *qnode; /* its node on the list of malloc types */
20
21 /* its slabs with free objects, per size class */
23};
24
25/* A kmalloc() flag: zero the object. */
26#define M_ZERO 0x0001
27
28/* Declares, or defines, a malloc type. */
29#define MALLOC_DECLARE(type) extern struct malloc_type (type)
30#define MALLOC_DEFINE(type, _name, _desc) struct malloc_type (type) = {.name = (_name), .desc = (_desc)}
31
32MALLOC_DECLARE(M_BUFFER);
33MALLOC_DECLARE(M_RINGBUF);
34MALLOC_DECLARE(M_QUEUE);
35MALLOC_DECLARE(M_QNODE);
36MALLOC_DECLARE(M_HASHMAP);
37MALLOC_DECLARE(M_HASHMAP_NODE);
38
39/* Allocates `size` bytes of `type` (zeroed with M_ZERO), or returns NULL
40 * if there's no memory; frees what kmalloc() gave. */
41void *kmalloc(size_t size, struct malloc_type *type, int flags);
42void kfree(void *);
43
44#endif /* ! _MM_KVMEM_H */
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
Definition kvmem.c:123
#define SLAB_CLASSES
Definition kvmem.h:9
#define MALLOC_DECLARE(type)
Definition kvmem.h:29
void kfree(void *)
Frees an object that kmalloc() gave.
Definition kvmem.c:146
A malloc type: what an allocation is for, which /proc/kvmem counts by.
Definition kvmem.h:14
struct slab * slabs[SLAB_CLASSES]
Definition kvmem.h:22
const char * name
Definition kvmem.h:15
size_t total
Definition kvmem.h:18
size_t nr
Definition kvmem.h:17
struct qnode * qnode
Definition kvmem.h:19
const char * desc
Definition kvmem.h:16
A slab's header, at the start of its page.
Definition slab.c:30
uint32_t size
Definition slab.c:34
struct malloc_type * type
Definition slab.c:32