AquilaOS documentation
How it works, and its code
Toggle main menu visibility
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
11
struct
slab
;
12
14
struct
malloc_type
{
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 */
22
struct
slab
*
slabs
[
SLAB_CLASSES
];
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
32
MALLOC_DECLARE
(M_BUFFER);
33
MALLOC_DECLARE
(M_RINGBUF);
34
MALLOC_DECLARE
(M_QUEUE);
35
MALLOC_DECLARE
(M_QNODE);
36
MALLOC_DECLARE
(M_HASHMAP);
37
MALLOC_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. */
41
void
*
kmalloc
(
size_t
size
,
struct
malloc_type
*
type
,
int
flags);
42
void
kfree
(
void
*);
43
44
#endif
/* ! _MM_KVMEM_H */
kmalloc
void * kmalloc(size_t size, struct malloc_type *type, int flags)
Allocates memory for one of the kernel's structures.
Definition
kvmem.c:123
SLAB_CLASSES
#define SLAB_CLASSES
Definition
kvmem.h:9
MALLOC_DECLARE
#define MALLOC_DECLARE(type)
Definition
kvmem.h:29
kfree
void kfree(void *)
Frees an object that kmalloc() gave.
Definition
kvmem.c:146
malloc_type
A malloc type: what an allocation is for, which /proc/kvmem counts by.
Definition
kvmem.h:14
malloc_type::slabs
struct slab * slabs[SLAB_CLASSES]
Definition
kvmem.h:22
malloc_type::name
const char * name
Definition
kvmem.h:15
malloc_type::total
size_t total
Definition
kvmem.h:18
malloc_type::nr
size_t nr
Definition
kvmem.h:17
malloc_type::qnode
struct qnode * qnode
Definition
kvmem.h:19
malloc_type::desc
const char * desc
Definition
kvmem.h:16
slab
A slab's header, at the start of its page.
Definition
slab.c:30
slab::size
uint32_t size
Definition
slab.c:34
slab::type
struct malloc_type * type
Definition
slab.c:32
kernel
include
mm
kvmem.h
Generated by
1.18.0