Skip to content

Figure out rules for minimal alignment of system allocator #812

@RalfJung

Description

@RalfJung

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

No one assigned

    Labels

    A-intptrcastArea: affects int2ptr and ptr2int castsA-shimsArea: This affects the external function shimsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions