]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
NVMEDevice: make flush wait for all write completed
authorHaomai Wang <haomai@xsky.com>
Sun, 17 Jan 2016 15:21:29 +0000 (23:21 +0800)
committerHaomai Wang <haomai@xsky.com>
Mon, 1 Feb 2016 14:00:47 +0000 (22:00 +0800)
Signed-off-by: Haomai Wang <haomai@xsky.com>
src/os/bluestore/NVMEDevice.cc
src/os/bluestore/NVMEDevice.h

index af78b5cfe03662f0adf853eb83e5e98c182b5f94..623c3b0b4a6986a8b4e1014c189b367a02e63e8b 100644 (file)
@@ -317,6 +317,8 @@ NVMEDevice::NVMEDevice(aio_callback_t cb, void *cbpriv)
       queue_empty(1),
       queue_lock("NVMEDevice::queue_lock"),
       aio_thread(this),
+      flush_lock("NVMEDevice::flush_lock"),
+      flush_waiters(0),
       logger(nullptr),
       inflight_ops(0),
       aio_callback(cb),
@@ -418,6 +420,7 @@ void NVMEDevice::_aio_thread()
       if (queue_empty.read()) {
         if (aio_stop)
           break;
+        assert(flush_waiters.read() == 0);
         queue_cond.Wait(queue_lock);
       }
     }
@@ -477,6 +480,10 @@ void NVMEDevice::_aio_thread()
       }
     } else if (!inflight_ops.read()) {
       dout(20) << __func__ << " idle, have a pause" << dendl;
+      if (flush_waiters.read()) {
+        Mutex::Locker l(flush_lock);
+        flush_cond.Signal();
+      }
 #ifdef HAVE_SSE
       _mm_pause();
 #else
@@ -494,6 +501,16 @@ void NVMEDevice::_aio_thread()
 int NVMEDevice::flush()
 {
   dout(10) << __func__ << " start" << dendl;
+  if (inflight_ops.read()) {
+    // TODO: this may contains read op
+    dout(1) << __func__ << " existed inflight ops " << inflight_ops.read() << dendl;
+    Mutex::Locker l(flush_lock);
+    flush_waiters.inc();
+    while (inflight_ops.read()) {
+      flush_cond.Wait(flush_lock);
+    }
+    flush_waiters.dec();
+  }
   return 0;
   // nvme device will cause terriable performance degraded
   // while issuing flush command
index 96cfd1c8e07ef4fd6c9438cdf67e97cc65575e51..3825c590b6db4bcf999add9faa8ffbc8fd6e8f44 100644 (file)
@@ -92,6 +92,10 @@ class NVMEDevice : public BlockDevice {
 
   void _aio_thread();
 
+  Mutex flush_lock;
+  Cond flush_cond;
+  atomic_t flush_waiters;
+
   static void init();
 
  public: