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

Specify default options at compile time #945

Open
mpoeter opened this issue Oct 11, 2024 · 5 comments
Open

Specify default options at compile time #945

mpoeter opened this issue Oct 11, 2024 · 5 comments

Comments

@mpoeter
Copy link

mpoeter commented Oct 11, 2024

Is there a way to specify the default values for the options during compile time? From what I have seen in the code so far this does not seem to be the case. In particular we are concerned about the default value of arena_reserve because we have seen some OOM issues during the first tests.

Background: we are thinking about using mimalloc statically linked into a shared library which itself is used by some Java application. If we are setting the options at runtime after the library has been loaded it is probably too late.

@daanx
Copy link
Collaborator

daanx commented Oct 11, 2024

Hi Manuel, hope you are doing well. In the src/options.c you can compile in the default options like arena_reserve .

Aside: Normally though, the memory for such arena is only "reserved", not "committed" yet so it should not lead to an OOM even though it reserve 1GiB at a time. This is controlled by arena_eager_commit which is by default 2 meaning it only eagerly commits the arena memory on OS's with overcommit (which is I think only Linux ). Maybe I made a wrong assumption here?

@mpoeter
Copy link
Author

mpoeter commented Oct 14, 2024

Hi Daan! All good, thanks for asking. :) I guess I wasn't clear enough. I would like to be able to change some options before mimalloc is initialized, but if possible without changing the mimalloc source code. Changing the default parameters just seem the obvious approach, but I would also take any other solution. Most importantly, we prefer to not have to change 3rdParty code (which includes mimalloc).

Regarding arena size and reserve/commit - ATM it is just a guess that the arena size is causing the OOM issues - we are still investigating.

@daanx
Copy link
Collaborator

daanx commented Oct 21, 2024

Ah I see. There are some options that are read before user code can set them -- it'll still work from environment variables but that is probably not what you want. We could add some pre-processor definitions here for the defaults of those options that may be needed early in mimalloc -- like the MIMALLOC_ARENA_RESERVE. Would that work for you?

I guess the compile time options would be: eager_commit, arena_eager_commit, arena_reserve, allow_large_os_pages, and maybe reserve_huge_os_pages and reserve_os_memory.

daanx added a commit that referenced this issue Oct 21, 2024
@daanx
Copy link
Collaborator

daanx commented Oct 21, 2024

I pushed an update to dev and dev-slice that let you set extra c definitions with cmake ../.. -DMI_EXTRA_CPPDEFS=MI_ARENA_RESERVE=128*1024L for example. Let me know if this would work for you.

@mpoeter
Copy link
Author

mpoeter commented Oct 24, 2024

Yes, I think that should work - thank you!

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