From 981d4c77040d2648d69f7ee862737183386c4b88 Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Fri, 19 Jul 2019 21:20:19 +0800 Subject: [PATCH] os/bluestore: Reduce unnecessary wakeups. Add bool kv_sync_in_progress to indicate thread kv_sync_thread is running or waiting. Only wake up if thread waiting. Signed-off-by: Jianpeng Ma --- src/os/bluestore/BlueStore.cc | 26 +++++++++++++++++++++----- src/os/bluestore/BlueStore.h | 1 + 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 10742c7dd60a4..4dac4bff8c4f3 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -9912,7 +9912,10 @@ void BlueStore::_txc_state_proc(TransContext *txc) { std::lock_guard l(kv_lock); kv_queue.push_back(txc); - kv_cond.notify_one(); + if (!kv_sync_in_progress) { + kv_sync_in_progress = true; + kv_cond.notify_one(); + } if (txc->state != TransContext::STATE_KV_SUBMITTED) { kv_queue_unsubmitted.push_back(txc); ++txc->osr->kv_committing_serially; @@ -10294,7 +10297,10 @@ void BlueStore::_osr_drain_preceding(TransContext *txc) { // wake up any previously finished deferred events std::lock_guard l(kv_lock); - kv_cond.notify_one(); + if (!kv_sync_in_progress) { + kv_sync_in_progress = true; + kv_cond.notify_one(); + } } osr->drain_preceding(txc); --deferred_aggressive; @@ -10317,7 +10323,10 @@ void BlueStore::_osr_drain(OpSequencer *osr) { // wake up any previously finished deferred events std::lock_guard l(kv_lock); - kv_cond.notify_one(); + if (!kv_sync_in_progress) { + kv_sync_in_progress = true; + kv_cond.notify_one(); + } } osr->drain(); --deferred_aggressive; @@ -10450,6 +10459,7 @@ void BlueStore::_kv_sync_thread() if (kv_stop) break; dout(20) << __func__ << " sleep" << dendl; + kv_sync_in_progress = false; kv_cond.wait(l); dout(20) << __func__ << " wake" << dendl; } else { @@ -10930,7 +10940,10 @@ void BlueStore::_deferred_aio_finish(OpSequencer *osr) // catch us on the next commit anyway. if (deferred_aggressive) { std::lock_guard l(kv_lock); - kv_cond.notify_one(); + if (!kv_sync_in_progress) { + kv_sync_in_progress = true; + kv_cond.notify_one(); + } } } @@ -11048,7 +11061,10 @@ int BlueStore::queue_transactions( { // wake up any previously finished deferred events std::lock_guard l(kv_lock); - kv_cond.notify_one(); + if (!kv_sync_in_progress) { + kv_sync_in_progress = true; + kv_cond.notify_one(); + } } throttle_deferred_bytes.get(txc->cost); --deferred_aggressive; diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 52b2d701b14f0..d3ed51e860181 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1951,6 +1951,7 @@ private: deque kv_queue_unsubmitted; ///< ready, need submit by kv thread deque kv_committing; ///< currently syncing deque deferred_done_queue; ///< deferred ios done + bool kv_sync_in_progress = false; KVFinalizeThread kv_finalize_thread; ceph::mutex kv_finalize_lock = ceph::make_mutex("BlueStore::kv_finalize_lock"); -- 2.39.5