-
Notifications
You must be signed in to change notification settings - Fork 21
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
Support for reserving address space? #4
Comments
The |
Another thing to consider is that, even with the memory64 proposal as-is, when you |
@lukewagner that really depends on how it is implemented, and on the OS. For example, on Windows, your lowest level allocator would typically acquire memory from the OS with Now that I write this, I am actually doubting the functionality I am suggesting is even possible on Windows.. unless we specify that Though I guess making it part of the spec somehow that "new memory made available thru memory.grow can reasonably be expected to not use physical pages until accessed" would leave slightly more room for people to decide to ask for the maximum memory they may need with no performance consequences. I am guessing the |
Updated the original post, realizing there's a 3rd reason for this being efficient: being able to omit check on pointer bumps. And I think its useful beyond programming language runtimes, in e.g. databases. |
@aardappel Ah hah, good point; I forgot that Windows didn't have overcommit. In that case, then to achieve your bullet one option (which seems like the most attractive option to me), a wasm impl either needs an OS with overcommit or an OS that provides the ability to:
One thing I haven't seen discussed in general is whether we assume the memory64 feature will be available on all hosts (even 32-bit ones, where memory64 would be fairly slow due to it being forced to use emulated |
@lukewagner yup, that's pretty much the only way it would work on Windows. I was actually curious how it would work on Windows and couldn't find a clear example online, so created a prototype that would work thru a page fault handler myself: https://github.com/aardappel/stackalloc/blob/master/stackalloc.cpp Actually difference is that this code uses As for wether 32-bit hardware platforms should support memory64:
|
Ok, verified that committing without guard pages also works on Windows, which allows random access to the reserved address space. So yes, this would allow an engine to use this for |
I wonder if the 2nd option (adding explicit |
Just noting that this feature, if there is interest, is intended for post-MVP. |
(meta-comment: maybe create a "post-mvp" label, and add it for issues like these?) |
We now have a memory-control proposal where this kind of post-MVP feature is being discussed: https://github.com/WebAssembly/memory-control |
With a 64-bit address space, we don't just get to break the 4GB barrier, but potentially new programming techniques become available, in particular techniques that rely on using larger parts of the address space, i.e. the ability to reserve memory that does not cause physical memory to be used unless touched (possible on native platforms with
mmap
orVirtualAlloc
).This is particularly useful in working with large data sets, being able to reserve large arrays, and being able to work with them and:
realloc
/memcpy
as it grows.This can be particularly useful for implementing programming languages, that like to manage the implemented language's objects in a single contiguous blocks, and for whom the above 2 downsides of
realloc
would be prohibitive.Efficient coroutine implementations may rely on it.
I can see it also useful for databases, larger caches etc.
We already have
memory.grow
that can extend memory withoutrealloc
, but that only allows one such large array, and assumes we have complete control over the allocator and other runtime code that may be using memory, which may be impractical.Question is, how could we allow for this functionality?
mmap
underneath for all Wasm memory, which may be unpractical.There is also the question to what extend memory reserved with
mmap
can typically fail after being reserved, which to my knowledge it won't if not called withMAP_NORESERVE
, but I'm no expert.memory.reserve
, which would guarantee address space above the limit thatmemory.grow
has been called. The limit established bymemory.grow
would all be committed memory, and above that, uncommitted until touched. This would also be helpful in the case that reserving can fail and/or not all implementations want to support it (ifmemory.reserve
fails, the program can fall back on a different memory strategy).mmap
like instruction. That is likely unpractical since we may not want to have to deal with "holes" in our memories.I realize browsers may be hesitant to hand out larger parts of address space, but I feel this feature could be important in the future, or for non-browser environments.
@binji @jakobkummerow @sunfishcode
The text was updated successfully, but these errors were encountered: