From e4d547ede7f04c02f6514d466f534396f435b57e Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 17 Mar 2017 13:54:20 -0400 Subject: [PATCH] os/bluestore: simplify flush() wake-up condition Clearer, and fewer wakeups. Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 12 ++++++++---- src/os/bluestore/BlueStore.h | 18 +++++++++++++----- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 1cb89000b8e..bd3e215cf5e 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -7093,9 +7093,6 @@ void BlueStore::_txc_state_proc(TransContext *txc) } else { _txc_finalize_kv(txc, txc->t); txc->state = TransContext::STATE_KV_SUBMITTED; - if (txc->osr->kv_submitted_waiters) { - txc->osr->qcond.notify_all(); - } int r = db->submit_transaction(txc->t); assert(r == 0); _txc_applied_kv(txc); @@ -7181,6 +7178,11 @@ void BlueStore::_txc_finish_io(TransContext *txc) _txc_state_proc(&*p++); } while (p != osr->q.end() && p->state == TransContext::STATE_IO_DONE); + + if (osr->kv_submitted_waiters && + osr->_is_all_kv_submitted()) { + osr->qcond.notify_all(); + } } void BlueStore::_txc_write_nodes(TransContext *txc, KeyValueDB::Transaction t) @@ -7610,7 +7612,9 @@ void BlueStore::_kv_sync_thread() txc->state = TransContext::STATE_KV_SUBMITTED; if (txc->osr->kv_submitted_waiters) { std::lock_guard l(txc->osr->qlock); - txc->osr->qcond.notify_all(); + if (txc->osr->_is_all_kv_submitted()) { + txc->osr->qcond.notify_all(); + } } } if (num_aios) { diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 89ca1c532ea..87d436a18f6 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1578,14 +1578,22 @@ public: qcond.wait(l); } + bool _is_all_kv_submitted() { + // caller must hold qlock + if (q.empty()) { + return true; + } + TransContext *txc = &q.back(); + if (txc->state >= TransContext::STATE_KV_SUBMITTED) { + return true; + } + return false; + } + void flush() override { std::unique_lock l(qlock); while (true) { - if (q.empty()) { - return; - } - TransContext *txc = &q.back(); - if (txc->state >= TransContext::STATE_KV_SUBMITTED) { + if (_is_all_kv_submitted()) { return; } ++kv_submitted_waiters; -- 2.39.5