Skip to content

Commit

Permalink
Only track memory usage after it has been approved by the downstream …
Browse files Browse the repository at this point in the history
…limiter.
  • Loading branch information
acw committed Jun 20, 2024
1 parent 382bc32 commit 0116457
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/src/linking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,19 @@ impl wasmtime::ResourceLimiter for Limiter {
desired: usize,
maximum: Option<usize>,
) -> anyhow::Result<bool> {
// Track the diff in memory allocated over time. As each instance will start with 0 and
// gradually resize, this will track the total allocations throughout the lifetime of the
// instance.
self.memory_allocated += desired - current;
// limit the amount of memory that an instance can use to (roughly) 128MB, erring on
// the side of letting things run that might get killed on Compute, because we are not
// tracking some runtime factors in this count.
self.internal.memory_growing(current, desired, maximum)
let result = self.internal.memory_growing(current, desired, maximum);

if matches!(result, Ok(true)) {
// Track the diff in memory allocated over time. As each instance will start with 0 and
// gradually resize, this will track the total allocations throughout the lifetime of the
// instance.
self.memory_allocated += desired - current;
}

result
}

fn table_growing(
Expand Down

0 comments on commit 0116457

Please sign in to comment.