Skip to content

Conversation

@abyss7
Copy link

@abyss7 abyss7 commented Nov 13, 2024

This feature is useful i.e. to handle large heap allocations, pre-OOM state, or just signal about a certain size of heap.

@ckennelly
Copy link
Collaborator

Thanks for the pull request.

It's somewhat tricky to support a callback right here, since we're holding pageheap_lock. We read stats about memory usage under that lock, and that plausibly seems like something a zero-argument callee might need to do.

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?

@abyss7
Copy link
Author

abyss7 commented Nov 29, 2024

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.

@ckennelly
Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants