summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsabdenovch <[email protected]>2025-03-20 12:11:29 +0300
committersabdenovch <[email protected]>2025-03-20 12:28:24 +0300
commitdaa0fae61cb590ee620443fde726dae156c60d4e (patch)
tree8de27e90f77411159108adbd11d3c8007c673b67
parentaa2d8d74de6e524e44eff8d61a0a229dee2fa5df (diff)
Poison lookup cache
* Changelog entry Type: feature Component: dynamic-tables Added poisoning of row-cache for better memory error detection. commit_hash:0c32257fa66b55b4d4059617b64fbfb7f445d664
-rw-r--r--yt/yt/core/misc/slab_allocator.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/yt/yt/core/misc/slab_allocator.cpp b/yt/yt/core/misc/slab_allocator.cpp
index 96cbb895959..3b7d3e043c2 100644
--- a/yt/yt/core/misc/slab_allocator.cpp
+++ b/yt/yt/core/misc/slab_allocator.cpp
@@ -7,6 +7,7 @@
#include <library/cpp/yt/malloc/malloc.h>
#include <library/cpp/yt/memory/memory_usage_tracker.h>
+#include <library/cpp/yt/memory/poison.h>
namespace NYT {
@@ -114,6 +115,7 @@ public:
{
auto* obj = FreeList_.Extract();
if (Y_LIKELY(obj)) {
+ RecycleFreedMemory(TMutableRef(&obj[1], ObjectSize_ - sizeof(TFreeListItem)));
AllocatedItems.Increment();
AliveItems.Update(GetRefCounter(this)->GetRefCount() + 1);
// Fast path.
@@ -127,7 +129,10 @@ public:
{
FreedItems.Increment();
AliveItems.Update(GetRefCounter(this)->GetRefCount() - 1);
- FreeList_.Put(static_cast<TFreeListItem*>(obj));
+ auto* typedPtr = static_cast<TFreeListItem*>(obj);
+ // Poison all memory except the header used for FreeList_.
+ PoisonFreedMemory(TMutableRef(&typedPtr[1], ObjectSize_ - sizeof(TFreeListItem)));
+ FreeList_.Put(typedPtr);
Unref(this);
}
@@ -193,6 +198,7 @@ private:
// Build chain of chunks.
auto objectCount = ObjectCount_;
auto objectSize = ObjectSize_;
+ auto poisonedSize = objectSize - sizeof(TFreeListItem);
YT_VERIFY(objectCount > 0);
YT_VERIFY(objectSize > 0);
@@ -202,6 +208,7 @@ private:
auto* current = reinterpret_cast<TFreeListItem*>(ptr);
ptr += objectSize;
+ PoisonFreedMemory(TMutableRef(&current[1], poisonedSize));
current->Next.store(reinterpret_cast<TFreeListItem*>(ptr), std::memory_order::release);
}
@@ -209,6 +216,7 @@ private:
auto* current = reinterpret_cast<TFreeListItem*>(ptr);
current->Next.store(nullptr, std::memory_order::release);
+ PoisonFreedMemory(TMutableRef(&current[1], poisonedSize));
return {head, current};
}
@@ -254,6 +262,7 @@ private:
// Extract one element.
auto* next = head->Next.load();
FreeList_.Put(next, tail);
+ RecycleFreedMemory(TMutableRef(head, ObjectSize_));
return head;
}
};
@@ -281,6 +290,7 @@ public:
auto itemCount = ++RefCount_;
auto ptr = malloc(allocatedSize);
+ PoisonUninitializedMemory(TMutableRef(ptr, allocatedSize));
auto header = reinterpret_cast<TSizeHeader*>(ptr);
header->Size = allocatedSize;
@@ -296,6 +306,7 @@ public:
ptr = reinterpret_cast<void*>(reinterpret_cast<char*>(ptr) - sizeof(TSizeHeader));
auto allocatedSize = reinterpret_cast<TSizeHeader*>(ptr)->Size;
+ PoisonFreedMemory(TMutableRef(ptr, allocatedSize));
ReleaseMemory(allocatedSize);
free(ptr);
FreedItems.Increment();