From: Xuehan Xu Date: Wed, 27 Nov 2024 01:32:48 +0000 (+0800) Subject: crimson/osd/pg_recovery: throttle backfills together with pg-log based X-Git-Tag: v20.0.0~432^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=14e068fdc557a204cc3c5d3a646bc99c32b86028;p=ceph.git crimson/osd/pg_recovery: throttle backfills together with pg-log based recoveries Signed-off-by: Xuehan Xu --- diff --git a/src/crimson/osd/backfill_state.cc b/src/crimson/osd/backfill_state.cc index 1392ee330ac20..0ea9e6372f0d0 100644 --- a/src/crimson/osd/backfill_state.cc +++ b/src/crimson/osd/backfill_state.cc @@ -342,6 +342,7 @@ BackfillState::Enqueuing::Enqueuing(my_context ctx) do { if (!backfill_listener().budget_available()) { + DEBUGDPP("throttle failed, turning to Waiting", pg()); post_event(RequestWaiting{}); return; } else if (should_rescan_replicas(backfill_state().peer_backfill_info, diff --git a/src/crimson/osd/backfill_state.h b/src/crimson/osd/backfill_state.h index 463be4a7a2eb5..0217886832df6 100644 --- a/src/crimson/osd/backfill_state.h +++ b/src/crimson/osd/backfill_state.h @@ -62,6 +62,8 @@ struct BackfillState { struct CancelBackfill : sc::event { }; + struct ThrottleAcquired : sc::event { + }; private: // internal events struct RequestPrimaryScanning : sc::event { @@ -257,6 +259,7 @@ public: sc::transition, sc::custom_reaction, sc::custom_reaction, + sc::transition, sc::transition>; explicit Waiting(my_context); sc::result react(ObjectPushed); diff --git a/src/crimson/osd/osd_operation.h b/src/crimson/osd/osd_operation.h index 6376dabd04dbe..394375c11297b 100644 --- a/src/crimson/osd/osd_operation.h +++ b/src/crimson/osd/osd_operation.h @@ -341,6 +341,18 @@ public: with_throttle_while(std::forward(args)...), *this); } + // Returns std::nullopt if the throttle is acquired immediately, + // returns the future for the acquiring otherwise + std::optional> + try_acquire_throttle_now(crimson::osd::scheduler::params_t params) { + if (!max_in_progress || in_progress < max_in_progress) { + ++in_progress; + --pending; + return std::nullopt; + } + return acquire_throttle(params); + } + private: void dump_detail(Formatter *f) const final; diff --git a/src/crimson/osd/pg_recovery.cc b/src/crimson/osd/pg_recovery.cc index ec3af0d2b0006..5eef584c77671 100644 --- a/src/crimson/osd/pg_recovery.cc +++ b/src/crimson/osd/pg_recovery.cc @@ -67,8 +67,6 @@ PGRecovery::start_recovery_ops( if (max_to_start > 0) { max_to_start -= start_replica_recovery_ops(trigger, max_to_start, &started); } - using interruptor = - crimson::interruptible::interruptor; return interruptor::parallel_for_each(started, [] (auto&& ifut) { return std::move(ifut); @@ -609,8 +607,21 @@ void PGRecovery::update_peers_last_backfill( bool PGRecovery::budget_available() const { - // TODO: the limits! - return true; + crimson::osd::scheduler::params_t params = + {1, 0, crimson::osd::scheduler::scheduler_class_t::background_best_effort}; + auto &ss = pg->get_shard_services(); + auto futopt = ss.try_acquire_throttle_now(std::move(params)); + if (!futopt) { + return true; + } + std::ignore = interruptor::make_interruptible(std::move(*futopt) + ).then_interruptible([this] { + assert(!backfill_state->is_triggered()); + using BackfillState = crimson::osd::BackfillState; + backfill_state->process_event( + BackfillState::ThrottleAcquired{}.intrusive_from_this()); + }); + return false; } void PGRecovery::on_pg_clean() diff --git a/src/crimson/osd/pg_recovery.h b/src/crimson/osd/pg_recovery.h index 657e6d3e888c7..5c7b5c5ef2bf2 100644 --- a/src/crimson/osd/pg_recovery.h +++ b/src/crimson/osd/pg_recovery.h @@ -25,6 +25,8 @@ class PGBackend; class PGRecovery : public crimson::osd::BackfillState::BackfillListener { public: + using interruptor = + crimson::interruptible::interruptor; template using interruptible_future = RecoveryBackend::interruptible_future; PGRecovery(PGRecoveryListener* pg) : pg(pg) {} diff --git a/src/crimson/osd/shard_services.h b/src/crimson/osd/shard_services.h index f4d4b4c2eb4f5..f1ed9b8d91129 100644 --- a/src/crimson/osd/shard_services.h +++ b/src/crimson/osd/shard_services.h @@ -591,6 +591,7 @@ public: FORWARD_TO_OSD_SINGLETON(get_pool_info) FORWARD(with_throttle_while, with_throttle_while, local_state.throttler) + FORWARD(try_acquire_throttle_now, try_acquire_throttle_now, local_state.throttler) FORWARD_TO_OSD_SINGLETON(build_incremental_map_msg) FORWARD_TO_OSD_SINGLETON(send_incremental_map)