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
25 changes: 14 additions & 11 deletions src/Common/CurrentMemoryTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,22 @@ AllocationTrace CurrentMemoryTracker::allocImpl(Int64 size, bool throw_if_memory
{
if (current_thread)
{
Int64 will_be = current_thread->untracked_memory + size;

if (will_be > current_thread->untracked_memory_limit)
Int64 previous_untracked_memory = current_thread->untracked_memory;
current_thread->untracked_memory += size;
if (current_thread->untracked_memory > current_thread->untracked_memory_limit)
{
auto res = memory_tracker->allocImpl(will_be, throw_if_memory_exceeded);
Int64 current_untracked_memory = current_thread->untracked_memory;
current_thread->untracked_memory = 0;
return res;
}
else
{
/// Update after successful allocations,
/// since failed allocations should not be take into account.
current_thread->untracked_memory = will_be;

try
{
return memory_tracker->allocImpl(current_untracked_memory, throw_if_memory_exceeded);
}
catch (...)
{
current_thread->untracked_memory += previous_untracked_memory;
throw;
}
}
}
/// total_memory_tracker only, ignore untracked_memory
Expand Down
3 changes: 2 additions & 1 deletion src/Common/ThreadStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ void ThreadStatus::flushUntrackedMemory()
if (untracked_memory == 0)
return;

memory_tracker.adjustWithUntrackedMemory(untracked_memory);
Int64 current_untracked_memory = current_thread->untracked_memory;
untracked_memory = 0;
memory_tracker.adjustWithUntrackedMemory(current_untracked_memory);
}

bool ThreadStatus::isQueryCanceled() const
Expand Down
Loading