Skip to content

mclock_common, mClockScheduler: Bound high_priority drain to prevent starvation - #71205

Merged
sseshasa merged 2 commits into
ceph:mainfrom
sseshasa:wip-fix-scrub-stalls-with-mclock
Sep 9, 2026
Merged

sseshasa merged 2 commits into
ceph:mainfrom
sseshasa:wip-fix-scrub-stalls-with-mclock

Conversation

@sseshasa

@sseshasa sseshasa commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor

Background & Changes:

  1. Under sustained client I/O on EC pools, mClockScheduler::dequeue() drains the strict-priority high_priority queue (immediate class, e.g. client-driven EC subop reads/writes/replies) unconditionally before ever calling scheduler.pull_request(), the entry point that services mClock managed queue items. Since high_priority can stay continuously non-empty under heavy load, this can starve mClock managed queue items -- in the trackers case most visibly deep-scrub's chunk-continuation events (PGScrubGetNextChunk, PGScrubChunkIsFree, PGScrubResched, etc.) -- for tens of seconds at a time, regardless of their configured mclock reservation.
  • Add a bounded check: once the mclock-managed queue has gone unserviced for osd_mclock_max_starve_time while high_priority keeps refilling, force one dequeue attempt from it before resuming the high_priority drain. No-op when the mclock queue is empty, so normal operation is unaffected.
  • Bound the starvation window on flash to 50ms via an internal constant -- scheduler_max_starve_time_ssd, and not a configuration option as this was tested on real hardware.
  • But since no HDD test hardware has been available for this investigation, rather than ship an unvalidated hardcoded constant with no adjustment path, a configurable called osd_mclock_max_starve_time_hdd is introduced. Default 0.25s, bounded to [0.1s, 0.5s]. A modern 7200 RPM HDD's average random-access time is roughly 10-15ms, so the configurable range remains a real, meaningful multiple of that even at the tightest allowed setting. This allows an operator some flexibility in case a given HDD fleet needs a different value.
  1. Give client class items enqueued via enqueue_front() a reserved high_priority queue (requeued_class_priority, set to SchedulerClass::client's own value purely so it documents itself) instead of priority 0, and gate the starvation-bound forced yield so it never pulls from the mclock-managed queue while requeued class priority queue is non-empty. The other high_priority queues(MAX, >=cutoff_priority) and their drain remain unchanged.

Tests (src/test/osd/TestMClockScheduler.cc):

  • Add Unit Tests to exercise the starvation logic for SSD and HDD.
  • Add unit tests to exercise the requeued_class_priority queue mechanics and maintaining op order invariant.

Documentation (doc/rados/configuration/mclock-config-ref.rst): Add a new "mClock Queue Starvation Prevention" section explaining the immediate/high-priority-vs-mclock-managed-queue starvation mechanism, the bounded forced-yield fix, the device-aware threshold split and add osd_mclock_max_starve_time_hdd to the list of config options.

Test Report - Discusses results from more in-depth testing on a node with NVMe hardware.

Fixes: https://tracker.ceph.com/issues/69078
Signed-off-by: Sridhar Seshasayee [email protected]

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)
Show available Jenkins commands

You must only issue one Jenkins command per-comment. Jenkins does not understand
comments with more than one command.

…starvation

Under sustained client I/O on EC pools, mClockScheduler::dequeue() drains
the strict-priority high_priority queue (immediate class, e.g. client-driven
EC subop reads/writes/replies) unconditionally before ever calling
scheduler.pull_request(), the entry point that services mClock managed queue
items. Since high_priority can stay continuously non-empty under heavy load,
this can starve mClock managed queue items -- in the trackers case most
visibly deep-scrub's chunk-continuation events (PGScrubGetNextChunk,
PGScrubChunkIsFree, PGScrubResched, etc.) -- for tens of seconds at a time,
regardless of their configured mclock reservation.

Add a bounded check: once the mclock-managed queue has gone unserviced for
osd_mclock_max_starve_time while high_priority keeps refilling,
force one dequeue attempt from it before resuming the high_priority drain.
No-op when the mclock queue is empty, so normal operation is unaffected.

Bound the starvation window on flash to 50ms via an internal constant --
scheduler_max_starve_time_ssd, and not a configuration option as this was
tested on real hardware.

But since no HDD test hardware has been available for this investigation,
rather than ship an unvalidated hardcoded constant with no adjustment path, a
configurable called osd_mclock_max_starve_time_hdd is introduced. Default
0.25s, bounded to [0.1s, 0.5s]. A modern 7200 RPM HDD's average random-access
time is roughly 10-15ms, so the configurable range remains a real, meaningful
multiple of that even at the tightest allowed setting. This allows an operator
some flexibility in case a given HDD fleet needs a different value.

