|
Serene Runtime 1.0.0-dev
C runtime for the Serene programming language
|
Notes: More...
#include <stddef.h>#include <stdint.h>#include <stdio.h>#include "serene/rt/configuration.h"#include "serene/utils.h"Go to the source code of this file.
Data Structures | |
| struct | srn_memory_provider_t |
| This interface is here to abstract over the allocator. More... | |
| struct | srn_block_t |
| struct | srn_mm_t |
| Main memory manager structure that will own all the allocated blocks and data. More... | |
Macros | |
| #define | FALLBACK_PAGE_SIZE 4096U |
| #define | MAX_NUMBER_OF_BLOCKS 256U |
| array of blocks is enough for us, we can tweak the size as we see fit. | |
| #define | DEFAULT_BLOCK_ALIGNMENT 16U |
| We strictly use 16 bytes alignment for blocks. | |
| #define | SRN_BLOCK_NO_ID SIZE_MAX |
| #define | srn_mm_allocate_in_block(mm, id, T) |
| #define | srn_mm_immortal_allocate(mm, T) |
Typedefs | |
| typedef struct srn_memory_provider_t | srn_memory_provider_t |
| This interface is here to abstract over the allocator. | |
| typedef struct srn_block_t | srn_block_t |
| typedef struct srn_mm_t | srn_mm_t |
| Main memory manager structure that will own all the allocated blocks and data. | |
Functions | |
| size_t | srn_mm_get_os_page_size (void) |
| Retutrns the OS page size. | |
| 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. | |
| 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. | |
| 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. | |
| 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_unlock_memory_manager (srn_mm_t *mm) |
| Unocks the memory manager. | |
| void | srn_lock_memory_manager (srn_mm_t *mm) |
| Locks the memory manager. | |
| 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. | |
Notes:
Definition in file interface.h.
| #define DEFAULT_BLOCK_ALIGNMENT 16U |
We strictly use 16 bytes alignment for blocks.
Definition at line 53 of file interface.h.
| #define FALLBACK_PAGE_SIZE 4096U |
Definition at line 42 of file interface.h.
| #define MAX_NUMBER_OF_BLOCKS 256U |
array of blocks is enough for us, we can tweak the size as we see fit.
But we need to change this for the final stage. We should be able to dynamically expand the array of blocks. Notes. Due to my laziness, if you ever change this value, you need to change the popcount functions for the block bitmap as well.
Definition at line 50 of file interface.h.
| #define SRN_BLOCK_NO_ID SIZE_MAX |
Definition at line 63 of file interface.h.
| #define srn_mm_allocate_in_block | ( | mm, | |
| id, | |||
| T ) |
Definition at line 180 of file interface.h.
| #define srn_mm_immortal_allocate | ( | mm, | |
| T ) |
Definition at line 183 of file interface.h.
| typedef struct srn_block_t srn_block_t |
| typedef struct srn_memory_provider_t srn_memory_provider_t |
This interface is here to abstract over the allocator.
For instance, malloc/free can be a page provider. This will let us switch to other implementation later on. Eventually we might end up coming up with our own version of malloc/free.
| typedef struct srn_mm_t srn_mm_t |
Main memory manager structure that will own all the allocated blocks and data.
In every instance of the compiler there should be only one instance of this. It should be created via srn_mm_init and destroyed via srn_shutdown_memory_manager.
| 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.