Commit 3bcf918f authored by Tomislav Novak's avatar Tomislav Novak Committed by Pavlo Kushnir

Fix large size class category handling in folly::goodMallocSize()

Summary:
jemalloc seems to now use `4064 * 1024` as `arena_maxclass`. Therefore,
allocations that fall in the range `(4064*1024, 4072*1024]` will trigger an
assert in `folly::goodMallocSize()` (`nallocx()` will round up sizes within
that range up to the next multiple of 4 MB (chunk size)).

Test Plan: Call to `folly::goodMallocSize(4161568)` no longer triggeres an assert.

Reviewed By: je@fb.com

Subscribers: aalexandre, trunkagent, njormrod, folly-diffs@

FB internal diff: D1638370

Signature: t1:1638370:1414703429:f3ed2cc8dcb183ff4e8367e2c1f884e122605cba
parent 5ea13370
...@@ -140,18 +140,11 @@ inline size_t goodMallocSize(size_t minSize) noexcept { ...@@ -140,18 +140,11 @@ inline size_t goodMallocSize(size_t minSize) noexcept {
// Round up to the next multiple of 64; we don't want to trip over // Round up to the next multiple of 64; we don't want to trip over
// cache line boundaries. // cache line boundaries.
goodSize = (minSize + 63) & ~size_t(63); goodSize = (minSize + 63) & ~size_t(63);
} else if (minSize <= 3584) {
// Round up to the next multiple of 256. For some size classes jemalloc
// will additionally round up to the nearest multiple of 512, hence the
// nallocx() call.
goodSize = nallocx((minSize + 255) & ~size_t(255), 0);
} else if (minSize <= 4072 * 1024) {
// Round up to the next multiple of 4KB
goodSize = (minSize + 4095) & ~size_t(4095);
} else { } else {
// Holy Moly // Boundaries between size classes depend on numerious factors, some of
// Round up to the next multiple of 4MB // which can even be modified at run-time. Determine the good allocation
goodSize = (minSize + 4194303) & ~size_t(4194303); // size by calling nallocx() directly.
goodSize = nallocx(minSize, 0);
} }
assert(nallocx(goodSize, 0) == goodSize); assert(nallocx(goodSize, 0) == goodSize);
return goodSize; return goodSize;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment