-
-
Notifications
You must be signed in to change notification settings - Fork 656
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
feat: lowMemoryLimit
can accept more than 1 page value
#2857
Conversation
What's the use case for this? |
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. |
Does this do anything that |
maximumMemory is in 64kB size, but lowMemoryLimit is 16B size. But I agree we may can unify them. |
Hmm, I think I'm confused. If you have more than 64 KiB of memory on your device, wouldn't 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. Some background: |
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 don't know the intricacies of TLSF and --lowMemoryLimit
. @dcodeIO is better suited to handle this.
Co-authored-by: CountBleck <[email protected]>
let end = <usize>endU64; | ||
if (ASC_LOW_MEMORY_LIMIT) { | ||
end = <u64>ASC_LOW_MEMORY_LIMIT; | ||
if (start > ASC_LOW_MEMORY_LIMIT) unreachable(); | ||
} |
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.
@HerrCai0907 would this work? Also, what's the background behind overwriting endU64
?
let end = <usize>endU64; | |
if (ASC_LOW_MEMORY_LIMIT) { | |
end = <u64>ASC_LOW_MEMORY_LIMIT; | |
if (start > ASC_LOW_MEMORY_LIMIT) unreachable(); | |
} | |
if (ASC_LOW_MEMORY_LIMIT) endU64 = ASC_LOW_MEMORY_LIMIT; | |
let end = <usize>endU64; |
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 original implement is u32, but huge memory will cause u32 overflow and failed the later assert.
I don't want to mix the debug assert (it should not happen) and oom (it may happen).
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 don't see how that overflow could happen. Memories larger than 4 GiB only exist when using memory64, and in that case, usize
would be equivalent to u64
, not u32
(so no overflow could take place).
Also, about separating those assertions, you can just change the if (DEBUG)
on the next line to if (ASC_LOW_MEMORY_LIMIT || DEBUG)
.
One last thing: can't ASC_LOW_MEMORY_LIMIT
be larger than the current memory size in bytes? An instance could start with a memory of 2 pages, but ASC_LOW_MEMORY_LIMIT
could be set to 224 KiB (3 and a half pages). In initialize
and computeSize
, addMemory
is called with an endU64
argument of memory.size() << 16
, which is the number of bytes available to the instance (if we assume every page has been committed). However, with this change, the value of end
is changed in addMemory
from the given value (memory.size() << 16
) to ASC_LOW_MEMORY_LIMIT
. While this wouldn't have been a problem before, since previously this was only supposed to work with amounts smaller than 1 page, ASC_LOW_MEMORY_LIMIT
could be larger than memory.size() << 16
, and that could lead to addMemory
adding memory that the instance doesn't have yet (and in turn, cause a crash due to an OOB memory access when someone tries to allocate there).
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 key point is 4gb, it will overflow to zero
…emblyscript into support-max-szie
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! |
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.