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

[wasm] stop using mmap/munmap #108512

Merged
merged 6 commits into from
Oct 24, 2024

Conversation

pavelsavara
Copy link
Member

@pavelsavara pavelsavara commented Oct 3, 2024

Contributes to #108510
Fixes #107215

Context

  • sgen GC is using mono_valloc -> mmap on all other platforms.
  • mmap emulator in emscripten and wasi-libc doens't implement partial munmap
    • It's implemented on top of malloc rather than on top of sbrk.
    • It has large alignment overhead and no added value.
  • We have our own implementation of custom mmap
    • which can do partial munmap
    • but it never releases pages back to malloc pool.
  • wasm could only grow, we can't return pages to OS/browser
  • wasm32 adress space is rather small and could get fragmented easily

Changes

  • set MS_BLOCK_ALLOC_NUM to 1 which prevents sgen from doing partial mono_vfree
  • set LOCK_FREE_ALLOC_SB_MAX_SIZE to 16384 * 32 to compensate for above
  • sgen_los_memory_usage_total is accounting for alignment
  • implement mono_vfree using dlfree
  • implement mono_valloc_aligned and mono_valloc using posix_memalign
    • emscripten sys_alloc implementation will stitch last segment to new memory allocated via sbrk
  • avoids emscripten mmap which always calls memset to zero the memory
    • this PR brings optimization that new pages which are received from sbrk don't need that.
    • also some calls to mono_valloc pass MONO_MMAP_NOZERO
  • removes mono-wasm-pagemgr.c and wasm-mmap option

TODO

  • measure startup performance

image

@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-GC-mono os-browser Browser variant of arch-wasm labels Oct 3, 2024
@pavelsavara pavelsavara added this to the 10.0.0 milestone Oct 3, 2024
@pavelsavara pavelsavara self-assigned this Oct 3, 2024
@pavelsavara pavelsavara force-pushed the browser_page_leak_repro branch from 0d68ed9 to 779fbac Compare October 8, 2024 16:03
@pavelsavara
Copy link
Member Author

@radekdoulik could you please run startup benchmark on this PR ? Many thanks

@radekdoulik
Copy link
Member

there are visible regressions in json on firefox. I will schedule the updated commit to have another measurement at hand

@radekdoulik
Copy link
Member

the commit 5070e99 is measured and visible in the perf tool
Screenshot 2024-10-21 at 15 16 32

@pavelsavara
Copy link
Member Author

/ba-g all CI issues are known

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-wasm WebAssembly architecture area-GC-mono os-browser Browser variant of arch-wasm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[wasm] New failure condition introduced by anonymous mmap implementation
4 participants