-
Notifications
You must be signed in to change notification settings - Fork 391
Closed
Labels
A-intptrcastArea: affects int2ptr and ptr2int castsArea: affects int2ptr and ptr2int castsA-shimsArea: This affects the external function shimsArea: This affects the external function shimsC-bugCategory: This is a bug.Category: This is a bug.
Description
libstd assumes that the system allocator (which does not have an explicitly alignment parameter) still provides some minimal alignment, given by MIN_ALIGN
:
// The minimum alignment guaranteed by the architecture. This value is used to
// add fast paths for low alignment values.
#[cfg(all(any(target_arch = "x86",
target_arch = "arm",
target_arch = "mips",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "asmjs",
target_arch = "wasm32")))]
pub const MIN_ALIGN: usize = 8;
#[cfg(all(any(target_arch = "x86_64",
target_arch = "aarch64",
target_arch = "mips64",
target_arch = "s390x",
target_arch = "sparc64")))]
pub const MIN_ALIGN: usize = 16;
However, at least on Unix, MIN_ALIGN
is only exploited for allocations where the size is at least as big as the alignment. On Windows, OTOH, MIN_ALIGN
is exploited regardless of the size of the allocation.
Does that mean that we can reduce the alignment we provide for small allocations?
Metadata
Metadata
Assignees
Labels
A-intptrcastArea: affects int2ptr and ptr2int castsArea: affects int2ptr and ptr2int castsA-shimsArea: This affects the external function shimsArea: This affects the external function shimsC-bugCategory: This is a bug.Category: This is a bug.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
RalfJung commentedon Jun 30, 2019
This behavior on Unix platforms was introduced by rust-lang/rust@21d8992 to fix rust-lang/rust#45955 (I totally forgot I reported this...). Curiously, the Windows allocator was left unchanged.
Cc @SimonSapin
RalfJung commentedon Jun 30, 2019
https://support.microsoft.com/en-us/help/286470/how-to-use-pageheap-exe-in-windows-xp-windows-2000-and-windows-server seems to indicate that Windows indeed guarantees alignment regardless of size:
it doesn't say anything about size.
So maybe we should make Miri give out more liberally aligned small allocations everywhere except on Windows.
SimonSapin commentedon Jul 1, 2019
It’s been a while, but not changing Windows may have been an oversight. I did not look at all into the guarantees provided by
HeapAlloc
like I did formalloc
.RalfJung commentedon Jul 2, 2019
See jemalloc/jemalloc#1533.
Auto merge of #817 - RalfJung:small-alloc, r=RalfJung