-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wasi: round up the size for aligned_alloc
#115254
Conversation
C11 `aligned_alloc` requires that the size be a multiple of the alignment. This is enforced in the wasi-libc emmalloc implementation, which always returns NULL if the size is not a multiple. (The default `MALLOC_IMPL=dlmalloc` does not currently check this.)
r? @thomcc (rustbot has picked a reviewer for you, use r? to override) |
@bors r+ |
Note that this behavior has been proposed to change, so we should consider reverting this in the future if https://open-std.org/JTC1/SC22/WG14/www/docs/n2072.htm is standardized. |
wasi: round up the size for `aligned_alloc` C11 `aligned_alloc` requires that the size be a multiple of the alignment. This is enforced in the wasi-libc emmalloc implementation, which always returns NULL if the size is not a multiple. (The default `MALLOC_IMPL=dlmalloc` does not currently check this.)
We could... but I wouldn't bother unless there's some evidence that it's useful, and not just the allocator rounding up on your behalf or otherwise wasting that padding. |
It's definitely useful, to the point where it's surprising this restriction exists. Consider allocating 1 byte at alignment 1024 from a bump nursery (this is true for other types of allocators as well but less easy to show). You'd do something like To put it another way, if I'm an allocator, I only need to allocate (Note: if I have an off-by-one anywhere in here, I blame the fact that I have the flu) |
☀️ Test successful - checks-actions |
Finished benchmarking commit (1baf77a): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 630.803s -> 631.998s (0.19%) |
FWIW, I can't find this requirement in C18 or C23 any more, so wasi may have to be updated here. EDIT: #125003 |
C11
aligned_alloc
requires that the size be a multiple of thealignment. This is enforced in the wasi-libc emmalloc implementation,
which always returns NULL if the size is not a multiple.
(The default
MALLOC_IMPL=dlmalloc
does not currently check this.)