|
AquilaOS documentation
How it works, and its code
|
#include <core/system.h>Go to the source code of this file.
Data Structures | |
| struct | vmem_seg |
| A segment of an arena: a range that is either free or allocated. More... | |
| struct | vmem |
| An arena: a range, and its segments. More... | |
Macros | |
| #define | VMEM_LISTS (sizeof(size_t) * 8) |
| #define | VMEM_HASH 256 |
Functions | |
| int | vmem_init (struct vmem *vm, const char *name, uintptr_t base, size_t size, size_t quantum) |
| Sets up an arena: the range [base, base + size), all free. | |
| struct vmem_seg * | vmem_alloc (struct vmem *vm, size_t size) |
| Allocates a range from an arena. | |
| struct vmem_seg * | vmem_find (struct vmem *vm, uintptr_t base) |
| Finds the allocated segment that starts at an address. | |
| void | vmem_free (struct vmem *vm, struct vmem_seg *seg) |
| Frees an allocated segment. | |
| #define VMEM_HASH 256 |
Definition at line 38 of file vmem.h.
Referenced by hash_chain().
| #define VMEM_LISTS (sizeof(size_t) * 8) |
Definition at line 37 of file vmem.h.
Referenced by vmem_alloc().
Allocates a range from an arena.
| vm | the arena |
| size | the size wanted, in bytes (rounded up to a multiple of the quantum) |
Definition at line 134 of file vmem.c.
References vmem_seg::base, vmem::free, vmem_seg::free, free_list(), hash_chain(), vmem::inuse, kmalloc(), list_insert(), log2_ceil(), log2_floor(), M_ZERO, NULL, vmem::quantum, seg_link(), seg_list_remove(), vmem_seg::size, vmem_alloc(), and VMEM_LISTS.
Referenced by kvmem_alloc(), and vmem_alloc().
Finds the allocated segment that starts at an address.
| vm | the arena |
| base | the address |
Definition at line 193 of file vmem.c.
References vmem_seg::base, hash_chain(), NULL, and vmem_find().
Referenced by kfree(), and vmem_find().
Frees an allocated segment.
It merges with the free segments next to it, so that the arena doesn't fragment. Freeing a free segment panics.
| vm | the arena |
| seg | the segment, which vmem_alloc() gave |
Definition at line 223 of file vmem.c.
References free_list(), hash_chain(), vmem::inuse, list_insert(), NULL, panic, seg_list_remove(), seg_merge(), and vmem_free().
Referenced by kfree(), kvmem_alloc(), and vmem_free().
Sets up an arena: the range [base, base + size), all free.
| vm | the arena |
| name | its name, for messages |
| base | the range's start |
| size | its size, in bytes (rounded down to a multiple of quantum) |
| quantum | the unit of allocation: every segment's size is a multiple of it |
Definition at line 104 of file vmem.c.
References vmem_seg::base, free_list(), kmalloc(), list_insert(), M_ZERO, memset(), vmem::name, NULL, vmem::quantum, seg_link(), vmem::size, vmem_seg::size, and vmem_init().
Referenced by kvmem_setup(), and vmem_init().