aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-12-25 00:18:35 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-12-25 00:34:50 +0300
commit51158be0406575d66f3d630816647d4660973b94 (patch)
tree3b48933d393fc6e754970430c99a99d53f8c1552
parent190164b5ff7a9995db5b1627d320c84d8928e800 (diff)
downloadydb-51158be0406575d66f3d630816647d4660973b94.tar.gz
Intermediate changes
commit_hash:490f1b4698188633a21ca14677e4c779098aa72d
-rw-r--r--yt/yt/core/misc/concurrent_cache-inl.h11
-rw-r--r--yt/yt/core/misc/concurrent_cache.h4
2 files changed, 10 insertions, 5 deletions
diff --git a/yt/yt/core/misc/concurrent_cache-inl.h b/yt/yt/core/misc/concurrent_cache-inl.h
index 614b5ef329..9419262ce4 100644
--- a/yt/yt/core/misc/concurrent_cache-inl.h
+++ b/yt/yt/core/misc/concurrent_cache-inl.h
@@ -17,12 +17,14 @@ struct TConcurrentCache<T>::TLookupTable final
static constexpr bool EnableHazard = true;
const size_t Capacity;
+ const TMemoryUsageTrackerGuard MemoryUsageGuard;
std::atomic<size_t> Size = 0;
TAtomicPtr<TLookupTable> Next;
- explicit TLookupTable(size_t capacity)
+ TLookupTable(size_t capacity, IMemoryUsageTrackerPtr memoryUsageTracker)
: THashTable(capacity)
, Capacity(capacity)
+ , MemoryUsageGuard(TMemoryUsageTrackerGuard::Acquire(std::move(memoryUsageTracker), THashTable::GetByteSize()))
{ }
typename THashTable::TItemRef Insert(TValuePtr item)
@@ -46,7 +48,7 @@ TConcurrentCache<T>::RenewTable(const TIntrusivePtr<TLookupTable>& head, size_t
}
// Rotate lookup table.
- auto newHead = New<TLookupTable>(capacity);
+ auto newHead = New<TLookupTable>(capacity, MemoryUsageTracker_);
newHead->Next = head;
if (Head_.SwapIfCompare(head, newHead)) {
@@ -63,9 +65,10 @@ TConcurrentCache<T>::RenewTable(const TIntrusivePtr<TLookupTable>& head, size_t
}
template <class T>
-TConcurrentCache<T>::TConcurrentCache(size_t capacity)
+TConcurrentCache<T>::TConcurrentCache(size_t capacity, IMemoryUsageTrackerPtr tracker)
: Capacity_(capacity)
- , Head_(New<TLookupTable>(capacity))
+ , Head_(New<TLookupTable>(capacity, tracker))
+ , MemoryUsageTracker_(tracker)
{
YT_VERIFY(capacity > 0);
}
diff --git a/yt/yt/core/misc/concurrent_cache.h b/yt/yt/core/misc/concurrent_cache.h
index 7f0f52054e..ae5672b967 100644
--- a/yt/yt/core/misc/concurrent_cache.h
+++ b/yt/yt/core/misc/concurrent_cache.h
@@ -3,6 +3,7 @@
#include "public.h"
#include "atomic_ptr.h"
#include "lock_free_hash_table.h"
+#include "memory_usage_tracker.h"
namespace NYT {
@@ -21,7 +22,7 @@ private:
public:
using TValuePtr = TIntrusivePtr<T>;
- explicit TConcurrentCache(size_t maxElementCount);
+ explicit TConcurrentCache(size_t maxElementCount, IMemoryUsageTrackerPtr tracker = nullptr);
~TConcurrentCache();
@@ -96,6 +97,7 @@ public:
private:
std::atomic<size_t> Capacity_;
TAtomicPtr<TLookupTable> Head_;
+ IMemoryUsageTrackerPtr MemoryUsageTracker_;
};