]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore/bluefs_type: avoid interator all extents when call func get_allocated. 14121/head
authorJianpeng Ma <jianpeng.ma@intel.com>
Mon, 27 Mar 2017 14:47:23 +0000 (22:47 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Tue, 28 Mar 2017 12:24:50 +0000 (20:24 +0800)
Only update extents it interator all extents to get allocated,
especially for recycling-log-file.

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

index 3f7fa0f2a0ce5d1595f90829db4b02a7a492cb71..aef7d1dba3db300c3e50dfe95466e3a8253dbe5e 100644 (file)
@@ -302,6 +302,7 @@ int BlueFS::mkfs(uuid_d osd_uuid)
     log_file->fnode.prefer_bdev,
     cct->_conf->bluefs_max_log_runway,
     &log_file->fnode.extents);
+  log_file->fnode.recalc_allocated();
   assert(r == 0);
   log_writer = _create_writer(log_file);
 
@@ -841,6 +842,7 @@ void BlueFS::_drop_link(FileRef file)
     }
     file_map.erase(file->fnode.ino);
     file->deleted = true;
+    file->fnode.recalc_allocated();
     if (file->dirty_seq) {
       assert(file->dirty_seq > log_seq_stable);
       assert(dirty_files.count(file->dirty_seq));
@@ -1099,10 +1101,12 @@ void BlueFS::_compact_log_sync()
 
   mempool::bluefs::vector<bluefs_extent_t> old_extents;
   old_extents.swap(log_file->fnode.extents);
+  log_file->fnode.recalc_allocated();
   while (log_file->fnode.get_allocated() < need) {
     int r = _allocate(log_file->fnode.prefer_bdev,
                      need - log_file->fnode.get_allocated(),
                      &log_file->fnode.extents);
+    log_file->fnode.recalc_allocated();
     assert(r == 0);
   }
 
@@ -1168,6 +1172,7 @@ void BlueFS::_compact_log_async(std::unique_lock<std::mutex>& l)
                      cct->_conf->bluefs_max_log_runway,
                      &log_file->fnode.extents);
     assert(r == 0);
+    log_file->fnode.recalc_allocated();
   }
   dout(10) << __func__ << " log extents " << log_file->fnode.extents << dendl;
 
@@ -1202,6 +1207,7 @@ void BlueFS::_compact_log_async(std::unique_lock<std::mutex>& l)
   int r = _allocate(BlueFS::BDEV_DB, new_log_jump_to,
                     &new_log->fnode.extents);
   assert(r == 0);
+  new_log->fnode.recalc_allocated();
   new_log_writer = _create_writer(new_log);
   new_log_writer->append(bl);
 
@@ -1252,6 +1258,8 @@ void BlueFS::_compact_log_async(std::unique_lock<std::mutex>& l)
 
   // swap the log files. New log file is the log file now.
   log_file->fnode.extents.swap(new_log->fnode.extents);
+  log_file->fnode.recalc_allocated();
+  new_log->fnode.recalc_allocated();
   log_writer->pos = log_writer->file->fnode.size =
     log_writer->pos - old_log_jump_to + new_log_jump_to;
 
@@ -1354,6 +1362,7 @@ int BlueFS::_flush_and_sync_log(std::unique_lock<std::mutex>& l,
                      cct->_conf->bluefs_max_log_runway,
                      &log_writer->file->fnode.extents);
     assert(r == 0);
+    log_writer->file->fnode.recalc_allocated();
     log_t.op_file_update(log_writer->file->fnode);
   }
 
@@ -1472,6 +1481,7 @@ int BlueFS::_flush_range(FileWriter *h, uint64_t offset, uint64_t length)
            << dendl;
       return r;
     }
+    h->file->fnode.recalc_allocated();
     if (cct->_conf->bluefs_preextend_wal_files &&
        h->writer_type == WRITER_WAL) {
       // NOTE: this *requires* that rocksdb also has log recycling
@@ -1831,6 +1841,7 @@ int BlueFS::_preallocate(FileRef f, uint64_t off, uint64_t len)
     int r = _allocate(f->fnode.prefer_bdev, want, &f->fnode.extents);
     if (r < 0)
       return r;
+    f->fnode.recalc_allocated();
     log_t.op_file_update(f->fnode);
   }
   return 0;
@@ -1919,6 +1930,7 @@ int BlueFS::open_for_write(
        pending_release[p.bdev].insert(p.offset, p.length);
       }
       file->fnode.extents.clear();
+      file->fnode.recalc_allocated();
     }
   }
   assert(file->fnode.ino > 1);
index 3d2717146798969f606256e32aed033fb878dee3..a340de2f121c5d6fb32aec065af63e86f6857b08 100644 (file)
@@ -138,6 +138,7 @@ void bluefs_fnode_t::decode(bufferlist::iterator& p)
   ::decode(prefer_bdev, p);
   ::decode(extents, p);
   DECODE_FINISH(p);
+  recalc_allocated();
 }
 
 void bluefs_fnode_t::dump(Formatter *f) const
index 06ef3b017dc56a186ca14d2bb6e2eaf6a3bb83d1..6586f32277f89b84f17d14da23631b5ae1bafb4e 100644 (file)
@@ -30,14 +30,18 @@ struct bluefs_fnode_t {
   utime_t mtime;
   uint8_t prefer_bdev;
   mempool::bluefs::vector<bluefs_extent_t> extents;
+  uint64_t allocated;
 
-  bluefs_fnode_t() : ino(0), size(0), prefer_bdev(0) {}
+  bluefs_fnode_t() : ino(0), size(0), prefer_bdev(0), allocated(0) {}
 
   uint64_t get_allocated() const {
-    uint64_t r = 0;
+    return allocated;
+  }
+
+  void recalc_allocated() {
+    allocated = 0;
     for (auto& p : extents)
-      r += p.length;
-    return r;
+      allocated += p.length;
   }
 
   mempool::bluefs::vector<bluefs_extent_t>::iterator seek(