Skip to content
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

memfd: Reduce some syscalls in the on-demand case #3757

Merged
merged 3 commits into from
Feb 2, 2022

Conversation

alexcrichton
Copy link
Member

This tweaks the internal organization of the MemFdSlot to avoid some
syscalls in the default case as well as opportunistically in the pooling
case. The two cases added here are:

  • A MemFdSlot is now created with a specified initial size. For
    pooling this is 0 but for the on-demand case this can be non-zero.

  • When instantiate is called with no prior image and the sizes match
    (as will be the case for on-demand allocation) then mprotect is
    skipped entirely.

  • In the clear_and_remain-ready case the mprotect is skipped if the
    heap wasn't grown at all.

This should avoid ever using mprotect unnecessarily and makes the
ranges we mprotect a bit smaller as well.

This tweaks the internal organization of the `MemFdSlot` to avoid some
syscalls in the default case as well as opportunistically in the pooling
case. The two cases added here are:

* A `MemFdSlot` is now created with a specified initial size. For
  pooling this is 0 but for the on-demand case this can be non-zero.

* When `instantiate` is called with no prior image and the sizes match
  (as will be the case for on-demand allocation) then `mprotect` is
  skipped entirely.

* In the `clear_and_remain-ready` case the `mprotect` is skipped if the
  heap wasn't grown at all.

This should avoid ever using `mprotect` unnecessarily and makes the
ranges we `mprotect` a bit smaller as well.
@alexcrichton alexcrichton requested a review from cfallin February 2, 2022 21:09
Copy link
Member

@cfallin cfallin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks for these optimizations!

crates/runtime/src/memfd.rs Outdated Show resolved Hide resolved
@alexcrichton alexcrichton merged commit 8ed79c8 into bytecodealliance:main Feb 2, 2022
@alexcrichton alexcrichton deleted the less-mprotect branch February 2, 2022 22:09
mpardesh pushed a commit to avanhatt/wasmtime that referenced this pull request Mar 17, 2022
)

* memfd: Reduce some syscalls in the on-demand case

This tweaks the internal organization of the `MemFdSlot` to avoid some
syscalls in the default case as well as opportunistically in the pooling
case. The two cases added here are:

* A `MemFdSlot` is now created with a specified initial size. For
  pooling this is 0 but for the on-demand case this can be non-zero.

* When `instantiate` is called with no prior image and the sizes match
  (as will be the case for on-demand allocation) then `mprotect` is
  skipped entirely.

* In the `clear_and_remain-ready` case the `mprotect` is skipped if the
  heap wasn't grown at all.

This should avoid ever using `mprotect` unnecessarily and makes the
ranges we `mprotect` a bit smaller as well.

* Review comments

* Tweak allow to apply to whole crate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants