Skip to content

crimson/osd: fix backfill deadlock in BackfillState::Waiting - #69824

Merged
mohit84 merged 2 commits into
ceph:mainfrom
mohit84:backfill_stuck
Jul 22, 2026
Merged

mohit84 merged 2 commits into
ceph:mainfrom
mohit84:backfill_stuck

Conversation

@mohit84

@mohit84 mohit84 commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

crimson/osd: fix backfill deadlock in BackfillState::Waiting

BackfillState::Enqueuing unconditionally posts RequestWaiting{}
when budget available return false. Waiting can exit only via
ObjectPushed which requires an in-flight push. If the budget
is exhausted with no pushes in flight no objectPush will ever
arrive and the PG stalls permanently.

Solution: Introduce a dedicated BudgetBlocked state. When budget_available()
is false and tracked_objects_completed()==true post RequestBudgetBlocked{}
instead of RequestWaiting{}.BudgetBlocked calls get_backfill_throttle()
to suspend until a slots free up, then fires BudgetAvailable{} which
transitions directly back to Enqueuing to dispatch the next batch of pushes.

Fixes: https://tracker.ceph.com/issues/77804

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.

@mohit84
mohit84 requested a review from a team as a code owner June 30, 2026 07:27
Comment thread src/crimson/osd/backfill_state.cc Outdated
// Enqueuing and re-checks budget_available() fresh.
DEBUGDPP("backfill budget unavailable with nothing in flight, "
"rescanning instead of entering Waiting", pg());
post_event(RequestPrimaryScanning{});

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.

I understand the problem - Waiting with nothing in flight deadlocks. I'm not sure if triggering a primary scan is the best solution.
Is it being used because the scan path waits on get_backfill_throttle()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes exactly but not because of this patch, the throttler was implemented in request primary scan via other pull request.I will try to find some other solution but do u have any approach how to wakeup after reach in Waiting state.

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.

I'm not completely sure either, maybe a new state that waits on get_backfill_throttle()?
@tchaikov @Matan-B what do you think?

@Matan-B Matan-B Jul 1, 2026 •

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.

RequestPrimaryScanning would create repeated scans:

  1. In Enqueuing - no budget AND no tracked objects
  2. RequestPrimaryScanning
  3. PrimaryScanned goes back to Enqueuing
  4. Back to 1

The problem here I think is the fact that Waiting is only suitable when there's an event that should wake it (i.e ObjectPushed).
As @amathuria suggested above, we should instead create a dedicated state that instead of reusing the existing Waiting one.

For example:

  1. In Enqueuing - no budget AND no tracked objects
  2. RequestBudgetBlocked goes to BudgetBlocked
  3. BudgetBlocked waits for a real retry path (e.g. budget becoming available / recovery requeue / explicit trigger).
  4. That event transitions back to Enqueuing (now that budget_available() should be true)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@Matan-B Matan-B left a comment

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.

Great catch! Though I think we should avoid busy looping over scanning - See comment.

Comment thread src/crimson/osd/backfill_state.cc Outdated
// Enqueuing and re-checks budget_available() fresh.
DEBUGDPP("backfill budget unavailable with nothing in flight, "
"rescanning instead of entering Waiting", pg());
post_event(RequestPrimaryScanning{});

@Matan-B Matan-B Jul 1, 2026 •

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.

RequestPrimaryScanning would create repeated scans:

  1. In Enqueuing - no budget AND no tracked objects
  2. RequestPrimaryScanning
  3. PrimaryScanned goes back to Enqueuing
  4. Back to 1

The problem here I think is the fact that Waiting is only suitable when there's an event that should wake it (i.e ObjectPushed).
As @amathuria suggested above, we should instead create a dedicated state that instead of reusing the existing Waiting one.

For example:

  1. In Enqueuing - no budget AND no tracked objects
  2. RequestBudgetBlocked goes to BudgetBlocked
  3. BudgetBlocked waits for a real retry path (e.g. budget becoming available / recovery requeue / explicit trigger).
  4. That event transitions back to Enqueuing (now that budget_available() should be true)

