diff --git a/src/tbbmalloc/large_objects.cpp b/src/tbbmalloc/large_objects.cpp index 6994813df7..59e1177ef6 100644 --- a/src/tbbmalloc/large_objects.cpp +++ b/src/tbbmalloc/large_objects.cpp @@ -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); } /* ----------------------------------------------------------------------------------------------------- */ diff --git a/test/tbbmalloc/test_malloc_whitebox.cpp b/test/tbbmalloc/test_malloc_whitebox.cpp index 78a56c57a2..78a7a3acdc 100644 --- a/test/tbbmalloc/test_malloc_whitebox.cpp +++ b/test/tbbmalloc/test_malloc_whitebox.cpp @@ -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