-
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
feat: on low wasm memory hook #286
Draft
ielashi
wants to merge
12
commits into
master
Choose a base branch
from
ielashi/on_low_wasm_memory
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
4f109b2
feat: on low wasm memory hook
ielashi 5c4c3d9
.
ielashi 071a811
Update spec/index.md
mraszyk d514072
Merge branch 'master' into ielashi/on_low_wasm_memory
mraszyk a261c12
Merge branch 'master' into ielashi/on_low_wasm_memory
mraszyk 5a08b34
Update spec/index.md
dragoljub-duric f4128a1
Update spec/index.md
dragoljub-duric e4d9c82
Change name of the field.
dragoljub-duric 8668d17
Merge branch 'master' into ielashi/on_low_wasm_memory
mraszyk ba6a1fd
Apply suggestions from code review
mraszyk cc4dc5d
formal semantics
mraszyk 31cf9a5
Update spec/index.md
mraszyk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1218,6 +1218,8 @@ In order for a WebAssembly module to be usable as the code for the canister, it | |
|
||
- If it exports a function called `canister_heartbeat`, the function must have type `() -> ()`. | ||
|
||
- If it exports a function called `canister_on_low_wasm_memory`, the function must have type `() -> ()`. | ||
|
||
- If it exports a function called `canister_global_timer`, the function must have type `() -> ()`. | ||
|
||
- If it exports any functions called `canister_update <name>`, `canister_query <name>`, or `canister_composite_query <name>` for some `name`, the functions must have type `() -> ()`. | ||
|
@@ -1271,6 +1273,8 @@ The canister provides entry points which are invoked by the IC under various cir | |
|
||
- The canister may export functions with name `canister_composite_query <name>` and type `() -> ()`. | ||
|
||
- The canister may export functions with name `canister_on_low_wasm_memory` and type `() -> ()`. | ||
mraszyk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- The canister table may contain functions of type `(env : i32) -> ()` which may be used as callbacks for inter-canister calls and composite query methods. | ||
|
||
If the execution of any of these entry points traps for any reason, then all changes to the WebAssembly state, as well as the effect of any externally visible system call (like `ic0.msg_reply`, `ic0.msg_reject`, `ic0.call_perform`), are discarded. For upgrades, this transactional behavior applies to the `canister_pre_upgrade`/`canister_post_upgrade` sequence as a whole. | ||
|
@@ -1348,6 +1352,18 @@ While an implementation will likely try to keep the interval between the value o | |
|
||
::: | ||
|
||
#### On Low Wasm Memory {#on-low-wasm-memory} | ||
|
||
A canister can export a function with the name `canister_on_low_wasm_memory`, which is scheduled whenever the canister's remaining wasm memory size in bytes falls from above a threshold `t` to < `t`. | ||
mraszyk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The threshold `t` can be defined in the [canister's settings](#ic-canister_status) and by default it is set to 0. | ||
|
||
:::note | ||
|
||
While the above function is scheduled immediately once the condition above is triggered, it may not necessarily be executed immediately if it does not have enough cycles. | ||
If the canister gets frozen immediately after the function is scheduled for execution, the function will run once the canister's unfrozen _if_ the canister's wasm memory remains above the threshold `t`. | ||
mraszyk marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This property is not established by the implementation. |
||
|
||
::: | ||
|
||
#### Callbacks | ||
|
||
Callbacks are addressed by their table index (as a proxy for a Wasm `funcref`). | ||
|
@@ -1485,7 +1501,7 @@ The comment after each function lists from where these functions may be invoked: | |
|
||
- `F`: from `canister_inspect_message` | ||
|
||
- `T`: from *system task* (`canister_heartbeat` or `canister_global_timer`) | ||
- `T`: from *system task* (`canister_heartbeat` or `canister_global_timer` or `canister_on_low_wasm_memory`) | ||
mraszyk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- `*` = `I G U RQ NRQ CQ Ry Rt CRy CRt C CC F T` (NB: Not `(start)`) | ||
|
||
|
@@ -2228,6 +2244,8 @@ Indicates various information about the canister. It contains: | |
|
||
- The WASM heap memory limit of the canister in bytes (the value of `0` means that there is no explicit limit). | ||
|
||
- The "low wasm memory" threshold, which is used to determine when the [canister_on_low_wasm_memory](#on-low-wasm-memory) function is executed. | ||
|
||
- A SHA256 hash of the module installed on the canister. This is `null` if the canister is empty. | ||
|
||
- The actual memory usage of the canister. | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This field is not exported by the implementation.