|
Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
|
#include <assert.h>#include <inttypes.h>#include <stdlib.h>#include <string.h>#include "serene/rt/mm/interface.h"#include "serene/utils.h"Go to the source code of this file.
Macros | |
| #define | MM_LOG(FMT, ...) |
Functions | |
| static bool | is_block_id_free (const srn_mm_t *mm, uint16_t bit) |
| static void | allocated_block_id (srn_mm_t *mm, uint16_t bit) |
| static void | deallocated_block_id (srn_mm_t *mm, uint16_t bit) |
| static int | find_a_free_block_id (const srn_mm_t *mm) |
| static srn_block_t * | get_block (const srn_mm_t *mm, srn_block_id_t block_id) |
| An abstraction over ID->Block operation. | |
| static void * | stdlib_allocator (size_t size, size_t alignment) |
| Just a proxy functions to the standard stdlib malloc/free later on if we decided to use mimalloc or something or even our own malloc, we can plug them in like this. | |
| static void | stdlib_releaser (void *ptr) |
| void * | srn_mm_malloc (srn_mm_t *mm, size_t size) |
| Generic allocations that do not participate in the block based pools. | |
| void * | srn_mm_reallocate (srn_mm_t *mm, void *ptr, size_t new_size) |
| void | srn_mm_free (srn_mm_t *mm, void *ptr) |
| Release a pointer previously returned by srn_mm_malloc or srn_mm_reallocate. | |
| static size_t | block_capacity (const srn_block_t *block) |
| Return the size of the payload section of the block. | |
| static size_t | block_remaining (const srn_block_t *block) |
| Return the number of unused payload bytes left in the block. | |
| static void | init_block (srn_mm_t *mm, srn_block_t *block) |
| static void * | alloc_block_internal (srn_mm_t *mm) |
| Allocate a block worth of memory using the memory provider. | |
| static void | destroy_chain (srn_mm_t *mm, srn_block_id_t root_id) |
| static void * | alloc_in_block (srn_mm_t *mm, srn_block_t *root_block, size_t size, size_t alignment) |
| This is the main allocation logic that allocates the space in the given block. | |
| size_t | srn_mm_get_os_page_size (void) |
| Retutrns the OS page size. | |
| srn_block_t * | srn_mm_get_block (srn_mm_t *mm, srn_block_id_t block_id) |
| Return the block object associated by the given block_id. | |
| srn_mm_t * | srn_mm_init (const srn_configuration_t *config) |
| Initialize the memory manager, this function will panic on error. | |
| void | srn_mm_shutdown (srn_mm_t *mm) |
| Shut down the memory manager and release the resources. | |
| void * | srn_mm_allocate_in_block_aligned (srn_mm_t *mm, srn_block_id_t block_id, size_t size, size_t alignment) |
| Allocate memory on a block with the given block_id. | |
| void * | srn_mm_immortal_allocate_aligned (srn_mm_t *mm, size_t size, size_t alignment) |
| Allocate memory on the importal block which will never gets freed. | |
| void | srn_unlock_memory_manager (srn_mm_t *mm) |
| Unocks the memory manager. | |
| void | srn_lock_memory_manager (srn_mm_t *mm) |
| Locks the memory manager. | |
| srn_block_id_t | srn_mm_allocate_block (srn_mm_t *mm) |
| Allocate a new block in the memory manager and return its ID. | |
| void | srn_mm_release_block (srn_mm_t *mm, srn_block_id_t id) |
| Release the given block id and free the memory for later allocations. | |
Variables | |
| static srn_memory_provider_t | stdlib_provider |
|
inlinestatic |
Allocate a block worth of memory using the memory provider.
This is an internal function and it will NOT allocate block_id nor track the block via the memory manager by default.
Definition at line 197 of file default.c.
|
inlinestatic |
This is the main allocation logic that allocates the space in the given block.
Other public functions have to use this fuction to operate. The caller must hold the chain's lock for the whole call.
Definition at line 243 of file default.c.
|
inlinestatic |
Definition at line 56 of file default.c.
|
inlinestatic |
Return the size of the payload section of the block.
Definition at line 173 of file default.c.
|
inlinestatic |
|
inlinestatic |
Definition at line 67 of file default.c.
|
inlinestatic |
Definition at line 206 of file default.c.
|
inlinestatic |
Definition at line 76 of file default.c.
|
inlinestatic |
An abstraction over ID->Block operation.
Definition at line 109 of file default.c.
|
inlinestatic |
Definition at line 185 of file default.c.
|
inlinestatic |
| void srn_lock_memory_manager | ( | srn_mm_t * | mm | ) |
Locks the memory manager.
We have to lock the memory manager when allocating blocks. TODO(lxsameer): Do we need to support thread local blocks?
Definition at line 424 of file default.c.
|
nodiscard |
Allocate a new block in the memory manager and return its ID.
The client code can use the ID to allocate memory on the block and when it's done, just use the same ID to release the block
Definition at line 426 of file default.c.
|
nodiscard |
Allocate memory on a block with the given block_id.
Definition at line 396 of file default.c.
| void srn_mm_free | ( | srn_mm_t * | mm, |
| void * | ptr ) |
| srn_block_t * srn_mm_get_block | ( | srn_mm_t * | mm, |
| srn_block_id_t | block_id ) |
| size_t srn_mm_get_os_page_size | ( | void | ) |
Retutrns the OS page size.
Definition at line 303 of file default.c.
|
nodiscard |
Allocate memory on the importal block which will never gets freed.
Definition at line 415 of file default.c.
| srn_mm_t * srn_mm_init | ( | const srn_configuration_t * | config | ) |
Initialize the memory manager, this function will panic on error.
config provides the knobs the manager reads at init (mm.block_size_magnitude, the block size is 1 << magnitude); a null config means "use the defaults". The config is read only during the call, so the caller may pass a stack value and reuse it for srn_engine_make.
Definition at line 322 of file default.c.
|
nodiscard |
Generic allocations that do not participate in the block based pools.
Equivalent to malloc/realloc/free. Routed through the memory manager so the backend can later be swapped without touching callers. mm is reserved for future per manager routing and is currently unused inside the implementation.
Definition at line 155 of file default.c.
|
nodiscard |
| void srn_mm_release_block | ( | srn_mm_t * | mm, |
| srn_block_id_t | id ) |
Release the given block id and free the memory for later allocations.
Definition at line 451 of file default.c.
| void srn_mm_shutdown | ( | srn_mm_t * | mm | ) |
Shut down the memory manager and release the resources.
Will panic on error. Technically it should be the final piece of clean up that we call. Note: Shutdown is not thread safe at has to execute on the main thread.
Definition at line 374 of file default.c.
| void srn_unlock_memory_manager | ( | srn_mm_t * | mm | ) |
|
static |
Just a proxy functions to the standard stdlib malloc/free later on if we decided to use mimalloc or something or even our own malloc, we can plug them in like this.
Definition at line 123 of file default.c.
|
static |
|
static |