microsoft / microsoft/mimalloc
`mi_malloc_satisfies_alignment` returns false for small alignments
- Dominant language
- C
- Stars
- 13.4k
- Forks
- 1.2k
- Avg merge
- 4d 45m
- Merged PRs (30d)
- 13
Description
`mi_malloc_satisfies_alignment` seems like it will not do the right thing for a allocation request with a explicit-but-small alignment request. This can lead to some functions calling mi_malloc_aligned over mi_malloc, which will hurt performance.
As a concrete example, the function returns false for an alignment of 1, but any pointer would satisfy this trivially. (I suspect in reality the first check should be `alignment <= sizeof(void*)`?)
https://github.com/microsoft/mimalloc/blob/13a4030619edada133e1a3c06c6287ad5a9c74c1/include/mimalloc-internal.h#L237
On a related note, what *is* the test for a given `(size, alignment)` that I should go through the unaligned function? I'm attempting to improve Rust's mimalloc integration, and for Rust, every allocation request comes with both size and alignment. I had been assuming `alignment <= alignof(maxalign_t) && alignment <= size` is the test, but then I noticed this.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at include/mimalloc-internal.h around line 237 and inspect mi_malloc_satisfies_alignment, mi_malloc, and mi_malloc_aligned. Check concrete small-alignment cases such as alignment 1 and compare the function's result with the proposed pointer-size boundary. Done means the alignment decision is correct and the (size, alignment) rule for using the unaligned path is clear.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, rust
- Domain
- operating-systems, performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100