Make goodMallocSize always use nallocx
authorGiuseppe Ottaviano <ott@fb.com>
Wed, 25 Nov 2015 08:26:31 +0000 (00:26 -0800)
committerfacebook-github-bot-0 <folly-bot@fb.com>
Wed, 25 Nov 2015 09:20:20 +0000 (01:20 -0800)
commit5d820ea6512b730ec44696bb1a98d689f0b1c302
treeb93914d049d7fe17cdb96e9e59505261e2f37c2d
parent1f4a82214560abd7d83cbbe8027be90885e22d88
Make goodMallocSize always use nallocx

Summary: `goodMallocSize` is used extensively in `folly` data structures,
especially for containers optimized for small contents, such as
`fbstring` and `small_vector`.

However, it makes the design decision to align the allocation size to
a x86 cache line, forcing a minimum allocation size of `64` bytes,
despite jemalloc can provide smaller size classes (8, 16, 32,
48). This causes a large discontinuity between small contents that can
be inlined and heap-allocated contents:

- For `fbstring`, a string of 23 bytes (including terminator) occupies
  24 bytes (`sizeof(fbstring)`), a string of 24 bytes occupies 24 + 64
  + allocation overhead when it could be 24 + 32 + allocation
  overhead. The waste is more than 50%.

- For `small_vector<uint32_t, 1, uint32_t>`, for instance, a vector
  with 1 element occupies 12 bytes, a vector with 2 elements occupies
  12 + 64 + allocation overhead when it could be 12 + 8 + allocation
  overhead. The waste is more than 250%.

With this diff we just trust jemalloc and always use `nallocx`. If a
data structure need cache-line alignment it should be implemented at
its level.

Reviewed By: elsteveogrande

Differential Revision: D2688156

fb-gh-sync-id: 46548d4a91952e7c673d4f0997c4c067e03c190d
folly/Malloc.h