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

Disabling tcmalloc cache #1466

Closed
coder-saab001 opened this issue Dec 10, 2023 · 7 comments
Closed

Disabling tcmalloc cache #1466

coder-saab001 opened this issue Dec 10, 2023 · 7 comments

Comments

@coder-saab001
Copy link
Contributor

Hi community, is there is some way to disable the tcmalloc cache totally. We are working on minimising the memory usage of our system.

@alk
Copy link
Contributor

alk commented Dec 10, 2023

Hi. There are no ways to disable cache fully, but there are some knobs that could be used. Look at TCMALLOC_SMALL_BUT_SLOW (this is preprocessor define). You can also tweak down size of cache. And you can also enable aggressive decommit.

Do note however, that based on my experience (but without knowing exactly what is your use-case; so I might be totally wrong), I am guessing you might be fighting symptoms rather than root case. My suspicion is you're facing some sort of memory fragmentation case. And if so then attacking it more directly (rather then potentially crippling malloc performance for your entire program) might be better direction.

@coder-saab001
Copy link
Contributor Author

coder-saab001 commented Dec 10, 2023

Hi @alk. My use case is to minimise the memory utilisation to as low as possible, doesn't matter the performance. If possible, can you guide me with how to tweak down size of cache. I tried

MallocExtension::instance()->SetNumericProperty(
        "tcmalloc.max_total_thread_cache_bytes", 0);

but doesn't helped. Cache is still there.

I tried TCMALLOC_SMALL_BUT_SLOW also, but didn't saw improvement as such.

@alk
Copy link
Contributor

alk commented Dec 10, 2023

Well, consider some other malloc implementation then, if you don't care about performance at all. Ours is trying to balance performance and fragmentation matters with more emphasis on performance.

Aggressive decommit is available via --enable-aggressive-decommit-by-default configure option. As for cache size, that call above should get you to minimum size. The code clips value to kMinThreadCacheSize which appears to be set to 2 megs.

If none of that helps, then this is as much as we can offer you (but do listen to my words, every single indication so far that you're royally misunderstanding the issue you're dealing with)

@alk
Copy link
Contributor

alk commented Dec 10, 2023

Ah, also you may find MallocExtension::MarkThreadIdle potentially useful w.r.t. limiting cache usage (but it will only help in some cases; do check source code if in doubt)

@coder-saab001
Copy link
Contributor Author

coder-saab001 commented Dec 10, 2023

Thanks @alk
Tried but again didn't helped that. This is my tcmalloc consumption right now. Cache is taking too much. We want to mitigate or atleast freed it.
image

@alk
Copy link
Contributor

alk commented Dec 11, 2023

No. Not possible by design. And truly if few megs is so big deal for you, then perhaps consider doing something custom.

@coder-saab001
Copy link
Contributor Author

Thanks @alk . Yeah we had some issue with these few megs also. Just want to confirm if it is possible.

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

2 participants