-
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] stop using mmap/munmap #108512
base: main
Are you sure you want to change the base?
[wasm] stop using mmap/munmap #108512
Conversation
0d68ed9
to
779fbac
Compare
#else | ||
// WASM doesn't support partial munmap, so we can't free individual blocks | ||
// we use posix_memalign and free the whole block at once | ||
#define MS_BLOCK_ALLOC_NUM 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should investigate whether this will meaningfully regress performance; mwpm caused a benchmark regression that was fairly sizable
@@ -45,11 +45,7 @@ typedef struct { | |||
MonoMemAccountType account_type; | |||
} MonoLockFreeAllocator; | |||
|
|||
#ifdef HOST_WASM | |||
#define LOCK_FREE_ALLOC_SB_MAX_SIZE (mono_opt_wasm_mmap ? 65536 : 16384) | |||
#else | |||
#define LOCK_FREE_ALLOC_SB_MAX_SIZE 16384 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need a solution for the 16 vs 64k problem here since the system page size is still 64kb right now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does sbrk()
page size matter in any way ? Why ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it might be fine with the combination of all the changes you made, but mono_pagesize not agreeing with other sources of page size information feels like a hazard down the road
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what would be the other sources which could conflict ?
#endif | ||
|
||
return saved_pagesize; | ||
return 16384; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should make sure it's actually okay to lie here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will improve the state of things by making pagesize not > the max block size, but the design of sgen is optimized for a base page size in the 4-8K range so that it can start with smaller blocks and then step up to larger blocks. i think with a page size of 16K it will always allocate only large blocks, and that might be bad? i'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can change it down to 4K, I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The natural wasm page size of 64k is spoiled by the fact there is dlmalloc
header around it anyway.
So I think we could choose arbitrary page size and 16K is max on other platforms for sgen.
Right @BrzVlad ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kg not sure if you are talking about other blocks. GC major blocks (for small object allocation) are at least 16k.
I think 16k page size is just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm referring to the comments in the lock free allocator, which is one of the places that was consuming the page size and interacting with mmap. I guess I was under the mistaken assumption that we used the lock free allocator in more places than we do.
@radekdoulik could you please run startup benchmark on this PR ? Many thanks |
if ((flags & MONO_MMAP_NOZERO) == 0) { | ||
memset (res, 0, size); | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this no longer does mono_account_mem
tracking of allocated memory
|
||
mono_account_mem (type, -(ssize_t)length); | ||
|
||
// NOTE: this doesn't implement partial freeing like munmap does |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as above, missing tracking of allocated memory.
Contributes to #108510
Fixes #107215
Context
sgen
GC is usingmono_valloc
->mmap
on all other platforms.mmap
emulator in emscripten andwasi-libc
doens't implement partialmunmap
malloc
rather than on top ofsbrk
.mmap
munmap
malloc
pool.Changes
MS_BLOCK_ALLOC_NUM
to1
which preventssgen
from doing partialmono_vfree
mono_vfree
usingdlfree
mono_valloc_aligned
andmono_valloc
usingposix_memalign
sys_alloc
implementation will stitch last segment to new memory allocated viasbrk
mmap
which always callsmemset
to zero the memorysbrk
don't need that.mono_valloc
passMONO_MMAP_NOZERO
mono-wasm-pagemgr.c
andwasm-mmap
optionTODO
soft-heap-limit
to understanddlmalloc
overhead (vs zero overhead ofmmap
on other systems)