Block-based Memory Allocator
Block-based Memory Allocator
Nomenclature
- Block
- The minimal size at which memory is handed out to the GC / mutator.
- Block Descriptor
- The metadata associated with a given block. For each block address, the address of the associated metadata can be obtained via pointer arithmetic.
- (Block) Group
- A continuous run of multiple consecutive blocks in memory, up to CLUSTER_MAX_BLOCKS.
- Chain
- Multiple block groups linked together to form a (singly-)linked list.
- Cluster
- The minimal size at which memory is requested from / returned to the OS.
- Large Object
- An Object which is larger than LARGE_OBJECT_THRESHOLD (currently equal to BLOCK_SIZE, which is 4096 bytes)
- Object
- A single piece of data representing an Idris value.
- Oversized Block Group
- A continuous run of multiple consecutive blocks in memory, larger than CLUSTER_MAX_BLOCKS. Only the first block has associated metadata.
Memory Layout
At the beginning of each Cluster, the Block Descriptors for all Blocks in the Cluster are stored. Using the function get_block_descr, the Block Descriptor for any valid memory address can be fetched. A heap-allocated object's start address is always valid to fetch the Block Descriptor. Except for large objects, also any interior memory address of the object can be used.
Block Flags
The following flags are stored in the flags field of each Block Descriptor. All Blocks in a single Block Group have the same flags.
- BLOCKDESCR_FLAG_EVACUATED
- This flag is used during GC to mark the to-space. Objects in Blocks with this flag have already been evacuated and will not be moved again during the current GC cycle. This flag is cleared from all Blocks after GC is finished.
- BLOCKDESCR_FLAG_LARGE_OBJECT
- This flag is used to mark Blocks that belong to a Large Object which means the Object will not be moved by the GC (although it can be freed, if there are no references to the Large Object).