Skip to content

Commit d4c9316

Browse files
ts4zmeta-codesync[bot]
authored andcommitted
Suppress benign TSan race in SlabAllocator::getRandomAlloc()
Summary: Add a TSan annotation to the allocSize read in getRandomAlloc(). This sampling function is best-effort: slab headers can transition between allocation classes during slab release/rebalance, but callers validate the sampled item before using it. A racing allocSize read produces at worst an invalid sample (returned as nullptr or rejected by the caller's lookup validation). The same annotation pattern is already used in this file for nearby speculative reads. ___ overriding_review_checks_triggers_an_audit_and_retroactive_review Oncall Short Name: oil Differential Revision: D103780529 fbshipit-source-id: 106a8ee1830e23aee4c18e00e49c684ebcbecaa0
1 parent 3424d26 commit d4c9316

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

cachelib/allocator/memory/SlabAllocator.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@ std::tuple<uint32_t, const void*> SlabAllocator::getRandomAlloc()
472472
XDCHECK_GE(reinterpret_cast<uintptr_t>(memory),
473473
reinterpret_cast<uintptr_t>(slab));
474474

475+
// getRandomAlloc() is best-effort sampling. Slab headers can concurrently
476+
// transition between allocation classes while slab release/rebalance is in
477+
// progress; callers validate the sampled item before using it. A racing
478+
// allocSize read may at worst produce an invalid sample, which is reported as
479+
// nullptr below or rejected by the caller's lookup validation.
480+
folly::annotate_ignore_thread_sanitizer_guard g(__FILE__, __LINE__);
475481
const auto allocSize = header->allocSize;
476482
if (allocSize == 0) {
477483
return std::make_tuple(0, nullptr);

0 commit comments

Comments
 (0)