Skip to content

Commit 392f55c

Browse files
rlyerlymeta-codesync[bot]
authored andcommitted
Add some logging in ASAN builds
Summary: - Log whether slab poisoning is enabled or disabled - Log if an allocation class size is not a multiple of 8 and may lead to poisoning/unpoisoning imprecision Reviewed By: AlnisM Differential Revision: D109388859 fbshipit-source-id: e9d7f4e129b06880abce449a00b46fb0fbf6f181
1 parent f042f80 commit 392f55c

3 files changed

Lines changed: 26 additions & 0 deletions

File tree

cachelib/allocator/memory/AllocationClass.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ void AllocationClass::checkState() const {
9191
fmt::format("Current allocation slab {} is not in allocated slabs list",
9292
fmt::ptr(currSlab_)));
9393
}
94+
95+
if (slabAlloc_.isAsanPoisoningEnabled() && (allocationSize_ % 8 != 0)) {
96+
XLOGF(WARN,
97+
"Slab ASAN poisoning is enabled but allocation class {} has size {}, "
98+
"which is not a multiple of 8; freed-allocation poisoning will be "
99+
"imprecise at allocation boundaries.",
100+
classId_,
101+
allocationSize_);
102+
}
94103
}
95104

96105
// TODO(stuclar): Add poolId to the metadata to be serialized when cache shuts

cachelib/allocator/memory/SlabAllocator.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ void SlabAllocator::checkState() const {
8181
}
8282
}
8383

84+
void SlabAllocator::logAsanPoisoningStatus() const {
85+
#if FOLLY_SANITIZE_ADDRESS
86+
if (asanPoisoningEnabled_) {
87+
XLOG(INFO, "CacheLib slab ASAN poisoning is ENABLED");
88+
} else {
89+
XLOG(INFO, "CacheLib slab ASAN poisoning is DISABLED");
90+
}
91+
#endif
92+
}
93+
8494
SlabAllocator::~SlabAllocator() {
8595
stopMemoryLocker();
8696

@@ -153,6 +163,8 @@ SlabAllocator::SlabAllocator(void* memoryStart,
153163
XDCHECK(nextSlabAllocation_ != nullptr);
154164
XDCHECK_EQ(reinterpret_cast<uintptr_t>(nextSlabAllocation_),
155165
reinterpret_cast<uintptr_t>(slabMemoryStart_));
166+
167+
logAsanPoisoningStatus();
156168
}
157169

158170
SlabAllocator::SlabAllocator(const serialization::SlabAllocatorObject& object,
@@ -251,6 +263,8 @@ SlabAllocator::SlabAllocator(const serialization::SlabAllocatorObject& object,
251263
asanPoisonMemoryRegion(memoryStart_,
252264
reinterpret_cast<const uint8_t*>(slabMemoryStart_) -
253265
reinterpret_cast<const uint8_t*>(memoryStart_));
266+
267+
logAsanPoisoningStatus();
254268
}
255269

256270
void SlabAllocator::lockMemoryAsync() noexcept {

cachelib/allocator/memory/SlabAllocator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,9 @@ class SlabAllocator {
380380
// @throw std::invalid_argument if the state is invalid.
381381
void checkState() const;
382382

383+
// Logs whether slab ASAN poisoning is active. No-op in non-ASAN builds.
384+
void logAsanPoisoningStatus() const;
385+
383386
// returns first byte after the end of memory region we own.
384387
const Slab* getSlabMemoryEnd() const noexcept {
385388
return reinterpret_cast<Slab*>(reinterpret_cast<uint8_t*>(memoryStart_) +

0 commit comments

Comments
 (0)