-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[wasm] use sbrk instead of emscripten mmap or malloc when loading bytes into heap #100106
Conversation
Tagging subscribers to 'arch-wasm': @lewing |
/azp run runtime |
Azure Pipelines successfully started running 1 pipeline(s). |
As suspected it looks like mono_vfree does need to work on wasm, even though there's not really much point in handing pages back (the heap can't ever shrink and there's no wasm equivalent of MADV_DONTNEED). |
It is expected that the |
During startup malloc == mmap EDIT: And looking at another profile, |
Experimenting with reconfiguring dlmalloc on wasm to use sbrk instead of emscripten mmap/munmap, since they're fake. |
Since we determined that we shouldn't be using dlmalloc at all, removing the dlmalloc change. It did work, though. |
…avoid the overhead of emscripten's mmap HACK: Use sbrk instead of mmap to allocate wasm pages, to skip memset. Disable vfree. Fix build Revert mmap experiment
This reverts commit 0024b82.
I can see
|
…es into heap (dotnet#100106) Use sbrk to allocate persistent space for large load_bytes_into_heap calls to avoid the startup overhead of emscripten's malloc and memset for the new space
Emscripten's implementations of
mmap
andmalloc
have a lot of overhead, particularly time spent callingmemset
to zero brand new pages it got by growing the heap. During startup we lose a lot of time to this, because we have to reserve space for things like the sgen card tables and the contents of all our dll files (they live in the heap for metadata decoding).This PR tries using
sbrk
instead in the hot paths for improved startup, and based on my measurements, it makes most of the time spent inmemset
go away. It's theoretically a breaking change though since someone could have been relying on the ability to_free
the result ofmono_wasm_load_bytes_into_heap
'd preloaded assets, and our code might be relying on the ability to release pages to the "OS" in wasm?EDIT: PR updated to not replace all our uses of mmap, and only replace
load_bytes_into_heap
for now - the rest of them will take more work to replace.