]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
os/bluestore: remove unneeded indirection in BitMapZone.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Wed, 1 Mar 2017 15:54:39 +0000 (16:54 +0100)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 2 Mar 2017 23:20:29 +0000 (00:20 +0100)
BitMapZone aggregates BmapEntries through a pointer to independently-
allocated std::vector which in turn has its own pointer to the real
data. This indirection is unnecessary as std::vector is pretty cheap
in the terms of memory overhead. For instance, on x86-64 & GCC 5.4.0
sizeof(std::vector) == 24, which translates to 3 raw pointers.

Stripping the indirection could have positive impact on processor's
caches and allow to minimize the number of memory accesses.

Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/os/bluestore/BitAllocator.cc
src/os/bluestore/BitAllocator.h

index 238f5f36dfc9ae7c56cc30fa040d9bc0a0842a43..8a07030138c6ba0bbfebbb10fbf81e9575a10536 100644 (file)
@@ -355,8 +355,7 @@ void BitMapZone::init(int64_t zone_num, int64_t total_blocks, bool def)
   alloc_assert(total_blocks < std::numeric_limits<int32_t>::max());
   alloc_assert(!(total_blocks % BmapEntry::size()));
 
-  BmapEntryVector *bmaps = new BmapEntryVector(num_bmaps, BmapEntry(cct, def));
-  m_bmap_list = bmaps;
+  m_bmap_vec.resize(num_bmaps, BmapEntry(cct, def));
   incr_count();
 }
 
@@ -412,7 +411,6 @@ void BitMapZone::shutdown()
 
 BitMapZone::~BitMapZone()
 {
-  delete m_bmap_list;
 }
 
 /*
@@ -432,7 +430,7 @@ bool BitMapZone::is_allocated(int64_t start_block, int64_t num_blocks)
 
   while (num_blocks) {
     bit = start_block % BmapEntry::size();
-    bmap = &(*m_bmap_list)[start_block / BmapEntry::size()];
+    bmap = &m_bmap_vec[start_block / BmapEntry::size()];
     falling_in_bmap = MIN(num_blocks, BmapEntry::size() - bit);
 
     if (!bmap->is_allocated(bit, falling_in_bmap)) {
@@ -455,7 +453,7 @@ void BitMapZone::set_blocks_used(int64_t start_block, int64_t num_blocks)
 
   while (blks) {
     bit = start_block % BmapEntry::size();
-    bmap = &(*m_bmap_list)[start_block / BmapEntry::size()];
+    bmap = &m_bmap_vec[start_block / BmapEntry::size()];
     falling_in_bmap = MIN(blks, BmapEntry::size() - bit);
 
     bmap->set_bits(bit, falling_in_bmap);
@@ -481,7 +479,7 @@ void BitMapZone::free_blocks_int(int64_t start_block, int64_t num_blocks)
 
   while (count) {
     bit = first_blk % BmapEntry::size();
-    bmap = &(*m_bmap_list)[first_blk / BmapEntry::size()];
+    bmap = &m_bmap_vec[first_blk / BmapEntry::size()];
     falling_in_bmap = MIN(count, BmapEntry::size() - bit);
 
     bmap->clear_bits(bit, falling_in_bmap);
@@ -541,7 +539,7 @@ int64_t BitMapZone::alloc_blocks_dis(int64_t num_blocks,
   alloc_assert(check_locked());
 
   BitMapEntityIter <BmapEntry> iter = BitMapEntityIter<BmapEntry>(
-          m_bmap_list, bmap_idx);
+          &m_bmap_vec, bmap_idx);
   bmap = iter.next();
   if (!bmap) {
     return 0;
@@ -624,7 +622,7 @@ void BitMapZone::dump_state(int& count)
   BmapEntry *bmap = NULL;
   int bmap_idx = 0;
   BitMapEntityIter <BmapEntry> iter = BitMapEntityIter<BmapEntry>(
-          m_bmap_list, 0);
+          &m_bmap_vec, 0);
   dout(0) << __func__ << " zone " << count << " dump start " << dendl;
   while ((bmap = (BmapEntry *) iter.next())) {
     bmap->dump_state(cct, bmap_idx);
index e12b256e2c876358d3eb104a45bb9fc871be3457..082a8c15324fd0fc55e53f532371500e86e6d52b 100644 (file)
@@ -311,7 +311,7 @@ class BitMapZone: public BitMapArea{
 
 private:
   std::atomic<int32_t> m_used_blocks;
-  BmapEntryVector *m_bmap_list;
+  BmapEntryVector m_bmap_vec;
   std::mutex m_lock;
 
 public: