From 4e5d36f2928bcbc0d99c4181ee4d40bfdc50f0be Mon Sep 17 00:00:00 2001 From: Haomai Wang Date: Fri, 16 Dec 2016 18:42:58 +0800 Subject: [PATCH] os/bluestore: prevent lock for almost "flush" calls Signed-off-by: Haomai Wang --- src/os/bluestore/BlueStore.cc | 13 +++++++++---- src/os/bluestore/BlueStore.h | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index e8ff586e6c533..6732d8f101534 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -2365,10 +2365,12 @@ BlueStore::BlobRef BlueStore::ExtentMap::split_blob( void BlueStore::Onode::flush() { - std::unique_lock l(flush_lock); - ldout(c->store->cct, 20) << __func__ << " " << flush_txns << dendl; - while (!flush_txns.empty()) - flush_cond.wait(l); + if (flushing_count) { + std::unique_lock l(flush_lock); + ldout(c->store->cct, 20) << __func__ << " " << flush_txns << dendl; + while (!flush_txns.empty()) + flush_cond.wait(l); + } ldout(c->store->cct, 20) << __func__ << " done" << dendl; } @@ -6501,6 +6503,7 @@ void BlueStore::_txc_write_nodes(TransContext *txc, KeyValueDB::Transaction t) std::lock_guard l(o->flush_lock); o->flush_txns.insert(txc); + o->flushing_count++; } // objects we modified but didn't affect the onode @@ -6509,6 +6512,7 @@ void BlueStore::_txc_write_nodes(TransContext *txc, KeyValueDB::Transaction t) if (txc->onodes.count(*p) == 0) { std::lock_guard l((*p)->flush_lock); (*p)->flush_txns.insert(txc); + (*p)->flushing_count++; ++p; } else { // remove dups with onodes list to avoid problems in _txc_finish @@ -6585,6 +6589,7 @@ void BlueStore::_txc_finish(TransContext *txc) << dendl; assert(o->flush_txns.count(txc)); o->flush_txns.erase(txc); + o->flushing_count--; if (o->flush_txns.empty()) { o->flush_cond.notify_all(); } diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 0bfee14662af5..05a1da25ac3b5 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -804,6 +804,7 @@ public: ExtentMap extent_map; + std::atomic flushing_count = {0}; std::mutex flush_lock; ///< protect flush_txns std::condition_variable flush_cond; ///< wait here for unapplied txns set flush_txns; ///< committing or wal txns -- 2.39.5