libc - Fix malloc() alignment for small allocations
commit3f81f4537238b9318fd18979ca2d5be521caea13
authorMatthew Dillon <dillon@apollo.backplane.com>
Sat, 3 Sep 2016 17:24:56 +0000 (3 10:24 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Sat, 3 Sep 2016 17:24:56 +0000 (3 10:24 -0700)
treedbee04e563eee7dcba235783aa02f74ea8182613
parent4d8a23489695ade9247e1595bf006757f6a9ea7d
libc - Fix malloc() alignment for small allocations

* malloc()'s slab allocator was set to use 8-byte alignment
  for any allocation < 128 bytes that was not otherwise on
  an integral alignment boundary.  This breaks GCC-7 which assumes
  16-byte alignment for non-16-integral sizes < 128 bytes.  e.g.
  if 18 bytes is allocated, GCC-7 assumes the resulting pointer will
  be 16-byte-aligned.

* The standard is somewhat deficient in its characterization of what the
  required alignment should be, because there are already instructions
  which prefer 32 and 64 byte alignments, but are relaxed on Intel to
  only require 16-byte alignments (aka %ymm and %zmm registers in the
  vector extensions), and its stupid to enforce even larger alignments
  for tiny allocations.

* But generally speaking it makes sense to enforce a 16-byte alignment
  for any allocations >= 16 bytes, regardless of the size being passed-in
  not being 16-byte aligned, and this change does that.  Allocations of
  less than 16 bytes will still be 8-byte aligned because it is phenominally
  wasteful for them not to be.

Reported-by: marino
lib/libc/stdlib/nmalloc.c