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

Limit pool size #2019

Merged
merged 2 commits into from
Jun 15, 2023
Merged

Limit pool size #2019

merged 2 commits into from
Jun 15, 2023

Conversation

ntkme
Copy link
Contributor

@ntkme ntkme commented Jun 15, 2023

Currently we limit the isolate pool size to 15 as we know 16 isolates would deadlock. However, it turns out on 32-bit Dart SDK it would deadlock with 8 isolates.

The issue is that in Dart SDK having more than MaxMutatorThreadCount number of isolates would deadlock the whole Dart VM:

The number of MaxMutatorThreadCount is determined through the following logic:

https://github.com/dart-lang/sdk/blob/3.0.5/runtime/bin/main_impl.cc#L1174-L1181

  // When running from the command line we assume that we are optimizing for
  // throughput, and therefore use a larger new gen semi space size and a faster
  // new gen growth factor unless others have been specified.
  if (kWordSize <= 4) {
    vm_options.AddArgument("--new_gen_semi_max_size=16");
  } else {
    vm_options.AddArgument("--new_gen_semi_max_size=32");
  }

https://github.com/dart-lang/sdk/blob/3.0.5/runtime/vm/heap/scavenger.h#L121

  static const intptr_t kTLABSize = 512 * KB;

https://github.com/dart-lang/sdk/blob/3.0.5/runtime/vm/heap/scavenger.h#L222-L231

  // The maximum number of Dart mutator threads we allow to execute at the same
  // time.
  static intptr_t MaxMutatorThreadCount() {
    // With a max new-space of 16 MB and 512kb TLABs we would allow up to 8
    // mutator threads to run at the same time.
    const intptr_t max_parallel_tlab_usage =
        (FLAG_new_gen_semi_max_size * MB) / Scavenger::kTLABSize;
    const intptr_t max_pool_size = max_parallel_tlab_usage / 4;
    return max_pool_size > 0 ? max_pool_size : 1;
  }

For current Dart SDK:

  • 32-bit: 16MB / 512KB / 4 = 8
  • 64-bit: 32MB / 512KB / 4 = 16

Main isolate counts as one so the limit is really 7 for 32-bit and 15 for 64 bit.

Unfortunately, there is no programatic way to get MaxMutatorThreadCount from Dart code, so we can only hard code for whatever is the default today.

@nex3 nex3 self-requested a review June 15, 2023 21:28
@nex3 nex3 merged commit b11840e into sass:main Jun 15, 2023
45 checks passed
@ntkme ntkme deleted the pool-size branch June 15, 2023 22:03
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.

None yet

2 participants