Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions ydb/library/yql/dq/actors/compute/dq_compute_memory_quota.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#pragma once

#include <util/system/mem_info.h>
#include <ydb/library/services/services.pb.h>
#include <ydb/library/yql/dq/actors/compute/dq_compute_actor.h>
#include <ydb/library/yql/minikql/mkql_alloc.h>
Expand Down Expand Up @@ -55,6 +56,23 @@ namespace NYql::NDq {
}
}

// This callback is created for testing purposes and will be enabled only with spilling.
// Most likely this callback will be removed after KIKIMR-21481.
void TrySetIncreaseMemoryLimitCallbackWithRSSControl(NKikimr::NMiniKQL::TScopedAlloc* alloc) {
if (!CanAllocateExtraMemory) return;
const ui64 limitRSS = std::numeric_limits<ui64>::max();
const ui64 criticalRSSValue = limitRSS / 100 * 80;

alloc->Ref().SetIncreaseMemoryLimitCallback([this, alloc](ui64 limit, ui64 required) {
RequestExtraMemory(required - limit, alloc);

ui64 currentRSS = NMemInfo::GetMemInfo().RSS;
if (currentRSS > criticalRSSValue) {
alloc->SetMaximumLimitValueReached(true);
}
});
}

void TryShrinkMemory(NKikimr::NMiniKQL::TScopedAlloc* alloc) {
if (alloc->GetAllocated() - alloc->GetUsed() > MemoryLimits.MinMemFreeSize) {
alloc->ReleaseFreePages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,11 @@ class TLocalTaskRunnerActor

auto guard = TaskRunner->BindAllocator(MemoryQuota ? TMaybe<ui64>(MemoryQuota->GetMkqlMemoryLimit()) : Nothing());
if (MemoryQuota) {
MemoryQuota->TrySetIncreaseMemoryLimitCallback(guard.GetMutex());
if (settings.GetEnableSpilling()) {
MemoryQuota->TrySetIncreaseMemoryLimitCallbackWithRSSControl(guard.GetMutex());
} else {
MemoryQuota->TrySetIncreaseMemoryLimitCallback(guard.GetMutex());
}
}

TaskRunner->Prepare(settings, ev->Get()->MemoryLimits, *ev->Get()->ExecCtx);
Expand Down
4 changes: 4 additions & 0 deletions ydb/library/yql/minikql/mkql_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ class TScopedAlloc {
Release();
}

void SetMaximumLimitValueReached(bool IsReached) {
MyState_.SetMaximumLimitValueReached(IsReached);
}

private:
const bool InitiallyAcquired_;
TAllocState MyState_;
Expand Down