]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: prevent lock for almost "flush" calls 12524/head
authorHaomai Wang <haomai@xsky.com>
Fri, 16 Dec 2016 10:42:58 +0000 (18:42 +0800)
committerHaomai Wang <haomai@xsky.com>
Sat, 24 Dec 2016 16:05:53 +0000 (00:05 +0800)
Signed-off-by: Haomai Wang <haomai@xsky.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index e8ff586e6c5336bd3aabd47623703f2355501805..6732d8f101534c907351fb92f22a6a57aff4164f 100644 (file)
@@ -2365,10 +2365,12 @@ BlueStore::BlobRef BlueStore::ExtentMap::split_blob(
 
 void BlueStore::Onode::flush()
 {
-  std::unique_lock<std::mutex> 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<std::mutex> 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<std::mutex> 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<std::mutex> 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();
       }
index 0bfee14662af501d8f8fdf0c04043153e7d11f83..05a1da25ac3b516e08f23e21e6a82f32f7c9ebec 100644 (file)
@@ -804,6 +804,7 @@ public:
 
     ExtentMap extent_map;
 
+    std::atomic<int> flushing_count = {0};
     std::mutex flush_lock;  ///< protect flush_txns
     std::condition_variable flush_cond;   ///< wait here for unapplied txns
     set<TransContext*> flush_txns;   ///< committing or wal txns