]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluefs: only flush dirty devices when do _fsync. 22110/head
authorJianpeng Ma <jianpeng.ma@intel.com>
Mon, 21 May 2018 14:46:12 +0000 (22:46 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Tue, 22 May 2018 08:46:55 +0000 (16:46 +0800)
Now _fsync call flush_bdev make data safely. But flush_bdev flush all
devices which don't care whether has data for this sync.
So add new api flush_bdev(std::array<bool, MAX_BDEV>& dirty_bdevs)
which only flush dirty devices for this sync op.

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
src/os/bluestore/BlueFS.cc
src/os/bluestore/BlueFS.h

index ee0f2e74793b0dde50f1e78c07e1421c11b30f1b..b6b8c690058f2efd307e7988c93a561c3f375139 100644 (file)
@@ -1794,6 +1794,7 @@ int BlueFS::_flush_range(FileWriter *h, uint64_t offset, uint64_t length)
     } else {
       bdev[p->bdev]->aio_write(p->offset + x_off, t, h->iocv[p->bdev], buffered);
     }
+    h->dirty_devs[p->bdev] = true;
     bloff += x_len;
     length -= x_len;
     ++p;
@@ -1928,6 +1929,8 @@ int BlueFS::_fsync(FileWriter *h, std::unique_lock<std::mutex>& l)
 
 void BlueFS::_flush_bdev_safely(FileWriter *h)
 {
+  std::array<bool, MAX_BDEV> flush_devs = h->dirty_devs;
+  h->dirty_devs.fill(false);
 #ifdef HAVE_LIBAIO
   if (!cct->_conf->bluefs_sync_write) {
     list<aio_t> completed_ios;
@@ -1935,17 +1938,27 @@ void BlueFS::_flush_bdev_safely(FileWriter *h)
     lock.unlock();
     wait_for_aio(h);
     completed_ios.clear();
-    flush_bdev();
+    flush_bdev(flush_devs);
     lock.lock();
   } else
 #endif
   {
     lock.unlock();
-    flush_bdev();
+    flush_bdev(flush_devs);
     lock.lock();
   }
 }
 
+void BlueFS::flush_bdev(std::array<bool, MAX_BDEV>& dirty_bdevs)
+{
+  // NOTE: this is safe to call without a lock.
+  dout(20) << __func__ << dendl;
+  for (unsigned i = 0; i < MAX_BDEV; i++) {
+    if (dirty_bdevs[i])
+      bdev[i]->flush();
+  }
+}
+
 void BlueFS::flush_bdev()
 {
   // NOTE: this is safe to call without a lock.
index 98714a8b8e14a874c5e81e27ea70ed2ff57ca56f..8e7113519b8cc5e4be2824f893e71eb0583ca708 100644 (file)
@@ -126,6 +126,7 @@ public:
 
     std::mutex lock;
     std::array<IOContext*,MAX_BDEV> iocv; ///< for each bdev
+    std::array<bool, MAX_BDEV> dirty_devs;
 
     FileWriter(FileRef f)
       : file(f),
@@ -134,6 +135,7 @@ public:
                          g_conf->bluefs_alloc_size / CEPH_PAGE_SIZE)) {
       ++file->num_writers;
       iocv.fill(nullptr);
+      dirty_devs.fill(false);
     }
     // NOTE: caller must call BlueFS::close_writer()
     ~FileWriter() {
@@ -292,6 +294,7 @@ private:
 
   void _flush_bdev_safely(FileWriter *h);
   void flush_bdev();  // this is safe to call without a lock
+  void flush_bdev(std::array<bool, MAX_BDEV>& dirty_bdevs);  // this is safe to call without a lock
 
   int _preallocate(FileRef f, uint64_t off, uint64_t len);
   int _truncate(FileWriter *h, uint64_t off);