Skip to content
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

tcmalloc is trying to keep everything allocated for longer #215

Open
goyalishant001 opened this issue Dec 10, 2023 · 3 comments
Open

tcmalloc is trying to keep everything allocated for longer #215

goyalishant001 opened this issue Dec 10, 2023 · 3 comments

Comments

@goyalishant001
Copy link

I am working on an application which is reading continuously from network and let's say storing it somewhere. I am reading in say 1 MB chunks again and again. I want the tcmalloc memory of previous iteration to be freed before next read iteration. What I can see now is it takes about ~1 sec for tcmalloc to free the previously allocated memory. Is there any way to tweak this default behaviour of tcmalloc?

@ckennelly
Copy link
Collaborator

You can call MallocExtension::ReleaseMemoryToSystem to speed up the process, but there's some smoothing based on past memory usage.

If another 1MB allocation is going to likely occur, it's faster to keep it cached than to return it to the OS (a syscall) and then reuse it (page faults).

@goyalishant001
Copy link
Author

We want to minimise the memory usage. Say currently 16 chunks of 1 MB are in memory. In next iteration, next 16 chunks are about to come. We want to get that first 16 MB got release before second 16MB is fed into the memory. Is that possible somehow?

@junyer
Copy link
Contributor

junyer commented Dec 11, 2023

I doubt that any answer given here will differ substantially from the answer given on gperftools/gperftools#1465.

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

No branches or pull requests

3 participants