From cb1800fb19e65014f837184a2c6a61d04e1da039 Mon Sep 17 00:00:00 2001 From: xie xingguo Date: Thu, 6 Jul 2017 12:17:19 +0800 Subject: [PATCH] osd/OSD: move send_beacon into tick_without_osd_lock So we don't ask for the big osd_lock, which is potential expensive and shall be avoided under any cases. Also re-use min_last_epoch_clean_lock to access last_sent_beacon safely(we have two callers - ms_handle_connect and tick_without_osd_lock, hence may have potential races). Signed-off-by: xie xingguo --- src/osd/OSD.cc | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index efe593dd8949a..bcf65f5d812ea 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -4969,15 +4969,6 @@ void OSD::tick() do_waiters(); tick_timer.add_event_after(OSD_TICK_INTERVAL, new C_Tick(this)); - - if (is_active()) { - const auto now = ceph::coarse_mono_clock::now(); - const auto elapsed = now - last_sent_beacon; - if (chrono::duration_cast(elapsed).count() > - cct->_conf->osd_beacon_report_interval) { - send_beacon(now); - } - } } void OSD::tick_without_osd_lock() @@ -5066,6 +5057,20 @@ void OSD::tick_without_osd_lock() sched_scrub(); } service.promote_throttle_recalibrate(); + bool need_send_beacon = false; + const auto now = ceph::coarse_mono_clock::now(); + { + // borrow lec lock to pretect last_sent_beacon from changing + Mutex::Locker l{min_last_epoch_clean_lock}; + const auto elapsed = now - last_sent_beacon; + if (chrono::duration_cast(elapsed).count() > + cct->_conf->osd_beacon_report_interval) { + need_send_beacon = true; + } + } + if (need_send_beacon) { + send_beacon(now); + } } check_ops_in_flight(); @@ -6044,12 +6049,12 @@ void OSD::send_beacon(const ceph::coarse_mono_clock::time_point& now) monmap.get_required_features().contains_all( ceph::features::mon::FEATURE_LUMINOUS)) { dout(20) << __func__ << " sending" << dendl; - last_sent_beacon = now; MOSDBeacon* beacon = nullptr; { Mutex::Locker l{min_last_epoch_clean_lock}; beacon = new MOSDBeacon(osdmap->get_epoch(), min_last_epoch_clean); std::swap(beacon->pgs, min_last_epoch_clean_pgs); + last_sent_beacon = now; } monc->send_mon_message(beacon); } else { -- 2.39.5