From 8c6e4d3d38664d1aab82bb973b1581a7c706343e Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Mon, 21 May 2018 22:46:12 +0800 Subject: [PATCH] os/bluefs: only flush dirty devices when do _fsync. 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& dirty_bdevs) which only flush dirty devices for this sync op. Signed-off-by: Jianpeng Ma --- src/os/bluestore/BlueFS.cc | 17 +++++++++++++++-- src/os/bluestore/BlueFS.h | 3 +++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index ee0f2e74793b0..b6b8c690058f2 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -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& l) void BlueFS::_flush_bdev_safely(FileWriter *h) { + std::array flush_devs = h->dirty_devs; + h->dirty_devs.fill(false); #ifdef HAVE_LIBAIO if (!cct->_conf->bluefs_sync_write) { list 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& 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. diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index 98714a8b8e14a..8e7113519b8cc 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -126,6 +126,7 @@ public: std::mutex lock; std::array iocv; ///< for each bdev + std::array 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& 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); -- 2.39.5