feat(deps)!: update to marine runtime with memory limits and wasmtime (#768)

This commit is contained in:
Valery Antopol 2024-01-24 16:16:33 +03:00 committed by GitHub
parent 6c1cb289cc
commit 3375c7a3b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 18 additions and 11 deletions

View File

@ -52,7 +52,7 @@ rkyv = { version = "0.7.43", features = ["strict", "validation", "size_32", "arc
[dev_dependencies] [dev_dependencies]
air-test-utils = { path = "../crates/air-lib/test-utils" } air-test-utils = { path = "../crates/air-lib/test-utils" }
air-testing-framework = { path = "../crates/testing-framework" } air-testing-framework = { path = "../crates/testing-framework" }
fluence-app-service = "0.29.0" fluence-app-service = "0.31.0"
marine-rs-sdk = { version = "0.10.0", features = ["logger"] } marine-rs-sdk = { version = "0.10.0", features = ["logger"] }
borsh = "0.10.3" borsh = "0.10.3"

View File

@ -317,6 +317,7 @@ fn construct_service_config(module_name: impl Into<String>) -> AppServiceConfig
let marine_config = MarineConfig { let marine_config = MarineConfig {
modules_dir: Some(PathBuf::from(module_path)), modules_dir: Some(PathBuf::from(module_path)),
total_memory_limit: None,
modules_config: vec![module_descriptor], modules_config: vec![module_descriptor],
default_modules_config: None, default_modules_config: None,
}; };

View File

@ -19,7 +19,7 @@ air-interpreter-interface = { version = "0.17.1", path = "../../crates/air-lib/i
air-interpreter-sede = { version = "0.1.0", path = "../../crates/air-lib/interpreter-sede" } air-interpreter-sede = { version = "0.1.0", path = "../../crates/air-lib/interpreter-sede" }
air-utils = { version = "0.2.0", path = "../../crates/air-lib/utils" } air-utils = { version = "0.2.0", path = "../../crates/air-lib/utils" }
avm-data-store = { version = "0.7.6", path = "../../crates/data-store" } avm-data-store = { version = "0.7.6", path = "../../crates/data-store" }
marine-runtime = "0.30.0" marine-runtime = "0.32.0"
polyplets = { version = "0.6.0", path = "../../crates/air-lib/polyplets" } polyplets = { version = "0.6.0", path = "../../crates/air-lib/polyplets" }
avm-interface = { version = "0.31.1", path = "../../avm/interface" } avm-interface = { version = "0.31.1", path = "../../avm/interface" }

View File

@ -36,6 +36,8 @@ pub struct AVMRunner {
marine: Marine, marine: Marine,
/// file name of the AIR interpreter .wasm /// file name of the AIR interpreter .wasm
wasm_filename: String, wasm_filename: String,
/// The memory limit provided by constructor
total_memory_limit: Option<u64>,
} }
/// Return statistic of AVM server Wasm module heap footprint. /// Return statistic of AVM server Wasm module heap footprint.
@ -44,25 +46,29 @@ pub struct AVMMemoryStats {
/// Please note that linear memory contains not only heap, but globals, shadow stack and so on. /// Please note that linear memory contains not only heap, but globals, shadow stack and so on.
pub memory_size: usize, pub memory_size: usize,
/// Possibly set max memory size for AVM server. /// Possibly set max memory size for AVM server.
pub max_memory_size: Option<usize>, pub total_memory_limit: Option<u64>,
/// Number of allocations rejected due to memory limit.
/// May be not recorded by some backends in Marine.
pub allocation_rejects: Option<u32>,
} }
impl AVMRunner { impl AVMRunner {
/// Create AVM with the provided config. /// Create AVM with the provided config.
pub fn new( pub fn new(
air_wasm_path: PathBuf, air_wasm_path: PathBuf,
max_heap_size: Option<u64>, total_memory_limit: Option<u64>,
logging_mask: i32, logging_mask: i32,
) -> RunnerResult<Self> { ) -> RunnerResult<Self> {
let (wasm_dir, wasm_filename) = split_dirname(air_wasm_path)?; let (wasm_dir, wasm_filename) = split_dirname(air_wasm_path)?;
let marine_config = let marine_config =
make_marine_config(wasm_dir, &wasm_filename, max_heap_size, logging_mask); make_marine_config(wasm_dir, &wasm_filename, total_memory_limit, logging_mask);
let marine = Marine::with_raw_config(marine_config)?; let marine = Marine::with_raw_config(marine_config)?;
let avm = Self { let avm = Self {
marine, marine,
wasm_filename, wasm_filename,
total_memory_limit,
}; };
Ok(avm) Ok(avm)
@ -190,11 +196,12 @@ impl AVMRunner {
let stats = self.marine.module_memory_stats(); let stats = self.marine.module_memory_stats();
// only the interpreters must be loaded in Marine // only the interpreters must be loaded in Marine
debug_assert!(stats.len() == 1); debug_assert!(stats.modules.len() == 1);
AVMMemoryStats { AVMMemoryStats {
memory_size: stats[0].memory_size, memory_size: stats.modules[0].memory_size,
max_memory_size: stats[0].max_memory_size, total_memory_limit: self.total_memory_limit,
allocation_rejects: stats.allocation_stats.map(|stats| stats.allocation_rejects),
} }
} }
} }
@ -279,12 +286,10 @@ fn split_dirname(path: PathBuf) -> RunnerResult<(PathBuf, String)> {
fn make_marine_config( fn make_marine_config(
air_wasm_dir: PathBuf, air_wasm_dir: PathBuf,
air_wasm_file: &str, air_wasm_file: &str,
max_heap_size: Option<u64>, total_memory_limit: Option<u64>,
logging_mask: i32, logging_mask: i32,
) -> MarineConfig { ) -> MarineConfig {
let air_module_config = marine::MarineModuleConfig { let air_module_config = marine::MarineModuleConfig {
mem_pages_count: None,
max_heap_size,
logger_enabled: true, logger_enabled: true,
host_imports: <_>::default(), host_imports: <_>::default(),
wasi: None, wasi: None,
@ -293,6 +298,7 @@ fn make_marine_config(
MarineConfig { MarineConfig {
modules_dir: Some(air_wasm_dir), modules_dir: Some(air_wasm_dir),
total_memory_limit,
modules_config: vec![ModuleDescriptor { modules_config: vec![ModuleDescriptor {
load_from: None, load_from: None,
file_name: String::from(air_wasm_file), file_name: String::from(air_wasm_file),