-
Notifications
You must be signed in to change notification settings - Fork 13
Support big/lazy mappings for mmap #77
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
base: main
Are you sure you want to change the base?
Conversation
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.
@gkgoat1
Thank you for the suggestion! And I'm sorry for the late reply.
In the latest implementation, mmap is implemented only for heap areas(for using malloc and so on), so it may be good to implement every memory area and lazy mapping. However, In the recent analysis, I found that address translation (i.e. TranslateVMA) incurs large performance overheads. So, we'll need to be careful about the memory access implementation (Now, I am trying to avoid address translation as much as possible).
So, if you change the process of memory access, please check the performance comparing the latest commit (it is easy to try to execute linpack: examples/benchmarks/linpack).
| return *(uint8_t *) runtime_manager->TranslateVMA(addr); | ||
| uint8_t __remill_read_memory_8(RuntimeManager *g_run_mgr, addr_t addr) { | ||
| uint8_t a; | ||
| g_run_mgr->read(addr, &a); |
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.
Calling g_run_mgr->read or g_run_mgr->write for every memory access may incur performance overhead.
| } | ||
| uint8_t RuntimeManager::get(uint64_t vma_addr) { | ||
| if (vma_addr >= stack_memory->vma) { | ||
| if (stack_memory->other_memory) { |
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.
Probably, the conditional check for other_memory should not be used for general memory access in terms of performances.
| void read(uint64_t p, T *b, size_t c = 1) { | ||
| uint8_t buf[sizeof(T) * c]; | ||
| for (size_t a = 0; a < sizeof(T) * c; a++) | ||
| buf[a] = get(p + a); |
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.
calliing get for every character may incur performance overhead.
| uint8_t buf[sizeof(T) * c]; | ||
| memcpy((void *) buf, (const void *) b, sizeof(T) * c); | ||
| for (size_t a = 0; a < sizeof(T) * c; a++) | ||
| set(p + a, buf[a]); |
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.
Same above (line 94).
This implements lazy-loaded and file-backed mappings for WASI.
TODO: Browser and Native Support.
This should not be merged until I can work those targets out, but I am open to review on the WASI part, to start.