-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
Purge jemalloc arenas in case of high memory usage. #40277
Conversation
b75a00e
to
5b0ff1b
Compare
00725_memory_tracking again :( |
{ | ||
if (free_memory_in_allocator_arenas.exchange(-current_free_memory_in_allocator_arenas)) | ||
{ | ||
mallctl("arena." STRINGIFY(MALLCTL_ARENAS_ALL) ".purge", nullptr, nullptr, nullptr, 0); |
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.
Looks like it definitely deserves some metrics (not suggesting logging because it is memory tracker).
What do you think?
P.S. Now MemoryTracker code looks more and more complicated...
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.
Indeed, should be easy to add.
Now it is more like experimental pr
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.
Now it is more like experimental pr
Well it is merged...
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.
Let's bet how soon it would be rolled back :D
My bet that less then in a week.
|
||
Int64 difference = new_amount - amount; | ||
Int64 difference = rss - free_memory_in_allocator_arenas - amount; | ||
|
||
/// Log only if difference is high. This is for convenience. The threshold is arbitrary. | ||
if (difference >= 1048576 || difference <= -1048576) | ||
LOG_TRACE(log, | ||
"MemoryTracking: was {}, peak {}, will set to {} (RSS), difference: {}", |
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.
Maybe also put free_memory_in_allocator_arenas
value into the log?
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.
No message in the log
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.
Yes, sorry.
Well, this value is still available from system table...
BTW right now one can use the following trick to reduce jemalloc memory fragmentation:
This touches almost every thread, and so jemalloc will purge per-cpu arena. |
{ | ||
amount.store(to, std::memory_order_relaxed); | ||
Int64 new_amount = rss_; // - free_memory_in_allocator_arenas_; |
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.
Looks like the comment is irrelevant already
|
||
Int64 difference = new_amount - amount; | ||
Int64 difference = rss - free_memory_in_allocator_arenas - amount; | ||
|
||
/// Log only if difference is high. This is for convenience. The threshold is arbitrary. | ||
if (difference >= 1048576 || difference <= -1048576) | ||
LOG_TRACE(log, | ||
"MemoryTracking: was {}, peak {}, will set to {} (RSS), difference: {}", |
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.
No message in the log
{ | ||
if (free_memory_in_allocator_arenas.exchange(-current_free_memory_in_allocator_arenas)) | ||
{ | ||
mallctl("arena." STRINGIFY(MALLCTL_ARENAS_ALL) ".purge", nullptr, nullptr, nullptr, 0); |
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.
Now it is more like experimental pr
Well it is merged...
Is it normal that server log is flooded with:
|
#42582 should address this |
Changelog category (leave one):
Another version of #38682
For now, without separate counter for RSS.