assemblyscript icon indicating copy to clipboard operation
assemblyscript copied to clipboard

feat: `lowMemoryLimit` can accept more than 1 page value

Open HerrCai0907 opened this issue 1 year ago • 6 comments

The original lowMemoryLimit only support memory less than 64kB (1 wasm page). This PR wants to extend the function of lowMemoryLimit to support more than 64kB memory limitation.

HerrCai0907 avatar Jun 24 '24 15:06 HerrCai0907

What's the use case for this?

CountBleck avatar Jun 24 '24 16:06 CountBleck

In high performance embedded device which has larger RAM than the traditional embedded device but not too much (>1M). In this case, 64kB per page is still to much granularity. Then it can use lowMemoryLimit to control the memory usage.

HerrCai0907 avatar Jun 24 '24 22:06 HerrCai0907

Does this do anything that --maximumMemory doesn't?

CountBleck avatar Jun 24 '24 23:06 CountBleck

Does this do anything that --maximumMemory doesn't?

maximumMemory is in 64kB size, but lowMemoryLimit is 16B size. But I agree we may can unify them.

HerrCai0907 avatar Jun 25 '24 01:06 HerrCai0907

Hmm, I think I'm confused. If you have more than 64 KiB of memory on your device, wouldn't --maximumMemory work?

Or are you restricted to an amount of memory that's not a multiple of 64 KiB (for instance, 68 KiB, 123 KiB, etc.)?

CountBleck avatar Jun 25 '24 02:06 CountBleck

Or are you restricted to an amount of memory that's not a multiple of 64 KiB (for instance, 68 KiB, 123 KiB, etc.)?

Yes. For example, I have device with 150kB memory but want to run 2 wasm job. It is impossible to split 3 x 64kB linear memory. By this option, each job can use 75kB.

Some background: Lots of runtime use virtual memory which will not commit the linear memory from memory.grow utill it is really used. So the memory.grow will / can success even we don't have so many physical memory. When WASM want to write some data in linear memory, it will commit it and make it writable. But AS's allocator will write information at the end of linear memory, which will make runtime commit the whole linear memory. Then when runtime wants to commit the memory, it will trigger OOM and be killed.

HerrCai0907 avatar Jun 25 '24 03:06 HerrCai0907

This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!

github-actions[bot] avatar Aug 25 '24 23:08 github-actions[bot]