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

Reuse VM memory across executions #1888

Merged
merged 29 commits into from
Jun 4, 2024
Merged

Reuse VM memory across executions #1888

merged 29 commits into from
Jun 4, 2024

Conversation

Dentosal
Copy link
Member

@Dentosal Dentosal commented May 8, 2024

Closes #1878. Requires FuelLabs/fuel-vm#732 and a new fuel-vm release.

Introduces a per-thread pool for allocated VM memory instances. Whenever a new VM instance is needed for a tx, the memory is taken from this pool. After the tx has been executed, the memory is reset to an empty state without deallocating, and returned to the pool.

A per-thread pool was chosen to no pass allocations between threads unnecessarily.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog (none)
  • New behavior is reflected in tests

Before requesting review

  • I have reviewed the code myself
  • I have created follow-up issues caused by this PR and linked them here

@Dentosal Dentosal added enhancement New feature or request fuel-block-executor labels May 8, 2024
@Dentosal Dentosal self-assigned this May 8, 2024
pub(crate) fn get_vm_memory() -> Memory {
POOL.with(|pool| {
let mut pool = pool.borrow_mut();
pool.pop().unwrap_or_else(Memory::new)
Copy link
Member

@Voxelot Voxelot May 8, 2024

Choose a reason for hiding this comment

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

We should probably have some kind constraint on the max number of items allowed in each pool? Otherwise it should wait if there are none available.

Copy link
Member Author

Choose a reason for hiding this comment

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

We didn't do this earlier, and I don't see why it would make sense to track the items here, instead of just limiting concurrency of the executor itself. That said, keeping a pool per thread is by itself problematic and not useful, as:

  1. The threads are not CPU-pinned anyway
  2. The async runtime might decide to create new threads arbitarily, which would essentially cause a memory leak here

So I' changed the code to not keep separate pools in 5caec42

@xgreenx xgreenx self-assigned this Jun 3, 2024
@xgreenx xgreenx requested review from Voxelot, MitchTurner and a team June 3, 2024 13:11
@xgreenx xgreenx marked this pull request as ready for review June 3, 2024 13:11
@Dentosal Dentosal merged commit f52102b into master Jun 4, 2024
33 checks passed
@Dentosal Dentosal deleted the dento/reuse-vm-memory branch June 4, 2024 18:45
@xgreenx xgreenx mentioned this pull request Jun 6, 2024
xgreenx added a commit that referenced this pull request Jun 7, 2024
## Version v0.28.0

### Changed
- [#1934](#1934): Updated
benchmark for the `aloc` opcode to be `DependentCost`. Updated
`vm_initialization` benchmark to exclude growing of memory(It is handled
by VM reuse).
- [#1916](#1916): Speed up
synchronisation of the blocks for the `fuel-core-sync` service.
- [#1888](#1888):
optimization: Reuse VM memory across executions.

#### Breaking

- [#1934](#1934): Changed
`GasCosts` endpoint to return `DependentCost` for the `aloc` opcode via
`alocDependentCost`.
- [#1934](#1934): Updated
default gas costs for the local testnet configuration. All opcodes
became cheaper.
- [#1924](#1924):
`dry_run_opt` has new `gas_price: Option<u64>` argument
- [#1888](#1888): Upgraded
`fuel-vm` to `0.51.0`. See
[release](https://github.com/FuelLabs/fuel-vm/releases/tag/v0.51.0) for
more information.

### Added
- [#1939](#1939): Added API
functions to open a RocksDB in different modes.
- [#1929](#1929): Added
support of customization of the state transition version in the
`ChainConfig`.

### Removed
- [#1913](#1913): Removed dead
code from the project.

### Fixed
- [#1921](#1921): Fixed
unstable `gossipsub_broadcast_tx_with_accept` test.
- [#1915](#1915): Fixed
reconnection issue in the dev cluster with AWS cluster.
- [#1914](#1914): Fixed
halting of the node during synchronization in PoA service.

## What's Changed
* Removed dead code by @xgreenx in
#1913
* Added backward and forward compatibility integration tests for
forkless upgrades by @xgreenx in
#1895
* Fixed halting of the node in rare conditions by @xgreenx in
#1914
* Weekly `cargo update` by @github-actions in
#1928
* Fixed logging of the WASM executor by @xgreenx in
#1930
* Added support of customization of the state transition version in the
`ChainConfig` by @xgreenx in
#1929
* Document wasm toolchain installation, add rust-toolchain.toml by
@Dentosal in #1932
* Add optional `gas_price` argument to `dry_run_opt` by @hal3e in
#1924
* Reuse VM memory across executions by @Dentosal in
#1888
* Fixed reconnection issue in the dev cluster with AWS cluster by
@xgreenx in #1915
* Speeds up synchronisation of the blocks for the `fuel-core-sync`
service by @xgreenx in #1916
* Fixed unstable `gossipsub_broadcast_tx_with_accept` test by @xgreenx
in #1921
* Added API functions to open a RocksDB in different modes by @xgreenx
in #1939
* Use `DependentCost` for `aloc` opcode by @xgreenx in
#1934

## New Contributors
* @hal3e made their first contribution in
#1924

**Full Changelog**:
v0.27.0...v0.28.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reuse the same instance of the VM for txs in block production and validation
4 participants