|
Serene Runtime 1.0.0
C runtime for the Serene programming language
|
Notes: More...
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 |
| TODO(lxsameer): Since we want to move fast, at this stage a static 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 | DESIRED_BLOCK_SIZE 131072 |
| This is the value that we want for our blocks but we want it to be a multiple of the page size on the platform as well. | |
| #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. | |
| 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_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 (void) |
| 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_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. | |
Notes:
srn_mm_t.Definition in file interface.h.
| #define DEFAULT_BLOCK_ALIGNMENT 16U |
We strictly use 16 bytes alignment for blocks.
Definition at line 47 of file interface.h.
| #define DESIRED_BLOCK_SIZE 131072 |
This is the value that we want for our blocks but we want it to be a multiple of the page size on the platform as well.
So there is no guarantee that we get exactly this number. 128Kib
Definition at line 53 of file interface.h.
| #define FALLBACK_PAGE_SIZE 4096U |
Definition at line 36 of file interface.h.
| #define MAX_NUMBER_OF_BLOCKS 256U |
TODO(lxsameer): Since we want to move fast, at this stage a static 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 44 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 166 of file interface.h.
| #define srn_mm_immortal_allocate | ( | mm, | |
| T ) |
Definition at line 169 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 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.