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

Fix the return value of Concurrent.available_processor_count when cpu.cfs_quota_us is -1 #1060

Merged

Conversation

y-yagi
Copy link
Contributor

@y-yagi y-yagi commented Aug 9, 2024

I tried to use Concurrent.available_processor_count in parallel gem, but we got some feedback Concurrent.available_processor_count returned a negative value.
grosser/parallel#348 (comment)
grosser/parallel#349 (comment)

According to the https://docs.kernel.org/scheduler/sched-bwc.html#management, The default value of cpu.cfs_quota_us is -1. In that case, cgroup does not adhere to any CPU time restrictions.

This PR adds the case of cpu.cfs_quota_us is -1 to #cpu_quota to return processor count from Concurrent.available_processor_count in that case.

@y-yagi y-yagi marked this pull request as ready for review August 9, 2024 03:51
@eregon
Copy link
Collaborator

eregon commented Aug 9, 2024

cc @byroot @casperisfine

return nil if max == 0
# If the cpu.cfs_quota_us is -1, cgroup does not adhere to any CPU time restrictions
# https://docs.kernel.org/scheduler/sched-bwc.html#management
return nil if max == 0 || max == -1
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe we should check if max <= 0?
Seems a tiny bit safer and more efficient as we can't interpret a value <= 0 safely.
Could you change to that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for your review. I updated the condition.

@eregon
Copy link
Collaborator

eregon commented Aug 9, 2024

Thanks and sorry for the bug.
Could you add a CHANGELOG entry?

@y-yagi y-yagi force-pushed the fix_available_processor_count branch from ddf62f6 to 7306b26 Compare August 10, 2024 06:31
…cpu.cfs_quota_us` is -1

I tried to use `Concurrent.available_processor_count` in `parallel`
gem, but we got some feedback `Concurrent.available_processor_count`
returned a negative value.
grosser/parallel#348 (comment)
grosser/parallel#349 (comment)

According to the https://docs.kernel.org/scheduler/sched-bwc.html#management,
The default value of `cpu.cfs_quota_us` is -1. In that case,
cgroup does not adhere to any CPU time restrictions.

This PR adds the case of `cpu.cfs_quota_us` is -1 to `#cpu_quota`
to return processor count from `Concurrent.available_processor_count`
in that case.
@y-yagi y-yagi force-pushed the fix_available_processor_count branch from 7306b26 to 7fea31d Compare August 10, 2024 06:34
@y-yagi
Copy link
Contributor Author

y-yagi commented Aug 10, 2024

I've added a CHANGELOG entry.

@eregon eregon merged commit 98d0f16 into ruby-concurrency:master Aug 10, 2024
14 checks passed
@y-yagi y-yagi deleted the fix_available_processor_count branch August 10, 2024 11:45
@eregon
Copy link
Collaborator

eregon commented Aug 10, 2024

I released https://github.com/ruby-concurrency/concurrent-ruby/releases/tag/v1.3.4 with this fix

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