Skip to content

Adjust snt < max_cpu calculation #14280

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jhawthorn
Copy link
Member

[Bug #20146]

Previously we dealt with the main Ractor not being enabled for M:N by incrementing snt_cnt++. This worked for comparing against ractor count, but meant that we always had one less SNT than was specified by RUBY_MAX_CPU.

This was notably a problem for RUBY_MAX_CPU=1, which would cause Ractors to hang.

This commit instead of adjusting snt, adjusts a "schedulable_ractor_cnt". This way snt_cnt will actually reach RUBY_MAX_CPU.

[Bug #20146]

Previously we dealt with the main Ractor not being enabled for M:N by
incrementing snt_cnt++. This worked for comparing against ractor count,
but meant that we always had one less SNT than was specified by
RUBY_MAX_CPU.

This was notably a problem for RUBY_MAX_CPU=1, which would cause Ractors
to hang.

This commit instead of adjusting snt, adjusts a
"schedulable_ractor_cnt". This way snt_cnt will actually reach
RUBY_MAX_CPU.
@jhawthorn jhawthorn requested a review from ko1 August 20, 2025 17:19
@@ -397,11 +397,15 @@ native_thread_check_and_create_shared(rb_vm_t *vm)

rb_native_mutex_lock(&vm->ractor.sched.lock);
{
unsigned int snt_cnt = vm->ractor.sched.snt_cnt;
if (!vm->ractor.main_ractor->threads.sched.enable_mn_threads) snt_cnt++; // do not need snt for main ractor
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to not increase snt_cnt here and have it work?

Copy link
Member Author

@jhawthorn jhawthorn Aug 20, 2025

Choose a reason for hiding this comment

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

That and no other changes? It would work, but we'd spawn one more SNT than we need until we hit vm->ractor.sched.max_cpu (because we'd be spawning one "for" the main Ractor).

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