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

Insufficient resources: could not allocate code memory #10374

Closed
aleksuss opened this issue Jan 2, 2024 · 4 comments
Closed

Insufficient resources: could not allocate code memory #10374

aleksuss opened this issue Jan 2, 2024 · 4 comments
Labels
A-contract-runtime Area: contract compilation and execution, virtual machines, etc C-good-first-issue Category: issues that are self-contained and easy for newcomers to work on. T-contract-runtime Team: issues relevant to the contract runtime team

Comments

@aleksuss
Copy link

aleksuss commented Jan 2, 2024

I started getting the error: LoadingError("Insufficient resources: could not allocate code memory: Cannot allocate memory (os error 12)") while running tests on my CI after switching to the near-vm-runner = "0.19". But at the same time, I don't get such an error locally on my M2 laptop. Firstly, I thought that it could be related to different architectures, but then I decreased the number of threads for running tests on the CI (which uses 64 core runner by default) and the error didn't occur. I started some code investigation and found that there is only one mempool is used for all parallel running tests. After changing the count value from 8 to num cpus in my fork and use it instead of dependencies from crates.io fixed the issue and the started passing.

To Reproduce
Use heavy smart contract in near-vm-runner (in my case, it's about 1.2 mb) in tests running parallel on a host with >= 32 CPUs.

Expected behaviour
CPU number on the host shouldn't affect the result of running tests.

Screenshots
If applicable, add screenshots to help explain your problem.

Version (please complete the following information):

  • near-vm-runner 0.19.0
  • rust version: nightly-2023-12-15
@nagisa
Copy link
Collaborator

nagisa commented Jan 2, 2024

As the comment in the relevant code suggests, 8 is the best guess we made at the time. This works for neard as it can only have as many contracts running in parallel as there are shards being tracked by a node.

near-vm-runner is not written with any other use-cases in mind and I'm not sure what it would take before we consistently consider other users.

It wouldn’t be too hard to make the pool arguments configurable here. Add some fields to the Config struct & use those parameters to construct the pool. For neard the default values of these parameters should stay the same, but in your tests you would be able to specify whatever value you wish at the time you construct the runtime.

@nagisa nagisa added C-good-first-issue Category: issues that are self-contained and easy for newcomers to work on. A-contract-runtime Area: contract compilation and execution, virtual machines, etc T-contract-runtime Team: issues relevant to the contract runtime team labels Jan 2, 2024
@aleksuss
Copy link
Author

aleksuss commented Jan 2, 2024

near-vm-runner is not written with any other use-cases in mind and I'm not sure what it would take before we consistently consider other users.

But version 0.17.0 works fine. Unfortunately, this version doesn't support contracts compiled with recent Rust versions.

@nagisa
Copy link
Collaborator

nagisa commented Jan 2, 2024

That's unsurprising. The pool of memories has been added reasonably recently and having it be fixed size is actually desirable for neard as there have been concerns about statically establishing an memory requirement ceiling for the runtime.

The fact that a prior version worked for an external use-case doesn’t change the essence of my statement either. near-vm-runner is developed and maintained for its primary use as a runtime within the reference NEAR validator. Suitability for any other use-case is incidental.

That said, there's no reason it cannot be used elsewhere, but an implicit expectation is that the interested parties would contribute to the effort (of making it suitable for those other use-cases and helping to keep it in that shape by e.g. contributing to reviews.)

@aleksuss
Copy link
Author

Looks like the issue has been fixed in the near-vm-runner 0.20.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-contract-runtime Area: contract compilation and execution, virtual machines, etc C-good-first-issue Category: issues that are self-contained and easy for newcomers to work on. T-contract-runtime Team: issues relevant to the contract runtime team
Projects
None yet
Development

No branches or pull requests

2 participants