Tests (src/test/osd/TestMClockScheduler.cc):
Add Unit Tests to exercise the starvation logic for SSD and HDD.

Documentation (doc/rados/configuration/mclock-config-ref.rst):
Add a new "mClock Queue Starvation Prevention" section explaining the
immediate/high-priority-vs-mclock-managed-queue starvation mechanism, the
bounded forced-yield fix, the device-aware threshold split and add
osd_mclock_max_starve_time_hdd to the list of config options.

Fixes: https://tracker.ceph.com/issues/69078
Signed-off-by: Sridhar Seshasayee <[email protected]>
@github-actions

Copy link
Copy Markdown

Config Diff Tool Output

+ added: osd_mclock_max_starve_time_hdd (osd.yaml.in)

The above configuration changes are found in the PR. Please update the relevant release documentation if necessary.
Ignore this comment if docs are already updated. To make the "Check ceph config changes" CI check pass, please comment /config check ok and re-run the test.

@sseshasa

sseshasa commented Aug 20, 2026 •

Copy link
Copy Markdown
Contributor Author

Test Report - Discusses results from more in-depth testing on a node with NVMe hardware.

@sseshasa

Copy link
Copy Markdown
Contributor Author

jenkins test api

@sseshasa

Copy link
Copy Markdown
Contributor Author

/config check ok

@sseshasa

Copy link
Copy Markdown
Contributor Author

jenkins test api

Comment on lines +251 to +252
The threshold is device-aware because the same absolute value does not make
sense across device types: a rotational op's own natural per-op service time

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed.

mclock_conf.put_mclock_counter(retn.client, op_type, time_queued);
last_mclock_service_time = crimson::dmclock::get_time();

return std::move(*retn.request);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ACK.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath14-testing-20260826.230942-main.

@sseshasa

sseshasa commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Re-working the PR as teuthology tests show that there's an issue with handling requeued ops. I will update more details soon.

@sseshasa sseshasa removed the needs-qa label Sep 2, 2026
@sseshasa

sseshasa commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Re-working the PR as teuthology tests show that there's an issue with handling requeued ops. I will update more details soon.

@rzarzynski A second commit (title: mClockScheduler: Reserve a requeued-item prio queue to prevent op-order aborts) is added that resolves the requeued ops issue. A subset of following teuthology tests that were failing before due to the requeued ops being scheduled out-of-order are now passing with the fix. See https://pulpito.ceph.com/sseshasa-2026-09-03_09:48:01-rados-wip-sseshasa-71205-req_testing-2026-09-03-distro-default-trial/. The sole failure in the run is unrelated to the fix and is a known issue.

Please review the above mentioned commit when possible. The first commit you reviewed earlier remains unchanged. Thanks!

…er aborts

The starvation-bound forced yield added to dequeue() could let a client-class
item still sitting in the mclock-managed queue get scheduled ahead of a
same-client item that had been pulled out of its normal queue position via
enqueue_front() (PG map-wait release, rwordered-dependency requeue, or a
PG-slot wake). In other words, this is a requeued item now in the high_priority
queue. enqueue_front() has no way to preserve such an item's position
relative to same-client siblings still in the mclock queue, since mClock does
not support inserting at the front of its own queue. So the item would be
redirected into high_priority instead, where a forced yield due to starvation
could release its sibling first, producing a client visible tid inversion and
resulting in "bad op order" abort.

Fix:
Give client class items enqueued via enqueue_front() a reserved
high_priority queue (requeued_class_priority, set to SchedulerClass::client's
own value purely so it documents itself) instead of priority 0, and gate the
starvation-bound forced yield so it never pulls from the mclock-managed
queue while requeued class priority queue is non-empty. The other
high_priority queues(MAX, >=cutoff_priority) and their drain remain unchanged.

The usage of the requeued-item high priority queue is scoped only for
client items that get requeued via enqueue_front(). Other classes like
background-recovery / background-best-effort that are not bound by
tid-ordering invariant get requeued as before in the priority 0 queue.

Gating the force yield on the presence of requeued client ops is expected to
be rare and bursty rather than sustained and therefore is not expected to
dilute the effectiveness of the starvation mechanism.

Tests:
src/test/osd/TestMclockScheduler.cc - Add unit tests to validate the
requeued_class_priority mechanics and maintaining op order invariant.

Fixes: https://tracker.ceph.com/issues/69078
Signed-off-by: Sridhar Seshasayee <[email protected]>
@sseshasa
sseshasa force-pushed the wip-fix-scrub-stalls-with-mclock branch from b8871be to cf5e5db Compare September 4, 2026 10:58
@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been removed from wip-bharath14-testing-20260826.230942-main.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath12-testing-20260907.061609-main.

@sseshasa

sseshasa commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants