-
Notifications
You must be signed in to change notification settings - Fork 49
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
Allow heap to start not at a page boundary #88
Comments
Interesting! I think in theory it should be possible. There is a global variable provided by LLD call this works for meextern "C" {
static __heap_base: usize;
}
#[no_mangle]
pub extern "C" fn get_heap_base() -> *const () {
unsafe { &__heap_base as *const _ as *const () }
} Then, I think it might be fine, if we return a not full page from the first call to In anycase, I think @fitzgen would know better here. |
I tried hooking up Then, as long as
This is going to be very prone to hard-to-debug stack overflows, so beware. |
Motivation
We're trying to build an application where WASM is used to run "microfunctions", small stateless functions that can be written once in Rust and then ported via WASM to run in a variety of runtimes. A WASM Memory may be built once and then used again and again for multiple microfunction invocations. The buffers backing the WASM Memories would be owned and destroyed by the host environment.
One problem we're running into is that the WASM Memories, at 64 KiB page sizes, are unsuitable for scaling to dozens of microfunctions. It seems unlikely that the WASM spec would ever allow smaller page sizes, so the best alternative would be to guarantee that each microfunction fits within one page.
We've managed to get the Rust call stack and static memory to fit in a small chunk of linear memory, such that most of the first page is empty. However, per #61, wee_alloc seems to always add a new page for its heap, with no option to re-use empty space in the existing linear memory space.
Proposed Solution
Allow wee_alloc to set the head of its heap to an arbitrary location. The location could be provided by a Global, for example. If wee_alloc runs out of space in that initial block (between the start position and the current memory size), then it can allocate more pages as usual.
Alternatives
Additional Context
The project is called OmnICU. We're hoping to share more details soon. For now, you can track some of our work at https://github.com/i18n-concept/rust-discuss
CC @hagbard @nciric @echeran
The text was updated successfully, but these errors were encountered: