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

Add malloc_trim #116

Open
waddlesplash opened this issue Aug 17, 2019 · 3 comments
Open

Add malloc_trim #116

waddlesplash opened this issue Aug 17, 2019 · 3 comments
Assignees
Milestone

Comments

@waddlesplash
Copy link
Contributor

http://man7.org/linux/man-pages/man3/malloc_trim.3.html

This is a GNU extension, but it seems a lot of other allocators support it as well. It would be useful to have in e.g. system wide low-memory conditions.

@mjansson mjansson self-assigned this Aug 17, 2019
@mjansson
Copy link
Owner

The question is how aggressive it should be. It can only work on the calling thread cache and possibly the global cache. Should it empty and unmap both, or just the thread cache? Perhaps interpret the pad argument as

If argument is zero - empty and unmap both thread and global cache
If argument is non-zero - empty the thread cache (possibly leaving the number of spans matching the size given) and not touching global cache

@waddlesplash
Copy link
Contributor Author

It can only work on the calling thread cache and possibly the global cache.

Is there no way to (atomically) release the free spans from other caches? Otherwise it would not be very useful on systems like Haiku, where processes usually have 4-6 threads at a minimum, and usually more.

@mjansson
Copy link
Owner

Unfortunately not, a lot o the performance in rpmalloc and similar, like mimalloc and tcmalloc, comes from that the thread heap is known to be touched only by the owning heap (except for the cross-thread deferred free list).

Of course the thread cache lists could be changed to use atomics and sacrifice some performance which would allow a trim method to walk all heaps and release them. I'll think about adding a compile time option for this.

@mjansson mjansson modified the milestones: 1.4.0, Future Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants