diff options
author | Aleksandr Dmitriev <alexd.65536@gmail.com> | 2022-06-02 13:29:13 +0300 |
---|---|---|
committer | Aleksandr Dmitriev <alexd.65536@gmail.com> | 2022-06-02 13:29:13 +0300 |
commit | f95390e0bf9496e5d0e09c22c27235618c0e9143 (patch) | |
tree | 5ae9116f7785df4abcf174fe6fc03d1ada425987 | |
parent | b75519947fc4fc1bbc8f4ca309b632fb27c36ad3 (diff) | |
download | ydb-f95390e0bf9496e5d0e09c22c27235618c0e9143.tar.gz |
tcmalloc: background page cache release KIKIMR-15019
ref:3059586391b726b9d917cae60d233cbe9591fc29
-rw-r--r-- | ydb/core/mon_alloc/monitor.cpp | 11 | ||||
-rw-r--r-- | ydb/core/mon_alloc/monitor.h | 2 | ||||
-rw-r--r-- | ydb/core/mon_alloc/tcmalloc.cpp | 34 |
3 files changed, 34 insertions, 13 deletions
diff --git a/ydb/core/mon_alloc/monitor.cpp b/ydb/core/mon_alloc/monitor.cpp index 8afc7852c9..f72e136eb3 100644 --- a/ydb/core/mon_alloc/monitor.cpp +++ b/ydb/core/mon_alloc/monitor.cpp @@ -71,7 +71,8 @@ namespace NKikimr { CounterGroup = group->GetSubgroup("component", "lfalloc_profile"); } - void Update() override { + void Update(TDuration interval) override { + Y_UNUSED(interval); #ifdef PROFILE_MEMORY_ALLOCATIONS int maxTag = 0; int numSizes = 0; @@ -266,7 +267,8 @@ namespace NKikimr { CounterGroup = group->GetSubgroup("component", "ytalloc_profile"); } - void Update() override { + void Update(TDuration interval) override { + Y_UNUSED(interval); #ifdef PROFILE_MEMORY_ALLOCATIONS using namespace NYT::NYTAlloc; @@ -367,7 +369,8 @@ namespace NKikimr { }; struct TFakeAllocMonitor: public IAllocMonitor { - void Update() override { + void Update(TDuration interval) override { + Y_UNUSED(interval); } void Dump(IOutputStream& out, const TString& relPath) override { @@ -483,7 +486,7 @@ namespace NKikimr { } void HandleWakeup(const TActorContext& ctx) noexcept { - AllocMonitor->Update(); + AllocMonitor->Update(Interval); LogMemoryStatsIfNeeded(ctx); ctx.Schedule(Interval, new TEvents::TEvWakeup()); } diff --git a/ydb/core/mon_alloc/monitor.h b/ydb/core/mon_alloc/monitor.h index f6a8404b65..36b167c5e5 100644 --- a/ydb/core/mon_alloc/monitor.h +++ b/ydb/core/mon_alloc/monitor.h @@ -34,7 +34,7 @@ namespace NKikimr { Y_UNUSED(icb); } - virtual void Update() = 0; + virtual void Update(TDuration interval) = 0; virtual void Dump(IOutputStream& out, const TString& relPath) = 0; diff --git a/ydb/core/mon_alloc/tcmalloc.cpp b/ydb/core/mon_alloc/tcmalloc.cpp index ab84c83141..14a5e66833 100644 --- a/ydb/core/mon_alloc/tcmalloc.cpp +++ b/ydb/core/mon_alloc/tcmalloc.cpp @@ -466,28 +466,37 @@ class TTcMallocMonitor : public IAllocMonitor { struct TControls { static constexpr size_t MaxSamplingRate = 4ll << 30; + static constexpr size_t MaxPageCacheTargetSize = 128ll << 30; + static constexpr size_t MaxPageCacheReleaseRate = 128ll << 20; + + static constexpr size_t DefaultPageCacheTargetSize = 512ll << 20; + static constexpr size_t DefaultPageCacheReleaseRate = 8ll << 20; TControlWrapper ProfileSamplingRate; TControlWrapper GuardedSamplingRate; - TControlWrapper BackgroundReleaseRate; TControlWrapper MemoryLimit; + TControlWrapper PageCacheTargetSize; + TControlWrapper PageCacheReleaseRate; TControls() : ProfileSamplingRate(tcmalloc::MallocExtension::GetProfileSamplingRate(), 64 << 10, MaxSamplingRate) , GuardedSamplingRate(MaxSamplingRate, 64 << 10, MaxSamplingRate) - , BackgroundReleaseRate(0, - 0, 64 << 20) , MemoryLimit(0, 0, std::numeric_limits<i64>::max()) + , PageCacheTargetSize(DefaultPageCacheTargetSize, + 0, MaxPageCacheTargetSize) + , PageCacheReleaseRate(DefaultPageCacheReleaseRate, + 0, MaxPageCacheReleaseRate) {} void Register(TIntrusivePtr<TControlBoard> icb) { icb->RegisterSharedControl(ProfileSamplingRate, "TCMallocControls.ProfileSamplingRate"); icb->RegisterSharedControl(GuardedSamplingRate, "TCMallocControls.GuardedSamplingRate"); - icb->RegisterSharedControl(BackgroundReleaseRate, "TCMallocControls.BackgroundReleaseRate"); icb->RegisterSharedControl(MemoryLimit, "TCMallocControls.MemoryLimit"); + icb->RegisterSharedControl(PageCacheTargetSize, "TCMallocControls.PageCacheTargetSize"); + icb->RegisterSharedControl(PageCacheReleaseRate, "TCMallocControls.PageCacheReleaseRate"); } }; TControls Controls; @@ -544,9 +553,6 @@ private: } tcmalloc::MallocExtension::SetGuardedSamplingRate(Controls.GuardedSamplingRate); - tcmalloc::MallocExtension::BytesPerSecond rate{(size_t)Controls.BackgroundReleaseRate}; - tcmalloc::MallocExtension::SetBackgroundReleaseRate(rate); - tcmalloc::MallocExtension::MemoryLimit limit; limit.hard = false; limit.limit = Controls.MemoryLimit ? @@ -554,6 +560,17 @@ private: tcmalloc::MallocExtension::SetMemoryLimit(limit); } + void ReleaseMemoryIfNecessary(TDuration interval) { + auto properties = tcmalloc::MallocExtension::GetProperties(); + i64 pageHeapSize = GetProperty(properties, "tcmalloc.page_heap_free"); + if (pageHeapSize > Controls.PageCacheTargetSize) { + auto excess = (ui64)(pageHeapSize - Controls.PageCacheTargetSize); + auto releaseLimit = (ui64)(Controls.PageCacheReleaseRate * interval.Seconds()); + tcmalloc::MallocExtension::ReleaseMemoryToSystem( + std::min(excess, releaseLimit)); + } + } + void DumpCurrent(IOutputStream& out, tcmalloc::ProfileType type, size_t stackCountLimit = 256, size_t sampleCountLimit = 1024, bool forLog = false) { @@ -669,9 +686,10 @@ public: Controls.Register(icb); } - void Update() override { + void Update(TDuration interval) override { UpdateCounters(); UpdateControls(); + ReleaseMemoryIfNecessary(interval); } void Dump(IOutputStream& out, const TString& relPath) override { |