|
Serene Runtime 1.0.0
C runtime for the Serene programming language
|
#include <stdlib.h>#include "serene/rt/mm/interface.h"#include "serene/utils.h"#include <assert.h>#include <inttypes.h>#include <string.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_allocate (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_allocate or srn_mm_reallocate. | |
| static size_t | closest_multiple (size_t x, size_t m) |
| static size_t | block_capacity (const srn_block_t *block) |
| Return the size of the payload section of 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. | |
| size_t | srn_mm_get_block_size (void) |
| Calculates and return the block size based on our desired size and 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 () |
| 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 178 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.
Definition at line 207 of file default.c.
|
inlinestatic |
Definition at line 56 of file default.c.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Definition at line 67 of file default.c.
|
inlinestatic |
Definition at line 187 of file default.c.
|
inlinestatic |
Definition at line 76 of file default.c.
|
inlinestatic |
|
inlinestatic |
Definition at line 166 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 362 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 141 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 364 of file default.c.
|
nodiscard |
Allocate memory on a block with the given block_id.
Definition at line 347 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_block_size | ( | void | ) |
Calculates and return the block size based on our desired size and the OS page size.
Basically the ruturn value will be a number multiple of the OS page size and close or equal to our desired size
Definition at line 285 of file default.c.
| size_t srn_mm_get_os_page_size | ( | void | ) |
Retutrns the OS page size.
Definition at line 270 of file default.c.
|
nodiscard |
Allocate memory on the importal block which will never gets freed.
Definition at line 356 of file default.c.
| srn_mm_t * srn_mm_init | ( | void | ) |
Initialize the memory manager, this function will panic on error.
Definition at line 294 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 388 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 325 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 117 of file default.c.
|
static |
|
static |