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

mpk: add an example testing the memory limits #7609

Merged
merged 9 commits into from
Dec 2, 2023

Conversation

abrown
Copy link
Contributor

@abrown abrown commented Nov 29, 2023

This change adds an example program showing:

  • how to build a pool-allocated engine that uses MPK
  • the difference in the number of memory slots when creating an engine with MPK versus not

The output could look like:

$ cargo run --example mpk
without MPK:    14591 memory slots      85.5 TiB reserved
with MPK:       218861 memory slots     85.5 TiB reserved
                14.999x more slots per reserved memory

The example program probes exponentially larger memory pools to find the maximum available on the current system. This search is highly dependent on the memory available, the OS limits on VMAs, and various engine configuration parameters. See the example docs for more details.

@abrown
Copy link
Contributor Author

abrown commented Nov 29, 2023

cargo vet --locked should fail here with output like:

$ cargo vet --locked
Vetting Failed!

14 unvetted dependencies:
  bindgen:0.68.1 missing ["safe-to-run"]
  bytesize:1.3.0 missing ["safe-to-run"]
  cexpr:0.6.0 missing ["safe-to-run"]
  clang-sys:1.6.1 missing ["safe-to-run"]
  lazycell:1.3.0 missing ["safe-to-run"]
  libproc:0.14.2 missing ["safe-to-run"]
  mach2:0.4.1 missing ["safe-to-run"]
  minimal-lexical:0.2.1 missing ["safe-to-run"]
  nom:7.1.3 missing ["safe-to-run"]
  peeking_take_while:0.1.2 missing ["safe-to-run"]
  prettyplease:0.2.15 missing ["safe-to-run"]
  proc-maps:0.3.2 missing ["safe-to-run"]
  shlex:1.2.0 missing ["safe-to-run"]
  syn:2.0.32 missing ["safe-to-deploy"]

How do we want to handle this? The two added dependencies are dev-dependencies; should they require a vet? And if so, which kind?

@abrown abrown changed the title mpk: mpk: add an example testing the memory limits Nov 29, 2023
@alexcrichton
Copy link
Member

The bytesize crate looks vet-able relatively easily but looks like proc-maps is a pretty heavyweight dependency pulling in quite a lot. Could that dependency be dropped in favor of parsing /proc/self/maps manually?

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Neat! I like having little example programs like this.

examples/mpk.rs Outdated Show resolved Hide resolved
examples/mpk.rs Outdated Show resolved Hide resolved
@github-actions github-actions bot added wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime labels Nov 29, 2023
Copy link

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "wasmtime:api", "wasmtime:config"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

Copy link

Label Messager: wasmtime:config

It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:

  • If you added a new Config method, you wrote extensive documentation for
    it.

    Our documentation should be of the following form:

    Short, simple summary sentence.
    
    More details. These details can be multiple paragraphs. There should be
    information about not just the method, but its parameters and results as
    well.
    
    Is this method fallible? If so, when can it return an error?
    
    Can this method panic? If so, when does it panic?
    
    # Example
    
    Optional example here.
    
  • If you added a new Config method, or modified an existing one, you
    ensured that this configuration is exercised by the fuzz targets.

    For example, if you expose a new strategy for allocating the next instance
    slot inside the pooling allocator, you should ensure that at least one of our
    fuzz targets exercises that new strategy.

    Often, all that is required of you is to ensure that there is a knob for this
    configuration option in wasmtime_fuzzing::Config (or one
    of its nested structs).

    Rarely, this may require authoring a new fuzz target to specifically test this
    configuration. See our docs on fuzzing for more details.

  • If you are enabling a configuration option by default, make sure that it
    has been fuzzed for at least two weeks before turning it on by default.


To modify this label's message, edit the .github/label-messager/wasmtime-config.md file.

To add new label messages or remove existing label messages, edit the
.github/label-messager.json configuration file.

Learn more.

It is inconvenient to have to construct a `PoolingAllocationConfig` in
order to check if memory protection keys are available. This removes
the unused `&self` restriction.
When double-checking the slab layout calculations it is quite convenient
to see the total slab size. This helps in correlating with mapped
regions.
This adds an example that can be run with `cargo run --example mpk`. Not
only does the example demonstrate how to build a pool-allocated engine
that uses MPK, it performs an exponential search to find the maximum
number of slots the system can support, with and without MPK.
@abrown abrown marked this pull request as ready for review December 1, 2023 00:26
@abrown abrown requested review from a team as code owners December 1, 2023 00:26
@abrown abrown requested review from pchickey and removed request for a team December 1, 2023 00:26
@elliottt elliottt removed the request for review from a team December 1, 2023 18:18
@abrown abrown added this pull request to the merge queue Dec 1, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 1, 2023
@abrown abrown enabled auto-merge December 1, 2023 21:58
@abrown abrown added this pull request to the merge queue Dec 1, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 1, 2023
@abrown abrown enabled auto-merge December 1, 2023 22:54
@abrown abrown added this pull request to the merge queue Dec 1, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Dec 1, 2023
@abrown abrown enabled auto-merge December 2, 2023 00:30
@abrown abrown added this pull request to the merge queue Dec 2, 2023
Merged via the queue into bytecodealliance:main with commit 57efd60 Dec 2, 2023
19 checks passed
@abrown abrown deleted the pku-example2 branch December 2, 2023 01:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasmtime:api Related to the API of the `wasmtime` crate itself wasmtime:config Issues related to the configuration of Wasmtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants