New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix memory accounting in case of MEMORY_LIMIT_EXCEEDED errors #40249
Fix memory accounting in case of MEMORY_LIMIT_EXCEEDED errors #40249
Conversation
In case of memory allocation had been failed, it should not be take into account anywhere, otherwise it will report incorrect memory usage for query and in logs. I found this while was digging into OOM in stress tests, and saw memory allocations that had been significantly greater the memory limit (even with overcommit). Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
0673f92
to
8e4c967
Compare
ASTFuzzer: #39991 |
Yeah, I was on it actually (that's why I marked it as draft). |
/// more. It could be useful to enlarge Exception message in rethrow logic. | ||
Int64 tmp = current_thread->untracked_memory; | ||
current_thread->untracked_memory_limit_increase = current_thread->untracked_memory_limit; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KochetovNicolai found and interesting case here - #40424 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But I'm suggesting #40321 anyway
It looks useless nowadays, because operator new cannot throw MEMORY_LIMIT_EXCEEDED today, and so any code that works on Exception is likely safe. Refs: ClickHouse#40249 Refs: ClickHouse#24483 Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Fix memory accounting in case of MEMORY_LIMIT_EXCEEDED errors (previously [peak] memory usage was takes failed allocations into account)
In case of memory allocation had been failed, it should not be take into
account anywhere, otherwise it will report incorrect memory usage for
query and in logs.
I found this while was digging into OOM in stress tests, and saw memory
allocations that had been significantly greater the memory limit (even
with overcommit), where something interesting happened,
consider the query with failed allocation for 1TiB,
but since
ThreadStatus::untracked_memory
still includes it,it will be "freed" in ThreadStatus dtor, however it will not free but allocate,
since
untracked_memory > 0
, and since the code called from dtor,exceptions from MemoryTracker will be locked, and amount/peak will be updated.