Skip to content

Retry the kyber write while a sibling disk switches scheduler - #18228

Open
IronsideXXVI wants to merge 3 commits into
omacom:quattrofrom
IronsideXXVI:j604/kyber-retry-sibling-disks
Open

IronsideXXVI wants to merge 3 commits into
omacom:quattrofrom
IronsideXXVI:j604/kyber-retry-sibling-disks

Conversation

@IronsideXXVI

@IronsideXXVI IronsideXXVI commented Nov 9, 2026 •

Copy link
Copy Markdown

What changes

On Linux 7.2 (4ff58d6bc9dd on top of ce8ee8583ed8) and later kernels without commit 603523fd5466 ("block: only serialize elevator switches of the same queue", backported in Linux 7.3.5 as e68b22b51c60), a write to queue/scheduler returns EBUSY while another scheduler switch is running on the same tag set, instead of waiting. All namespaces of an NVMe controller share one tag set, and so do the LUNs of a USB card reader. udev handles sibling disks in parallel and never retries an ATTR write, so all but one of them keep the kernel's pick.

On Apple Silicon Macs this happens on every boot: the controller exposes three namespaces (the system disk and two small Apple ones), all three race, and one wins.

60-omarchy-io-scheduler.rules now writes from RUN and retries for up to two seconds, the way blktests handles the same EBUSY. RUN runs after every rule, so zoned disks are left out of this rule: 64-btrfs-zoned.rules moves zoned btrfs disks back to mq-deadline, and a later kyber write must not undo that.

Refs #17500, which reports the same EBUSY on empty USB card readers. #17516 skips zero-size disks for that case and notes that a busy queue on a disk with media "would need a retry mechanism udev rules do not have". This is that retry. It covers the card readers too, and it does not conflict with #17516's intent: ATTR{size}!="0" can sit on this line as well, so whichever merges first, the other rebases with a one-line change.

Verification

  • bash test/shell.d/io-scheduler-rule-test.sh passes on this branch and fails on quattro (cbd0029) with "the kyber write runs from RUN, so a busy queue is not the last attempt".
    • No existing test covers the udev rules, so this is a new 27-line file.
    • It runs the rule's own RUN command against a scratch disk whose queue/scheduler refuses writes, like a busy queue, until a background job frees it after 0.5 s.
  • udevadm verify (systemd 255) accepts the rule file on quattro and on this branch.
  • On a MacBook Pro 14-inch M4 (J604) running Omarchy 4.5.0-3, omarchy-settings 4.5.0-3 and linux-aurora 7.2.11 (it still happens on the edge channel, omarchy-settings-dev 4.0.0.r7634.gcbd0029: after a fresh boot nvme0n1 and nvme0n3 stay on mq-deadline and only nvme0n2 gets kyber):
    • With the stock rule, on the boot of 2026-11-09, the journal has two errors:
      (udev-worker)[702]: nvme0n1: /etc/udev/rules.d/60-omarchy-io-scheduler.rules:8 ATTR{queue/scheduler}="kyber": Failed to write "kyber" to sysfs attribute "queue/scheduler", ignoring: Device or resource busy
      (udev-worker)[685]: nvme0n2: /etc/udev/rules.d/60-omarchy-io-scheduler.rules:8 ATTR{queue/scheduler}="kyber": Failed to write "kyber" to sysfs attribute "queue/scheduler", ignoring: Device or resource busy
      
      Afterwards nvme0n1 (the system disk) and nvme0n2 are on mq-deadline, and nvme0n3 is on kyber.
    • With this rule (carried as a local omarchy-settings patch since 2026-11-04), the 7 boots before that one have no such error, and all three namespaces were on kyber.
    • Without the retry, this Mac logged EBUSY for two of the three namespaces on each of six boots on 2026-11-04, and the system disk stayed on mq-deadline in four of them.
  • Not run:
    • ./test/all, because AGENTS.md reserves it for shared code; CI runs it on this PR.
    • A USB card reader, because I had none to hand.

