Skip to content

Call malloc_trim() regularly to improve deallocation behavior #14707

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

Merged
merged 5 commits into from
Jun 7, 2024

Conversation

sfan5
Copy link
Collaborator

@sfan5 sfan5 commented May 26, 2024

adds a workaround which fixes #14645
as I suggested in my comment

To do

This PR is Ready for Review.

How to test

  1. test scenario from the forum post

@siliconsniffer
Copy link
Contributor

siliconsniffer commented May 26, 2024

How can I try this out?
Edit:

  • checked out to this commit
  • compiled it
  • server with mineclonia seems to work fine, ram usage goes down and up as it should

Do you need more info? Video?

@sfan5
Copy link
Collaborator Author

sfan5 commented May 27, 2024

Do you need more info? Video?

No that's fine, thanks for testing.

@Desour
Copy link
Member

Desour commented May 28, 2024

  • How expensive is malloc_trim, for the thread calling it, and for other threads using the heap while it's trimming?
  • If someone uses a different allocator with LD_PRELOAD, we should probably not call malloc_trim. Maybe add a build option and/or an env variable to turn this off.

@sfan5
Copy link
Collaborator Author

sfan5 commented May 28, 2024

How expensive is malloc_trim, for the thread calling it, and for other threads using the heap while it's trimming?

I have no idea. I think this unknown is mitigated by just not calling malloc_trim too often.
FWIW it was good enough for mruby: mruby/mruby#5069

If someone uses a different allocator with LD_PRELOAD, we should probably not call malloc_trim. Maybe add a build option and/or an env variable to turn this off.

I don't agree.
In the worst case we're just calling glibc to trim an empty heap. In the best case the allocator has overriden this to do something else useful (or a no-op).

@sfan5 sfan5 added the 1 approval rule low-risk PR according to Git guidelines label Jun 7, 2024
@sfan5 sfan5 merged commit 7189380 into luanti-org:master Jun 7, 2024
@sfan5 sfan5 deleted the malloctrim branch June 7, 2024 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 approval rule low-risk PR according to Git guidelines Bugfix 🐛 PRs that fix a bug Linux @ Server / Client / Env.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Minetest on Linux (glibc) is not able to give back freed MapBlocks to the OS
4 participants