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

limit process total memory #730

Closed
rtttech opened this issue Apr 16, 2023 · 3 comments
Closed

limit process total memory #730

rtttech opened this issue Apr 16, 2023 · 3 comments

Comments

@rtttech
Copy link

rtttech commented Apr 16, 2023

I need to limit the total memory of my program, does mimalloc support this feature?

@epoupon
Copy link

epoupon commented Apr 16, 2023

Note that you can also use ulimit to limit the memory of your process (and you can also tweak the kernel in order to prevent overcommit)

@daanx
Copy link
Collaborator

daanx commented Apr 17, 2023

I also think that ulimit is best for processes.
However, if you want, you can have various options in mimalloc as well:

  • use MIMALLOC_RESERVE_OS_MEMORY=1GiB to reserve memory, and also MIMALLOC_LIMIT_OS_ALLOC=1 to not allow further OS allocation. (you can set this programmatically too at the start of your program using mi_option_set and mi_reserve_os_memory).
  • use mi_reserve_os_memory_ex to reserve an exclusive arena, and then create per thread a heap with mi_heap_new_in_arena and set it as the default heap (with mi_heap_set_default) -- such heaps will only use memory in the reserved arena. This is used in Koka to have a compressed 32-bit heap by not initially committing the reserved arena (so it reserves address space but commits on demand).

Hope this helps, -- daan

@rtttech
Copy link
Author

rtttech commented Apr 18, 2023

Our application runs on windows, linux, android, and other limited env, and has disk file cache which can been freed when total memory reach the up limit. @daanx @epoupon

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