Screenshots

No visible change: a udev rule that picks the I/O scheduler.

Since Linux 7.2 (4ff58d6bc9dd, "block: serialize elevator changes for
the same queue using a writer lock", on top of ce8ee8583ed8's trylock),
a write to queue/scheduler takes its tag set's update_nr_hwq_lock as a
writer with a trylock and returns EBUSY when another switch on the same
tag set is running. Every namespace of an NVMe controller shares one
tag set, as do the LUNs of a USB card reader, and udev handles sibling
disks in parallel workers and never retries an ATTR write. So all but
one of them keep the kernel's pick.

On Apple Silicon Macs that is every boot: the controller exposes three
namespaces (the system disk plus two small Apple ones), all three race,
and one wins. An M4 MacBook Pro logged EBUSY for two of the three on
each of six boots, and the system disk, nvme0n1, stayed on mq-deadline
in four of them.

Write from RUN instead and retry for up to two seconds, the way
blktests handles the same EBUSY. RUN runs after every rule, so zoned
disks are left out here: 64-btrfs-zoned.rules moves zoned btrfs back to
mq-deadline, and a later kyber write must not undo that.

Refs omacom#17500

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
Assisted-by: Claude:claude-opus-5.5
@greptile-apps

greptile-apps Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5RetriggerView in Greptile

[Medium impact] The PR appears safe to merge, with no new actionable findings.

Summary

The PR retries busy scheduler writes before leaving a disk on its current scheduler.

  • Disk scheduler rules retry kyber writes after a sibling finishes.

Reviews (3) · Last reviewed commit: "Note that the kyber EBUSY race affects L..." · Reviewed by Greptile

IronsideXXVI added a commit to IronsideXXVI/omarchy-j604 that referenced this pull request Nov 12, 2026
What the J604 runs now: kernel 1.848, mesa-aurora and vulkan-aurora
1.8139 (the 1.8134 content, rebuilt so the repository matches what is
installed after a rollback), omarchy-dev 1.3 (the 1.1 content), stock
Hyprland. The mesa T8132 patch drops a trailer line; its change is the
same.

UPSTREAM.md: the new heads of aurora-silicon/linux#1494, #1495 and #1496
(now with Dylan's Signed-off-by), omacom/omarchy#18582 and
omacom/omarchy-mac-pkgs#134. omacom/omarchy#18228 is a live release item
again: on 1.848 two NVMe namespaces fall back to mq-deadline on every
boot.
@omarchybot

Copy link
Copy Markdown
Collaborator

GPT-6 in Codex read the diff, the current quattro rule, the discussion, issue #17500 and PR #17516; this session does not expose its reasoning effort setting. My classification was hardware compatibility because the reported failure depends on sibling disks sharing a tag set. The classification model, deepseek-v4p1-flash, returned no classification, so classification remains unsettled.

Verification stopped at that classification gate: no worker tests ran, no fix was pushed, and no class or verification labels were applied. The review service passed its availability check, but no second code review was requested. This needs a maintainer to resolve classification before verification continues.

@IronsideXXVI

Copy link
Copy Markdown
Author

For the classification: this is a compatibility fix, as the first read said. It changes nothing for a machine with one disk per tag set. It only matters where sibling disks share a tag set, like the three NVMe namespaces on Apple Silicon Macs or the LUNs of a USB card reader (#17500), on Linux 7.2 and later.

I re-checked it today against current quattro: it still merges cleanly, and test/shell.d/io-scheduler-rule-test.sh passes both on the branch and on the merge result. I can't set labels on this repo, so a maintainer needs to apply the label.

@omarchybot omarchybot added the bug Something isn't working label Nov 22, 2026
@IronsideXXVI

Copy link
Copy Markdown
Author

Some on-device numbers for this, from an M4 MacBook Pro (three NVMe namespaces sharing one tag set) on Linux 7.3 with the current rule, no retry:

  • After a fresh boot today, nvme0n1 was on kyber but nvme0n2 and nvme0n3 were still on mq-deadline. That's the race this PR fixes: two of the three writes lost.
  • With the boot settled, I switched all three namespaces by hand, one after another (kyber, mq-deadline, kyber, mq-deadline). Every write took on the first try, with no EBUSY. So the failure only shows up when the writes overlap, which is what udev does at boot.
  • Speed is the same either way, so this is about getting the scheduler the rule asks for on every boot, not about performance. Same boot, one disk, alternating arms:
    • 1 GiB sequential write (dd bs=1M, then sync), 8 runs each: kyber 3077 MiB/s, mq-deadline 3070 MiB/s.
    • 4 KiB write + fsync, 500 writes each: kyber median 6.96 ms (p99 7.89 ms), mq-deadline median 6.95 ms (p99 10.02 ms). The mq-deadline p99 comes from a burst in one of its two runs, so I wouldn't read anything into it.

Without the retry, which scheduler each namespace gets changes from boot to boot.

@IronsideXXVI

Copy link
Copy Markdown
Author

Follow-up with the retry rule installed (the rule file from this PR head, byte for byte; same M4 MacBook Pro, Linux 7.3):

  • 5 boots in a row, all clean.
  • 4 of them I read live in sysfs right after boot: [kyber] on nvme0n1, nvme0n2 and nvme0n3 every time, 12/12.
  • The other one I checked from its journal: no "failed with exit code" line for the scheduler RUN.
  • No udev worker slow or killed lines for the nvme devices in any of the 5 boots.

Before the retry, the same machine came up with two of the three namespaces on mq-deadline after a fresh boot. With it, every boot gives the same result.

Let the retry command create the scheduler file after the placeholder directory is removed. A separate truncation can run after a successful retry and erase kyber before the assertion reads it.

Co-Authored-By: GPT-6 <noreply@openai.com>
Co-Authored-By: Opus 5.5 High <noreply@anthropic.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Nov 23, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

GPT-6 in Codex (effort setting not exposed), Opus 5.5 High and muse-wonder via pi (thinking high) reviewed this change. Opus found a race in the test: the background job could truncate a successful kyber write. Commit e733285420b113592fa2afa658e330468629afc9 removes that redundant truncation. Forcing that ordering on the worker fails before the fix, passes afterward, and fails again when reverted. Both reviewers checked the final head and found no remaining concrete defect; independence of their agreement is not guaranteed.

On a disposable Omarchy worker running kernel 7.2.15, I reproduced the scheduler failure through real udev change events and sysfs on 16 SCSI test-driver LUNs with a shared tag set:

Rule Disks selecting kyber
Current quattro rule 1/16
This PR 16/16
Current rule restored 2/16
Single write from RUN, without retries 2/16

The base failures logged EBUSY. ./test/cli, the focused retry test and udevadm verify passed. The rule also switched the worker's ordinary virtio disk to kyber and left a host-managed zoned disk on mq-deadline. This verifies the kernel contention fix; it does not confirm a specific Apple controller or the physical reader from #17500.

#17516 adds a complementary empty-disk guard; the two changes touch the same rule line. Deferring the write to RUN also makes it take precedence over later custom ATTR scheduler rules. This is verified and waiting on the maintainer’s decision about the broader zoned-disk exclusion and the test’s fit with repository guidance.

@e-fu

e-fu commented Dec 2, 2026

Copy link
Copy Markdown

For context: on Apple Silicon NVMe (sibling namespaces sharing one tag set) this EBUSY comes from a kernel regression in 7.2 (4ff58d6bc9dd) that is fixed upstream by 603523fd5466 ("block: only serialize elevator switches of the same queue"). The first stable release with it is 7.3.5 (e68b22b51c60). After the fix, switches on sibling queues no longer block each other; writes that race with the same queue, an nr_hw_queues update, an nr_requests write or disk removal can still get EBUSY.

So the retry still helps on kernels without the fix, such as linux-aurora 7.3.0.aurora1-48, where I see 2 of 3 namespaces fail each boot on a MacBook Pro 14" M4 Pro. Kernel-side report: aurora-silicon/linux#3899.

@omarchybot

Copy link
Copy Markdown
Collaborator

GPT-6.2 Sol High in Codex checked the Linux changelog, Omarchy’s package indexes and the earlier worker results. Linux 7.3.5 includes e68b22b51c60, which removes the scheduler-switch race between sibling queues. Omarchy stable x86_64 still lists linux-omarchy 7.2.15-4, the build on which the worker reproduced the race. The Aurora report covers a different build from those in the current package indexes, so the backport status of those builds remains unverified. Linux 7.3.5 changelog · Aurora report

Opus 5.5 High and muse-wonder via pi (thinking high) agreed on the kernel and package evidence, with independence unconfirmed. Both flagged that the rule’s “since Linux 7.2” wording now needs to specify kernels without the fix. The earlier worker verification still applies to e7332854. The Tests workflow needs approval, and the PR is with the maintainer to decide whether to carry the retry while affected kernels ship. Tests workflow

Clarify the rule and test comments to note that the sibling tag-set
EBUSY race applies to Linux 7.2 and later kernels without commit
603523fd5466 (backported in Linux 7.3.5 as e68b22b51c60).

Signed-off-by: Dylan Ironside <dylan@dylanironside.io>
@IronsideXXVI

Copy link
Copy Markdown
Author

Updated the rule and test comments in e21f88ca9 to clarify that the sibling tag-set EBUSY race applies to Linux 7.2 and later kernels without commit 603523fd5466 (backported in Linux 7.3.5 as e68b22b51c60). No change to the rule logic; test/shell.d/io-scheduler-rule-test.sh and udevadm verify both pass.

@omarchybot omarchybot added verified Omarchy Triage has verified that this issue is ready for final review and removed verified Omarchy Triage has verified that this issue is ready for final review labels Dec 3, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Recommend: Hold — the Tests workflow needs maintainer approval, and the maintainer needs to decide whether to carry the retry while affected kernels still ship. Tests workflow

On Omarchy stable kernel 7.2.15-4, 1 of 16 shared-tag-set test disks selected Kyber with the stock rule, 16 of 16 with e21f88ca, and 1 of 16 after restoring the stock rule. On 7.3.6-10 the stock rule selected Kyber on all 16. The CLI suite, focused retry test, and udevadm verify passed on an isolated ISO worker. The physical dock in #17500 remains untested, and #17516 still covers the separate empty-reader case.

GPT-6 High in Codex, Opus 5.5 High and muse-wonder via pi (thinking high) agreed that the updated comments describe the upstream fix correctly and found no new code defect. Independence of that agreement is unconfirmed. Please give the PR description the same qualification about kernels that lack the upstream fix. Linux 7.3.5 changelog

@IronsideXXVI

Copy link
Copy Markdown
Author

Updated the PR description to clarify that the sibling tag-set EBUSY race applies to Linux 7.2 and later kernels without commit 603523fd5466 (backported in Linux 7.3.5 as e68b22b51c60).

@omarchybot

Copy link
Copy Markdown
Collaborator

Recommend: Hold — the maintainer needs to approve the Tests workflow and decide whether to carry the retry while affected kernels still ship. Tests workflow

The updated description names the upstream fix for the sibling-queue race. GPT-6.2 Sol High in Codex, Opus 5.5 High and muse-wonder via pi (thinking high) checked that clarification and the existing ISO-worker evidence for the unchanged head. Opus also flagged that udev runs the Kyber write after processing all rules, so it can overwrite a scheduler set by a later local ATTR{queue/scheduler} rule on a matching disk. Linux changelog · udev manual

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working verified Omarchy Triage has verified that this issue is ready for final review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants