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

Better stack limits #554

Merged
merged 5 commits into from
May 15, 2022
Merged

Better stack limits #554

merged 5 commits into from
May 15, 2022

Conversation

magik6k
Copy link
Contributor

@magik6k magik6k commented May 12, 2022

todo:

  • Measure max stack wasm use on mainnet
  • Set lower recursive send limit
  • Set lower wasm stack limit
  • (maybe) Make native stacks larger

Fixes #552

@@ -38,9 +39,24 @@ impl<K: Kernel> DerefMut for DefaultExecutor<K> {
}
}

lazy_static! {
static ref EXEC_POOL: yastl::Pool = yastl::Pool::with_config(
8,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is an arbitrary number; Just for chain-sync we probably don't need more than 1/2, but some users may want this to be higher e.g. to get internal sends in a bunch of historic tipsets.

Copy link
Member

Choose a reason for hiding this comment

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

How about using NUM CPUs?

Copy link
Member

Choose a reason for hiding this comment

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

Some people have a lot of CPUs. We're already reserving half a gig for stacks here. We'll actually likely want to shrink this.

Copy link
Member

Choose a reason for hiding this comment

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

I.e., 128 cores = 8GiB of memory just sitting there.

@magik6k magik6k force-pushed the fix/native-stack-limits branch 2 times, most recently from 17d75b5 to bd9c6ab Compare May 15, 2022 17:40
@magik6k magik6k changed the title [wip] better stack limits Better stack limits May 15, 2022
@magik6k magik6k marked this pull request as ready for review May 15, 2022 17:40
Copy link
Member

@raulk raulk 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! Just a few questions for now. Review from @Kubuxu @dignifiedquire @Stebalien @mriise would be welcome.

fvm/src/executor/default.rs Show resolved Hide resolved
@@ -124,8 +124,8 @@ impl NetworkConfig {
pub fn new(network_version: NetworkVersion) -> Self {
NetworkConfig {
network_version,
max_call_depth: 4096,
max_wasm_stack: 64 * 1024,
max_call_depth: 1024,
Copy link
Member

Choose a reason for hiding this comment

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

To be technically correct, we should set 1024 on nv16 and above, only.

Copy link
Member

Choose a reason for hiding this comment

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

So, @magik6k pointed out that we'll hit the rust stack limit at 4096. The only real solution would be to increase the thread size.

But, in practice, it's unclear if one can actually make a message that can get past 1024 calls on mainnet. By "unclear", I mean "totally not close to possible". @magik6k only got to 1025 by making a custom actor that did nothing but recursively send. On mainnet, one would have to make a recursive call in a multisig actor, where each recursive call would be significantly more expensive (running out of block gas before anything else).

Copy link
Member

Choose a reason for hiding this comment

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

Tradeoffs:

  • The current way, it's unlikely that something goes wrong, and the worst-case is a fork (for anyone running with the FVM_EXPERIMENTAL flag).
  • By increasing to 4096 (without changing the stack size), it's also unlikely that something will go wrong, but we'll crash (hard) if we do go past 1024.

.execute_message(message, ApplyKind::Explicit, 100)
.unwrap();

assert_eq!(res.msg_receipt.exit_code.value(), 0)
Copy link
Member

Choose a reason for hiding this comment

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

Is the exit code you see here 10?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added more cases with more readable codes.

@magik6k magik6k force-pushed the fix/native-stack-limits branch 2 times, most recently from c4a7c8f to 8f5fa91 Compare May 15, 2022 21:57
@@ -38,9 +39,24 @@ impl<K: Kernel> DerefMut for DefaultExecutor<K> {
}
}

lazy_static! {
static ref EXEC_POOL: yastl::Pool = yastl::Pool::with_config(
8,
Copy link
Member

Choose a reason for hiding this comment

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

Some people have a lot of CPUs. We're already reserving half a gig for stacks here. We'll actually likely want to shrink this.

@magik6k magik6k merged commit 1183818 into master May 15, 2022
@magik6k magik6k deleted the fix/native-stack-limits branch May 15, 2022 22:52
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.

Determine stack size limit approach
3 participants