Skip to content

Use __heap_base by dlmalloc - #114

Merged
sunfishcode merged 10 commits into
WebAssembly:masterfrom
mikevoronov:dlmalloc_heap_base
Nov 5, 2019
Merged

Use __heap_base by dlmalloc#114
sunfishcode merged 10 commits into
WebAssembly:masterfrom
mikevoronov:dlmalloc_heap_base

Conversation

@mikevoronov

@mikevoronov mikevoronov commented Oct 19, 2019

Copy link
Copy Markdown
Contributor

Force dlmalloc to use free memory between __heap_base and initial. Some details described here.

Comment thread dlmalloc/src/malloc.c
Comment thread dlmalloc/src/malloc.c Outdated
Comment thread dlmalloc/src/malloc.c
if (!is_initialized(gm)) {
try_init_allocator();
}
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it work to call this from within init_mparams instead? That way it'd get called for all entrypoints, not just malloc.

In that case, it shouldn't do ensure_initialization itself, but just do its work after init_mparams has done its work.

@mikevoronov mikevoronov Oct 24, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I've though about it, but there are some clues:

  1. ensure_initialization is used for mspace also (mspace is like arena in ptmalloc for different continuous space of allocations). At now, mspace is disabled, but if someone want to enable it, there will some unobvious problems. And it is logically incorrect.
  2. Currently, ensure_initialization is disabled in dlmalloc, because it is inside #if USE_LOCKS that is also disabled. And it is called into sys_alloc. But for our purpose it is important to have it initialized before main logic of chunk choosing in dlmalloc being called. => in case of ensure_initialization we will need two augmentation (into ensure_initialization and dlmalloc) instead of one in current case.
  3. On the other side this initialization into dlmalloc seems correct, because other entry points (realloc, calloc) in all important CFG paths will call it before any chunk manipulation. The only exception here is free, but it is UB to call free without any previous malloc.

So, yes, it possible to move top chunk initialization into ensure_initialization, but it seems that it is better leave it as now.

What do you think?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into that! I think what you have right now looks like a reasonable approach then.

Comment thread dlmalloc/src/malloc.c Outdated
@sunfishcode

Copy link
Copy Markdown
Member

Merging; thanks for implementing this!

@sunfishcode
sunfishcode merged commit a214f1c into WebAssembly:master Nov 5, 2019
@mikevoronov

mikevoronov commented Nov 5, 2019

Copy link
Copy Markdown
Contributor Author

And mimalloc is on the way :)

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

Successfully merging this pull request may close these issues.

3 participants