Add callback for the soft memory limit handling#270
Add callback for the soft memory limit handling#270abyss7 wants to merge 1 commit intogoogle:masterfrom
Conversation
|
Thanks for the pull request. It's somewhat tricky to support a callback right here, since we're holding For our internal use cases that need to track memory usage, we've had a lot of success with using callbacks on our sampled allocations: It allows the application to track memory usage with about 2MB of error either way and can be done without holding any locks. While we haven't (yet) open-sourced these APIs, is that something that would work for your use case? |
Sounds like a good solution, if these APIs get open-sourced. This pull request emerged from our internal code - we don't collect stats immediately, but fork the process in another thread, stop the parent, and dump any stats inside the child - relying on tcmalloc's heap state shared between processes. We have another patch to make tcmalloc more fork-friendly to supplement our technique - I'm not sure if it was also open-sourced. |
|
As of a62a344, the sampled hook implementation is available (albeit bazel visibility restricted pending having the tests for it up and running). By tracking the sampled allocations and their subsequent deallocations, you can get a fairly good sense of memory demand before it's a problem. |
This feature is useful i.e. to handle large heap allocations, pre-OOM state, or just signal about a certain size of heap.