From aaad3facdaac4f025e00807d02f8fbaf5ce869a9 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Wed, 1 Mar 2017 16:54:39 +0100 Subject: [PATCH] os/bluestore: remove unneeded indirection in BitMapZone. 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 --- src/os/bluestore/BitAllocator.cc | 14 ++++++-------- src/os/bluestore/BitAllocator.h | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/os/bluestore/BitAllocator.cc b/src/os/bluestore/BitAllocator.cc index 238f5f36dfc..8a07030138c 100644 --- a/src/os/bluestore/BitAllocator.cc +++ b/src/os/bluestore/BitAllocator.cc @@ -355,8 +355,7 @@ void BitMapZone::init(int64_t zone_num, int64_t total_blocks, bool def) alloc_assert(total_blocks < std::numeric_limits::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 iter = BitMapEntityIter( - 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 iter = BitMapEntityIter( - 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); diff --git a/src/os/bluestore/BitAllocator.h b/src/os/bluestore/BitAllocator.h index e12b256e2c8..082a8c15324 100644 --- a/src/os/bluestore/BitAllocator.h +++ b/src/os/bluestore/BitAllocator.h @@ -311,7 +311,7 @@ class BitMapZone: public BitMapArea{ private: std::atomic m_used_blocks; - BmapEntryVector *m_bmap_list; + BmapEntryVector m_bmap_vec; std::mutex m_lock; public: -- 2.39.5