Add alignment block splitting to malloc_freelist #91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The main allocator is modified to split blocks to align them, returning surplus to the free list.
I am sharing this because I think this approach is a little cleaner than the existing approach. It has several advantages and adds minimal complexity. It has been tested locally but it needs more testing and review. The primary code path should be unchanged for regular allocations besides dropping the minimum allocation size and calculating alignment_slack which should always be zero for regular allocations.
The fundamental algorithm is mostly unchanged although there is additional logic to calculate alignment_slack in the case that the alignment is greater than the alignment of the found block. If alignment_slack is non-zero it is used to split the block so that block is sufficiently aligned with the surplus returned to the free list. Some indent has been removed for readability.
aligned_free is now redundant but it is kept for compatibility. It is no longer necessary to unwrap an offset field in wrapper headers as the main allocation header block is aligned and free can be called directly on aligned allocations, so aligned_free now simply delegates to free(). Also, the surplus memory to align blocks is not wasted and can be allocated.
This changes needs rigorous testing and review. This is a heads up!
Type of change
How Has This Been Tested?
libmemory_freelist_test
test passes.Test Configuration:
Checklist: