]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/BlockDevice: make flush a no-op if there was no IO
authorSage Weil <sage@redhat.com>
Tue, 5 Jan 2016 03:04:28 +0000 (22:04 -0500)
committerSage Weil <sage@redhat.com>
Fri, 8 Jan 2016 18:10:18 +0000 (13:10 -0500)
fdatasync(2) does a cache flush on the device, which we want to avoid if
we didn't actually write anything.

Signed-off-by: Sage Weil <sage@redhat.com>
src/os/bluestore/BlockDevice.cc
src/os/bluestore/BlockDevice.h

index 0dbe095fb71daa1f88ee985b776b5e4703d781c6..13607ad2b84c4492aae5b46eca96ad1bbdfac6ab 100644 (file)
@@ -46,6 +46,7 @@ BlockDevice::BlockDevice(aio_callback_t cb, void *cbpriv)
     fs(NULL), aio(false), dio(false),
     debug_lock("BlockDevice::debug_lock"),
     ioc_reap_lock("BlockDevice::ioc_reap_lock"),
+    flush_lock("BlockDevice::flush_lock"),
     aio_queue(g_conf->bdev_aio_max_queue_depth),
     aio_callback(cb),
     aio_callback_priv(cbpriv),
@@ -165,7 +166,15 @@ void BlockDevice::close()
 
 int BlockDevice::flush()
 {
+  // serialize flushers, so that we can avoid weird io_since_flush
+  // races (w/ multipler flushers).
+  Mutex::Locker l(flush_lock);
+  if (io_since_flush.read() == 0) {
+    dout(10) << __func__ << " no-op (no ios since last flush)" << dendl;
+    return 0;
+  }
   dout(10) << __func__ << " start" << dendl;
+  io_since_flush.set(0);
   if (g_conf->bdev_inject_crash) {
     // sleep for a moment to give other threads a chance to submit or
     // wait on io that races with a flush.
@@ -409,6 +418,8 @@ int BlockDevice::aio_write(
       ::sync_file_range(fd_buffered, off, len, SYNC_FILE_RANGE_WRITE);
     }
   }
+
+  io_since_flush.set(1);
   return 0;
 }
 
index f5acc1113d95421298cd26825a1fb3e697228ed8..77bb8eb49b1a1b2e0f9e1c42efd2eb6633b6c840 100644 (file)
@@ -59,6 +59,9 @@ private:
   vector<IOContext*> ioc_reap_queue;
   atomic_t ioc_reap_count;
 
+  Mutex flush_lock;
+  atomic_t io_since_flush;
+
   FS::aio_queue_t aio_queue;
   aio_callback_t aio_callback;
   void *aio_callback_priv;