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

Use a ResourceLimiter for tracking allocations #300

Merged
merged 2 commits into from
Aug 7, 2023
Merged

Conversation

elliottt
Copy link
Contributor

@elliottt elliottt commented Aug 4, 2023

Instead of counting the number of pages present in the memory exported by a wasm module, count the memory allocation diffs over time using the ResourceLimiter api.

This change helps set us up for component support, as there's no analogue of get_memory for components.

@elliottt elliottt requested a review from acfoltzer August 7, 2023 21:07
impl wasmtime::ResourceLimiter for Limiter {
fn memory_growing(
&mut self,
current: usize,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we confirm that this starts at zero? In other words, is memory_growing called when the initial heap for an instance is set up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The interface for allocating new Memory structures in wasmtime is Memory::new_dynamic and Memory::new_static. Both dispatch to Memory::limit_new, which will call memory_growing with a current value of 0.

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome, thank you for checking!

Copy link
Contributor

@acfoltzer acfoltzer left a comment

Choose a reason for hiding this comment

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

Looks good, thank you!

@elliottt elliottt merged commit 0fefa2b into main Aug 7, 2023
7 checks passed
@elliottt elliottt deleted the trevor/limiter branch August 7, 2023 23:35
cmckendry pushed a commit to 1stdibs/Viceroy that referenced this pull request Feb 8, 2024
Co-authored-by: Adam C. Foltzer <acfoltzer@acfoltzer.net>
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