From 2d0d375809472d902fa706bb3f19e08f1bfbe2e9 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 9 Mar 2017 18:05:48 -0500 Subject: [PATCH] os/bluestore: make Sequencer::flush() more efficient BlueStore collection methods only need preceding transactions to be applied to the kv db; they do not need to be committed. Note that this is *only* needed for collection listings; all other read operations are immediately safe after queue_transactions(). Signed-off-by: Sage Weil --- src/os/bluestore/BlueStore.cc | 7 +++++++ src/os/bluestore/BlueStore.h | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 374e55c5736..19436c81e69 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -7139,6 +7139,9 @@ 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); @@ -7577,6 +7580,10 @@ void BlueStore::_kv_sync_thread() _txc_applied_kv(txc); --txc->osr->kv_committing_serially; txc->state = TransContext::STATE_KV_SUBMITTED; + if (txc->osr->kv_submitted_waiters) { + std::lock_guard l(txc->osr->qlock); + txc->osr->qcond.notify_all(); + } } for (auto txc : kv_committing) { if (txc->had_ios) { diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 2e428d1cea3..658c8b0b801 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -1539,6 +1539,8 @@ public: std::atomic_int kv_committing_serially = {0}; + std::atomic_int kv_submitted_waiters = {0}; + OpSequencer(CephContext* cct) //set the qlock to PTHREAD_MUTEX_RECURSIVE mode : Sequencer_impl(cct), @@ -1554,16 +1556,26 @@ public: q.push_back(*txc); } - void flush() override { + void drain() { std::unique_lock l(qlock); while (!q.empty()) qcond.wait(l); } - void drain() { + void flush() override { std::unique_lock l(qlock); - while (!q.empty()) + while (true) { + if (q.empty()) { + return; + } + TransContext *txc = &q.back(); + if (txc->state >= TransContext::STATE_KV_SUBMITTED) { + return; + } + ++kv_submitted_waiters; qcond.wait(l); + --kv_submitted_waiters; + } } bool flush_commit(Context *c) override { -- 2.39.5