]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: keep statfs replica in memory to avoid expensive KV access
authorIgor Fedotov <ifedotov@mirantis.com>
Fri, 26 May 2017 12:33:05 +0000 (15:33 +0300)
committerIgor Fedotov <ifedotov@mirantis.com>
Thu, 8 Jun 2017 11:38:47 +0000 (04:38 -0700)
Signed-off-by: Igor Fedotov <ifedotov@mirantis.com>
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h

index 34e424c1f835d753f1d057bf73dd02939a3f6658..26bd3dac20e1401cdfe1a6da5d048bc32e656b99 100644 (file)
@@ -4678,6 +4678,24 @@ int BlueStore::_open_collections(int *errors)
   return 0;
 }
 
+void BlueStore::open_statfs()
+{
+  bufferlist bl;
+  int r = db->get(PREFIX_STAT, "bluestore_statfs", &bl);
+  if (r >= 0) {
+    if (size_t(bl.length()) >= sizeof(vstatfs.values)) {
+      auto it = bl.begin();
+      vstatfs.decode(it);
+    }
+    else {
+      dout(10) << __func__ << " store_statfs is corrupt, using empty" << dendl;
+    }
+  }
+  else {
+    dout(10) << __func__ << " store_statfs missed, using empty" << dendl;
+  }
+}
+
 int BlueStore::_setup_block_symlink_or_file(
   string name,
   string epath,
@@ -5792,27 +5810,16 @@ int BlueStore::statfs(struct store_statfs_t *buf)
     }
   }
 
-  bufferlist bl;
-  int r = db->get(PREFIX_STAT, "bluestore_statfs", &bl);
-  if (r >= 0) {
-     volatile_statfs vstatfs;
-     if (size_t(bl.length()) >= sizeof(vstatfs.values)) {
-       auto it = bl.begin();
-       vstatfs.decode(it);
-
-       buf->allocated = vstatfs.allocated();
-       buf->stored = vstatfs.stored();
-       buf->compressed = vstatfs.compressed();
-       buf->compressed_original = vstatfs.compressed_original();
-       buf->compressed_allocated = vstatfs.compressed_allocated();
-     } else {
-       dout(10) << __func__ << " store_statfs is corrupt, using empty" << dendl;
-     }
-  } else {
-    dout(10) << __func__ << " store_statfs missed, using empty" << dendl;
+  {
+    std::lock_guard<std::mutex> l(vstatfs_lock);
+    
+    buf->allocated = vstatfs.allocated();
+    buf->stored = vstatfs.stored();
+    buf->compressed = vstatfs.compressed();
+    buf->compressed_original = vstatfs.compressed_original();
+    buf->compressed_allocated = vstatfs.compressed_allocated();
   }
 
-
   dout(20) << __func__ << *buf << dendl;
   return 0;
 }
@@ -7370,6 +7377,7 @@ int BlueStore::_open_super_meta()
     dout(10) << __func__ << " min_alloc_size 0x" << std::hex << min_alloc_size
             << std::dec << dendl;
   }
+  open_statfs();
   _set_alloc_sizes();
   _set_throttle_params();
 
@@ -7483,6 +7491,11 @@ void BlueStore::_txc_update_store_statfs(TransContext *txc)
   logger->inc(l_bluestore_compressed_allocated, txc->statfs_delta.compressed_allocated());
   logger->inc(l_bluestore_compressed_original, txc->statfs_delta.compressed_original());
 
+  {
+    std::lock_guard<std::mutex> l(vstatfs_lock);
+    vstatfs += txc->statfs_delta;
+  }
+
   bufferlist bl;
   txc->statfs_delta.encode(bl);
 
@@ -8318,6 +8331,7 @@ void BlueStore::_kv_finalize_thread()
        _txc_state_proc(txc);
        kv_committed.pop_front();
       }
+
       for (auto b : deferred_stable) {
        auto p = b->txcs.begin();
        while (p != b->txcs.end()) {
index 66c8a26faf7ac155724b7416915419086f22ea9c..83fe45d275217dbcb55665c8ada253eec06b1263 100644 (file)
@@ -1408,6 +1408,12 @@ public:
     void reset() {
       *this = volatile_statfs();
     }
+    volatile_statfs& operator+=(const volatile_statfs& other) {
+      for (size_t i = 0; i < STATFS_LAST; ++i) {
+       values[i] += other.values[i];
+      }
+      return *this;
+    }
     int64_t& allocated() {
       return values[STATFS_ALLOCATED];
     }
@@ -1896,6 +1902,9 @@ private:
 
   // cache trim control
 
+  std::mutex vstatfs_lock;
+  volatile_statfs vstatfs;
+
   struct MempoolThread : public Thread {
     BlueStore *store;
     Cond cond;
@@ -1960,6 +1969,8 @@ private:
 
   int _open_super_meta();
 
+  void open_statfs();
+
   int _reconcile_bluefs_freespace();
   int _balance_bluefs_freespace(PExtentVector *extents);
   void _commit_bluefs_freespace(const PExtentVector& extents);