@Matan-B Matan-B added this to Crimson Jul 1, 2026
@Matan-B Matan-B moved this to In Progress in Crimson Jul 1, 2026
@mohit84 mohit84 changed the title crimson/osd: Avoid in BackfillState::Waiting when no inflight objects crimson/osd: fix backfill deadlock in BackfillState::Waiting Jul 6, 2026
@mohit84 mohit84 moved this from In Progress to Awaits review in Crimson Jul 6, 2026
@mohit84
mohit84 requested a review from ronen-fr July 6, 2026 05:18
Comment thread src/crimson/osd/pg_recovery.cc Outdated
"(pg cleaned or interval changed)", *pg->get_dpp());
return;
}
backfill_state->process_event(

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.

When posting BudgetAvailable from the async throttle callback, let's use the same is_triggered() / post_event vs process_event pattern as enqueue_push does for ObjectPushed?

process_event runs the event immediately. post_event queues it until the current dispatch finishes. If the get_backfill_throttle grants a slot right away, the callback can run while we're still entering BudgetBlocked (processing RequestBudgetBlocked). Calling process_event there would nest one event inside another and can confuse the state machine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/crimson/osd/backfill_state.h Outdated
struct BudgetBlocked : sc::state<BudgetBlocked, BackfillMachine>,
StateHelper<BudgetBlocked> {
using reactions = boost::mpl::list<
sc::transition<BudgetAvailable, Enqueuing>,

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.

BudgetAvailable probably needs a custom_reaction here — with a direct
transition we'd enter Enqueuing even while suspended. Should match
Waiting::react(ObjectPushed) and check if (!backfill_state().is_suspended()).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/crimson/osd/pg_recovery.cc Outdated
LOG_PREFIX(PGRecovery::request_budget_retry);
DEBUGDPP("budget unavailable with nothing in flight, "
"waiting for throttle slot", *pg->get_dpp());
std::ignore = get_backfill_throttle()

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.

nit: Could we coroutinise this to match do_request_primary_scan /
do_request_replica_scan? A do_request_budget_retry() coroutine would make
interruption handling cleaner and keeps the backfill listener code consistent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

Comment thread src/crimson/osd/pg_recovery.cc Outdated
LOG_PREFIX(PGRecovery::request_budget_retry);
DEBUGDPP("budget unavailable with nothing in flight, "
"waiting for throttle slot", *pg->get_dpp());
std::ignore = get_backfill_throttle()

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.

we probably should not drop the releaser immediately. instead, we should release it after done with the requested budget.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@amathuria

Copy link
Copy Markdown
Contributor

@mohit84 make check seems to be failing on test_backfill.cc, could you check it out?

@github-actions github-actions Bot added the tests label Jul 8, 2026
@mohit84

mohit84 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test make check

@mohit84

mohit84 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

@mohit84 make check seems to be failing on test_backfill.cc, could you check it out?

done

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.

@mohit84 I had a doubt here - remove_on_peers() only calls enqueue_drop(). budget_retry_releaser is only reset in enqueue_push(), so a delete-only pass through Enqueuing → Waiting can leave the slot held until on_activate_complete? Is that okay? Just checking.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I agree we can release a slot in enqueue_drop also otherwise it is unnecessary waste the slot.

@amathuria amathuria left a comment

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.

Thanks for addressing the comments!
LGTM

Comment thread src/crimson/osd/pg_recovery.cc Resolved
@mohit84

mohit84 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

jenkins retest windows

@mohit84

mohit84 commented Jul 10, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@mohit84
mohit84 requested a review from Matan-B July 10, 2026 09:12

@Matan-B Matan-B left a comment

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.

Comment thread src/crimson/osd/pg_recovery.cc Resolved
Comment thread src/crimson/osd/pg_recovery.cc Outdated
Comment on lines +733 to +735
} catch (const crimson::common::interruption& e) {
DEBUGDPP("budget retry interrupted: {}", *pg->get_dpp(), e.what());
co_return;

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.

interrupts are not caught using try catch.
Please see test_crimson_coroutine.cc for examples or crimson/common/coroutine.h for the implementation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@Matan-B Matan-B moved this from Awaits review to In Progress in Crimson Jul 13, 2026
mohit84 and others added 2 commits July 14, 2026 10:28
BackfillState::Enqueuing unconditionally posts RequestWaiting{}
when budget available return false. Waiting can exit only via
ObjectPushed which requires an in-flight push. If the budget
is exhausted with no pushes in flight no objectPush will ever
arrive and the PG stalls permanently.

Solution: Introduce a dedicated BudgetBlocked state. When budget_available()
is false and tracked_objects_completed()==true post RequestBudgetBlocked{}
instead of RequestWaiting{}.BudgetBlocked calls get_backfill_throttle()
to suspend until a slots free up, then fires BudgetAvailable{} which
transitions directly back to Enqueuing to dispatch the next batch of pushes.

Fixes: https://tracker.ceph.com/issues/77804
Signed-off-by: Mohit Agrawal <[email protected]>
@mohit84

mohit84 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor Author

"crimson/osd: Resolved reviewer comment" is not a proper commit message. Please see https://github.com/ceph/ceph/blob/main/SubmittingPatches.rst#describe-your-changes

done

1 similar comment
@mohit84

mohit84 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

"crimson/osd: Resolved reviewer comment" is not a proper commit message. Please see https://github.com/ceph/ceph/blob/main/SubmittingPatches.rst#describe-your-changes

done

@mohit84

mohit84 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

jenkins test windows

@Matan-B
Matan-B dismissed their stale review July 22, 2026 11:06

stale

@mohit84
mohit84 merged commit 95a007b into ceph:main Jul 22, 2026
6 checks passed
@github-actions

Copy link
Copy Markdown

This is an automated message by src/script/redmine-upkeep.py.

I have resolved the following tracker ticket due to the merge of this PR:

No backports are pending for the ticket. If this is incorrect, please update the tracker
ticket and reset to Pending Backport state.

Update Log: https://github.com/ceph/ceph/actions/runs/29919611854

@Matan-B Matan-B moved this from In Progress to Merged (Main) in Crimson Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Merged (Main)

Development

Successfully merging this pull request may close these issues.

4 participants