aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/ytalloc
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2024-01-25 19:09:19 +0300
committerbabenko <babenko@yandex-team.com>2024-01-25 20:01:47 +0300
commit3fa3bc3d67f3e77fce7b45a7fc7608ef9a3131bb (patch)
tree8c5059e4aabe5be183a5a0b9fc851d12a086e568 /library/cpp/ytalloc
parent4d0fd29627f04e0419f75981e41efb2015daf093 (diff)
downloadydb-3fa3bc3d67f3e77fce7b45a7fc7608ef9a3131bb.tar.gz
Introduce TEnumIndexedArray as a refurbished version of TEnumIndexedVector
Diffstat (limited to 'library/cpp/ytalloc')
-rw-r--r--library/cpp/ytalloc/api/fallback.cpp18
-rw-r--r--library/cpp/ytalloc/api/ytalloc.h21
-rw-r--r--library/cpp/ytalloc/impl/core-inl.h70
3 files changed, 55 insertions, 54 deletions
diff --git a/library/cpp/ytalloc/api/fallback.cpp b/library/cpp/ytalloc/api/fallback.cpp
index d094cf2e93..d7dca33f88 100644
--- a/library/cpp/ytalloc/api/fallback.cpp
+++ b/library/cpp/ytalloc/api/fallback.cpp
@@ -144,47 +144,47 @@ Y_WEAK void SetEnableMadvisePopulate(bool /*value*/)
////////////////////////////////////////////////////////////////////////////////
-Y_WEAK TEnumIndexedVector<ETotalCounter, ssize_t> GetTotalAllocationCounters()
+Y_WEAK TEnumIndexedArray<ETotalCounter, ssize_t> GetTotalAllocationCounters()
{
return {};
}
-Y_WEAK TEnumIndexedVector<ESmallCounter, ssize_t> GetSmallAllocationCounters()
+Y_WEAK TEnumIndexedArray<ESmallCounter, ssize_t> GetSmallAllocationCounters()
{
return {};
}
-Y_WEAK TEnumIndexedVector<ELargeCounter, ssize_t> GetLargeAllocationCounters()
+Y_WEAK TEnumIndexedArray<ELargeCounter, ssize_t> GetLargeAllocationCounters()
{
return {};
}
-Y_WEAK std::array<TEnumIndexedVector<ESmallArenaCounter, ssize_t>, SmallRankCount> GetSmallArenaAllocationCounters()
+Y_WEAK std::array<TEnumIndexedArray<ESmallArenaCounter, ssize_t>, SmallRankCount> GetSmallArenaAllocationCounters()
{
return {};
}
-Y_WEAK std::array<TEnumIndexedVector<ELargeArenaCounter, ssize_t>, LargeRankCount> GetLargeArenaAllocationCounters()
+Y_WEAK std::array<TEnumIndexedArray<ELargeArenaCounter, ssize_t>, LargeRankCount> GetLargeArenaAllocationCounters()
{
return {};
}
-Y_WEAK TEnumIndexedVector<EHugeCounter, ssize_t> GetHugeAllocationCounters()
+Y_WEAK TEnumIndexedArray<EHugeCounter, ssize_t> GetHugeAllocationCounters()
{
return {};
}
-Y_WEAK TEnumIndexedVector<ESystemCounter, ssize_t> GetSystemAllocationCounters()
+Y_WEAK TEnumIndexedArray<ESystemCounter, ssize_t> GetSystemAllocationCounters()
{
return {};
}
-Y_WEAK TEnumIndexedVector<EUndumpableCounter, ssize_t> GetUndumpableAllocationCounters()
+Y_WEAK TEnumIndexedArray<EUndumpableCounter, ssize_t> GetUndumpableAllocationCounters()
{
return {};
}
-Y_WEAK TEnumIndexedVector<ETimingEventType, TTimingEventCounters> GetTimingEventCounters()
+Y_WEAK TEnumIndexedArray<ETimingEventType, TTimingEventCounters> GetTimingEventCounters()
{
return {};
}
diff --git a/library/cpp/ytalloc/api/ytalloc.h b/library/cpp/ytalloc/api/ytalloc.h
index 219814def2..43ba48852d 100644
--- a/library/cpp/ytalloc/api/ytalloc.h
+++ b/library/cpp/ytalloc/api/ytalloc.h
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <library/cpp/yt/misc/enum.h>
+#include <library/cpp/yt/misc/enum_indexed_array.h>
#include <util/system/types.h>
@@ -289,28 +290,28 @@ DEFINE_ENUM(ETotalCounter,
);
// Returns statistics for all user allocations.
-TEnumIndexedVector<ETotalCounter, ssize_t> GetTotalAllocationCounters();
+TEnumIndexedArray<ETotalCounter, ssize_t> GetTotalAllocationCounters();
// Returns statistics for small allocations; these are included into total statistics.
-TEnumIndexedVector<ESmallCounter, ssize_t> GetSmallAllocationCounters();
+TEnumIndexedArray<ESmallCounter, ssize_t> GetSmallAllocationCounters();
// Returns statistics for large allocations; these are included into total statistics.
-TEnumIndexedVector<ELargeCounter, ssize_t> GetLargeAllocationCounters();
+TEnumIndexedArray<ELargeCounter, ssize_t> GetLargeAllocationCounters();
// Returns per-arena statistics for small allocations; these are included into total statistics.
-std::array<TEnumIndexedVector<ESmallArenaCounter, ssize_t>, SmallRankCount> GetSmallArenaAllocationCounters();
+std::array<TEnumIndexedArray<ESmallArenaCounter, ssize_t>, SmallRankCount> GetSmallArenaAllocationCounters();
// Returns per-arena statistics for large allocations; these are included into total statistics.
-std::array<TEnumIndexedVector<ELargeArenaCounter, ssize_t>, LargeRankCount> GetLargeArenaAllocationCounters();
+std::array<TEnumIndexedArray<ELargeArenaCounter, ssize_t>, LargeRankCount> GetLargeArenaAllocationCounters();
// Returns statistics for huge allocations; these are included into total statistics.
-TEnumIndexedVector<EHugeCounter, ssize_t> GetHugeAllocationCounters();
+TEnumIndexedArray<EHugeCounter, ssize_t> GetHugeAllocationCounters();
// Returns statistics for all system allocations; these are not included into total statistics.
-TEnumIndexedVector<ESystemCounter, ssize_t> GetSystemAllocationCounters();
+TEnumIndexedArray<ESystemCounter, ssize_t> GetSystemAllocationCounters();
// Returns statistics for undumpable allocations.
-TEnumIndexedVector<EUndumpableCounter, ssize_t> GetUndumpableAllocationCounters();
+TEnumIndexedArray<EUndumpableCounter, ssize_t> GetUndumpableAllocationCounters();
DEFINE_ENUM(ETimingEventType,
(Mmap)
@@ -333,7 +334,7 @@ struct TTimingEventCounters
// Returns statistics for timing events happened since start.
// See SetTimingEventThreshold.
-TEnumIndexedVector<ETimingEventType, TTimingEventCounters> GetTimingEventCounters();
+TEnumIndexedArray<ETimingEventType, TTimingEventCounters> GetTimingEventCounters();
////////////////////////////////////////////////////////////////////////////////
@@ -349,7 +350,7 @@ struct TBacktrace
struct TProfiledAllocation
{
TBacktrace Backtrace;
- TEnumIndexedVector<EBasicCounter, ssize_t> Counters;
+ TEnumIndexedArray<EBasicCounter, ssize_t> Counters;
};
// Returns statistics for profiled allocations (available when allocation
diff --git a/library/cpp/ytalloc/impl/core-inl.h b/library/cpp/ytalloc/impl/core-inl.h
index 64e95188f4..ba5128bd8d 100644
--- a/library/cpp/ytalloc/impl/core-inl.h
+++ b/library/cpp/ytalloc/impl/core-inl.h
@@ -940,14 +940,14 @@ class TTimingManager
: public TEventLogManagerBase<TTimingEvent, TTimingManager>
{
public:
- TEnumIndexedVector<ETimingEventType, TTimingEventCounters> GetTimingEventCounters()
+ TEnumIndexedArray<ETimingEventType, TTimingEventCounters> GetTimingEventCounters()
{
auto guard = Guard(EventLock_);
return EventCounters_;
}
private:
- TEnumIndexedVector<ETimingEventType, TTimingEventCounters> EventCounters_;
+ TEnumIndexedArray<ETimingEventType, TTimingEventCounters> EventCounters_;
Y_POD_STATIC_THREAD(bool) DisabledForCurrentThread_;
@@ -1523,13 +1523,13 @@ static_assert(
"Wrong MaxMemoryTag");
template <class TCounter>
-using TUntaggedTotalCounters = TEnumIndexedVector<EBasicCounter, TCounter>;
+using TUntaggedTotalCounters = TEnumIndexedArray<EBasicCounter, TCounter>;
template <class TCounter>
struct TTaggedTotalCounterSet
: public TSystemAllocatable
{
- std::array<TEnumIndexedVector<EBasicCounter, TCounter>, TaggedCounterSetSize> Counters;
+ std::array<TEnumIndexedArray<EBasicCounter, TCounter>, TaggedCounterSetSize> Counters;
};
using TLocalTaggedBasicCounterSet = TTaggedTotalCounterSet<ssize_t>;
@@ -1577,20 +1577,20 @@ struct TTotalCounters
}
};
-using TLocalSystemCounters = TEnumIndexedVector<ESystemCounter, ssize_t>;
-using TGlobalSystemCounters = TEnumIndexedVector<ESystemCounter, std::atomic<ssize_t>>;
+using TLocalSystemCounters = TEnumIndexedArray<ESystemCounter, ssize_t>;
+using TGlobalSystemCounters = TEnumIndexedArray<ESystemCounter, std::atomic<ssize_t>>;
-using TLocalSmallCounters = TEnumIndexedVector<ESmallArenaCounter, ssize_t>;
-using TGlobalSmallCounters = TEnumIndexedVector<ESmallArenaCounter, std::atomic<ssize_t>>;
+using TLocalSmallCounters = TEnumIndexedArray<ESmallArenaCounter, ssize_t>;
+using TGlobalSmallCounters = TEnumIndexedArray<ESmallArenaCounter, std::atomic<ssize_t>>;
-using TLocalLargeCounters = TEnumIndexedVector<ELargeArenaCounter, ssize_t>;
-using TGlobalLargeCounters = TEnumIndexedVector<ELargeArenaCounter, std::atomic<ssize_t>>;
+using TLocalLargeCounters = TEnumIndexedArray<ELargeArenaCounter, ssize_t>;
+using TGlobalLargeCounters = TEnumIndexedArray<ELargeArenaCounter, std::atomic<ssize_t>>;
-using TLocalHugeCounters = TEnumIndexedVector<EHugeCounter, ssize_t>;
-using TGlobalHugeCounters = TEnumIndexedVector<EHugeCounter, std::atomic<ssize_t>>;
+using TLocalHugeCounters = TEnumIndexedArray<EHugeCounter, ssize_t>;
+using TGlobalHugeCounters = TEnumIndexedArray<EHugeCounter, std::atomic<ssize_t>>;
-using TLocalUndumpableCounters = TEnumIndexedVector<EUndumpableCounter, ssize_t>;
-using TGlobalUndumpableCounters = TEnumIndexedVector<EUndumpableCounter, std::atomic<ssize_t>>;
+using TLocalUndumpableCounters = TEnumIndexedArray<EUndumpableCounter, ssize_t>;
+using TGlobalUndumpableCounters = TEnumIndexedArray<EUndumpableCounter, std::atomic<ssize_t>>;
Y_FORCE_INLINE ssize_t LoadCounter(ssize_t counter)
{
@@ -1750,7 +1750,7 @@ struct TThreadState
std::array<bool, SmallRankCount> CachedChunkFull{};
#endif
};
- TEnumIndexedVector<EAllocationKind, TSmallBlobCache> SmallBlobCache;
+ TEnumIndexedArray<EAllocationKind, TSmallBlobCache> SmallBlobCache;
};
struct TThreadStateToRegistryNode
@@ -2227,7 +2227,7 @@ public:
}
// Computes memory usage for a list of tags by aggregating counters across threads.
- void GetTaggedMemoryCounters(const TMemoryTag* tags, size_t count, TEnumIndexedVector<EBasicCounter, ssize_t>* counters)
+ void GetTaggedMemoryCounters(const TMemoryTag* tags, size_t count, TEnumIndexedArray<EBasicCounter, ssize_t>* counters)
{
TMemoryTagGuard guard(NullMemoryTag);
@@ -2260,7 +2260,7 @@ public:
{
TMemoryTagGuard guard(NullMemoryTag);
- std::vector<TEnumIndexedVector<EBasicCounter, ssize_t>> counters;
+ std::vector<TEnumIndexedArray<EBasicCounter, ssize_t>> counters;
counters.resize(count);
GetTaggedMemoryCounters(tags, count, counters.data());
@@ -2269,9 +2269,9 @@ public:
}
}
- TEnumIndexedVector<ETotalCounter, ssize_t> GetTotalAllocationCounters()
+ TEnumIndexedArray<ETotalCounter, ssize_t> GetTotalAllocationCounters()
{
- TEnumIndexedVector<ETotalCounter, ssize_t> result;
+ TEnumIndexedArray<ETotalCounter, ssize_t> result;
auto accumulate = [&] (const auto& counters) {
result[ETotalCounter::BytesAllocated] += LoadCounter(counters[EBasicCounter::BytesAllocated]);
@@ -2312,9 +2312,9 @@ public:
return result;
}
- TEnumIndexedVector<ESmallCounter, ssize_t> GetSmallAllocationCounters()
+ TEnumIndexedArray<ESmallCounter, ssize_t> GetSmallAllocationCounters()
{
- TEnumIndexedVector<ESmallCounter, ssize_t> result;
+ TEnumIndexedArray<ESmallCounter, ssize_t> result;
auto totalCounters = GetTotalAllocationCounters();
result[ESmallCounter::BytesAllocated] = totalCounters[ETotalCounter::BytesAllocated];
@@ -2347,9 +2347,9 @@ public:
return result;
}
- TEnumIndexedVector<ELargeCounter, ssize_t> GetLargeAllocationCounters()
+ TEnumIndexedArray<ELargeCounter, ssize_t> GetLargeAllocationCounters()
{
- TEnumIndexedVector<ELargeCounter, ssize_t> result;
+ TEnumIndexedArray<ELargeCounter, ssize_t> result;
auto largeArenaCounters = GetLargeArenaAllocationCounters();
for (size_t rank = 0; rank < LargeRankCount; ++rank) {
result[ESmallCounter::BytesAllocated] += largeArenaCounters[rank][ELargeArenaCounter::BytesAllocated];
@@ -2826,7 +2826,7 @@ private:
}
};
-TExplicitlyConstructableSingleton<TEnumIndexedVector<EAllocationKind, std::array<TExplicitlyConstructableSingleton<TSmallArenaAllocator>, SmallRankCount>>> SmallArenaAllocators;
+TExplicitlyConstructableSingleton<TEnumIndexedArray<EAllocationKind, std::array<TExplicitlyConstructableSingleton<TSmallArenaAllocator>, SmallRankCount>>> SmallArenaAllocators;
////////////////////////////////////////////////////////////////////////////////
@@ -3023,7 +3023,7 @@ private:
std::array<TShardedFreeList<TChunkGroup>, SmallRankCount> RankToChunkGroups_;
};
-TExplicitlyConstructableSingleton<TEnumIndexedVector<EAllocationKind, TExplicitlyConstructableSingleton<TGlobalSmallChunkCache>>> GlobalSmallChunkCaches;
+TExplicitlyConstructableSingleton<TEnumIndexedArray<EAllocationKind, TExplicitlyConstructableSingleton<TGlobalSmallChunkCache>>> GlobalSmallChunkCaches;
////////////////////////////////////////////////////////////////////////////////
@@ -4750,49 +4750,49 @@ void SetEnableMadvisePopulate(bool value)
ConfigurationManager->SetEnableMadvisePopulate(value);
}
-TEnumIndexedVector<ETotalCounter, ssize_t> GetTotalAllocationCounters()
+TEnumIndexedArray<ETotalCounter, ssize_t> GetTotalAllocationCounters()
{
InitializeGlobals();
return StatisticsManager->GetTotalAllocationCounters();
}
-TEnumIndexedVector<ESystemCounter, ssize_t> GetSystemAllocationCounters()
+TEnumIndexedArray<ESystemCounter, ssize_t> GetSystemAllocationCounters()
{
InitializeGlobals();
return StatisticsManager->GetSystemAllocationCounters();
}
-TEnumIndexedVector<ESystemCounter, ssize_t> GetUndumpableAllocationCounters()
+TEnumIndexedArray<ESystemCounter, ssize_t> GetUndumpableAllocationCounters()
{
InitializeGlobals();
return StatisticsManager->GetUndumpableAllocationCounters();
}
-TEnumIndexedVector<ESmallCounter, ssize_t> GetSmallAllocationCounters()
+TEnumIndexedArray<ESmallCounter, ssize_t> GetSmallAllocationCounters()
{
InitializeGlobals();
return StatisticsManager->GetSmallAllocationCounters();
}
-TEnumIndexedVector<ESmallCounter, ssize_t> GetLargeAllocationCounters()
+TEnumIndexedArray<ESmallCounter, ssize_t> GetLargeAllocationCounters()
{
InitializeGlobals();
return StatisticsManager->GetLargeAllocationCounters();
}
-std::array<TEnumIndexedVector<ESmallArenaCounter, ssize_t>, SmallRankCount> GetSmallArenaAllocationCounters()
+std::array<TEnumIndexedArray<ESmallArenaCounter, ssize_t>, SmallRankCount> GetSmallArenaAllocationCounters()
{
InitializeGlobals();
return StatisticsManager->GetSmallArenaAllocationCounters();
}
-std::array<TEnumIndexedVector<ELargeArenaCounter, ssize_t>, LargeRankCount> GetLargeArenaAllocationCounters()
+std::array<TEnumIndexedArray<ELargeArenaCounter, ssize_t>, LargeRankCount> GetLargeArenaAllocationCounters()
{
InitializeGlobals();
return StatisticsManager->GetLargeArenaAllocationCounters();
}
-TEnumIndexedVector<EHugeCounter, ssize_t> GetHugeAllocationCounters()
+TEnumIndexedArray<EHugeCounter, ssize_t> GetHugeAllocationCounters()
{
InitializeGlobals();
return StatisticsManager->GetHugeAllocationCounters();
@@ -4816,7 +4816,7 @@ std::vector<TProfiledAllocation> GetProfiledAllocationStatistics()
}
tags.push_back(AllocationProfilingUnknownMemoryTag);
- std::vector<TEnumIndexedVector<EBasicCounter, ssize_t>> counters;
+ std::vector<TEnumIndexedArray<EBasicCounter, ssize_t>> counters;
counters.resize(tags.size());
StatisticsManager->GetTaggedMemoryCounters(tags.data(), tags.size(), counters.data());
@@ -4838,7 +4838,7 @@ std::vector<TProfiledAllocation> GetProfiledAllocationStatistics()
return statistics;
}
-TEnumIndexedVector<ETimingEventType, TTimingEventCounters> GetTimingEventCounters()
+TEnumIndexedArray<ETimingEventType, TTimingEventCounters> GetTimingEventCounters()
{
InitializeGlobals();
return TimingManager->GetTimingEventCounters();