Skip to content

Commit

Permalink
Merge 25817ce into 50b9d76
Browse files Browse the repository at this point in the history
  • Loading branch information
lll-phill-lll authored May 23, 2024
2 parents 50b9d76 + 25817ce commit 2835e09
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
14 changes: 14 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,18 @@ namespace NYql::NDq {
}
}

void TrySetIncreaseMemoryLimitCallbackWithRSSControl(NKikimr::NMiniKQL::TScopedAlloc* alloc) {
if (CanAllocateExtraMemory) {
alloc->Ref().SetIncreaseMemoryLimitCallback([this, alloc](ui64 limit, ui64 required) {
RequestExtraMemory(required - limit, alloc);
auto currentRSS = NMemInfo::GetMemInfo().RSS;
if (currentRSS > 10_GB) {
alloc->SetMaximumLimitValueReached(true);
}
});
}
}

void TryShrinkMemory(NKikimr::NMiniKQL::TScopedAlloc* alloc) {
if (alloc->GetAllocated() - alloc->GetUsed() > MemoryLimits.MinMemFreeSize) {
alloc->ReleaseFreePages();
Expand Down Expand Up @@ -113,6 +126,7 @@ namespace NYql::NDq {

private:
void RequestExtraMemory(ui64 memory, NKikimr::NMiniKQL::TScopedAlloc* alloc) {
alloc->GetAllocated();
memory = std::max(AlignMemorySizeToMbBoundary(memory), MemoryLimits.MinMemAllocSize);

if (MemoryLimits.MkqlProgramHardMemoryLimit && MkqlMemoryLimit + memory > MemoryLimits.MkqlProgramHardMemoryLimit) {
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

0 comments on commit 2835e09

Please sign in to comment.