Skip to content

Commit

Permalink
Do not store in LargeObjectCache objects whose sizes align to maxHuge…
Browse files Browse the repository at this point in the history
…Size (#838)

Signed-off-by: Dmitri Mokhov <[email protected]>
  • Loading branch information
dnmokhov authored May 26, 2022
1 parent faaf43c commit 451e76e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tbbmalloc/large_objects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void LargeObjectCache::setHugeSizeThreshold(size_t value)

bool LargeObjectCache::sizeInCacheRange(size_t size)
{
return size <= maxHugeSize && (size <= defaultMaxHugeSize || size >= hugeSizeThreshold);
return size < maxHugeSize && (size <= defaultMaxHugeSize || size >= hugeSizeThreshold);
}

/* ----------------------------------------------------------------------------------------------------- */
Expand Down
6 changes: 6 additions & 0 deletions test/tbbmalloc/test_malloc_whitebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,12 @@ void TestHugeSizeThreshold() {
// Unit testing for scalable_allocation_command
scalable_allocation_mode(TBBMALLOC_SET_HUGE_SIZE_THRESHOLD, 56 * MByte);
TestHugeSizeThresholdImpl(loc, 56 * MByte, true);
// Verify that objects whose sizes align to maxHugeSize are not cached.
size_t sz = LargeObjectCache::maxHugeSize;
size_t aligned_sz = LargeObjectCache::alignToBin(sz);
REQUIRE_MESSAGE(sz == aligned_sz, "maxHugeSize should be aligned.");
REQUIRE_MESSAGE(!loc->sizeInCacheRange(sz), "Upper bound sized object shouldn't be cached.");
REQUIRE_MESSAGE(loc->get(sz) == nullptr, "Upper bound sized object shouldn't be cached.");
}

//! \brief \ref error_guessing
Expand Down

0 comments on commit 451e76e

Please sign in to comment.