Scheduling: OR in SCHED_RESET_ON_FORK instead of ANDing it#2046
Merged
Conversation
Scheduling_setPolicy() set the reset-on-fork flag with `policy &= SCHED_RESET_ON_FORK`. SCHED_RESET_ON_FORK is 0x40000000 and the scheduling policies (SCHED_OTHER=0, FIFO=1, RR=2, BATCH=3, IDLE=5) share no bits with it, so `&=` always zeroes the policy to SCHED_OTHER and drops the flag. Enabling "Reset on fork" while choosing a real-time policy therefore either fails with EINVAL (the RT priority no longer matches SCHED_OTHER) or silently downgrades the process to SCHED_OTHER. Use `|=` so the flag is combined with the chosen policy, matching the sibling Scheduling_formatPolicy() which strips it with `policy & ~SCHED_RESET_ON_FORK`. Assisted-by: Claude (Anthropic) Signed-off-by: winklemad <winklemad@outlook.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthrough
Poem
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
BenBE
approved these changes
Jul 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Scheduling_setPolicy()sets the reset-on-fork flag with&=instead of|=:SCHED_RESET_ON_FORKis0x40000000, and the scheduling policies (SCHED_OTHER=0,FIFO=1,RR=2,BATCH=3,IDLE=5) share no bits with it, sopolicy &= 0x40000000is always0(SCHED_OTHER) — the chosen policy and the flag are both lost.So when a user enables "Reset on fork" and selects a real-time policy (FIFO/RR/BATCH/IDLE), the subsequent
sched_setscheduler(pid, SCHED_OTHER, {sched_priority > 0})fails with EINVAL (a nonzero priority is invalid forSCHED_OTHER) and the action silently fails; with priority 0 the process is silently downgraded toSCHED_OTHER. Either way, neither the requested policy nor reset-on-fork is applied.Fix
Use
|=so the flag is OR-ed onto the chosen policy — matching the siblingScheduling_formatPolicy(), which strips it back out withpolicy & ~SCHED_RESET_ON_FORK, confirming it's meant to be combined.Verification
The block is Linux-only (
#ifdef SCHED_RESET_ON_FORKinsideSCHEDULER_SUPPORT), so I confirmed the bitwise logic with a small harness rather than the live UI: for every policy, the current&=yields0x00000000(policy lost) while|=yields the correct0x40000000 | policy(e.g. FIFO →0x40000001). htop builds cleanly before/after. A repo-wide grep confirms this is the only&=used to set (rather than clear) a flag.This fix was prepared with AI assistance (noted via the
Assisted-by:commit trailer, per the project's policy); I reviewed the change and verified the logic and the reproduction myself.