From aa2146de7703e5a656b6a4180d327e5daa68dc78 Mon Sep 17 00:00:00 2001 From: Ramesh Chander Date: Fri, 11 Nov 2016 15:08:33 -0500 Subject: [PATCH] mempool changes for bitmap allocator [with bstore_balloc -> bluestore_alloc rename by sage] Signed-off-by: Ramesh Chander --- src/include/mempool.h | 1 + src/os/bluestore/Allocator.h | 6 +++--- src/os/bluestore/BitAllocator.cc | 9 ++++++++- src/os/bluestore/BitAllocator.h | 20 +++++++++++++++----- src/os/bluestore/BitMapAllocator.cc | 6 +++--- src/os/bluestore/BitMapAllocator.h | 6 +++--- src/os/bluestore/BlueFS.cc | 3 +-- src/os/bluestore/BlueStore.cc | 3 +-- src/os/bluestore/StupidAllocator.cc | 8 ++++++-- src/os/bluestore/StupidAllocator.h | 2 +- src/os/bluestore/bluestore_types.h | 12 +++++++----- src/test/objectstore/Allocator_test.cc | 14 +++++++------- src/test/objectstore/BitAllocator_test.cc | 14 +++++++------- 13 files changed, 63 insertions(+), 41 deletions(-) diff --git a/src/include/mempool.h b/src/include/mempool.h index 7ba83cbdcc596..81d20976adfcd 100644 --- a/src/include/mempool.h +++ b/src/include/mempool.h @@ -146,6 +146,7 @@ namespace mempool { f(osd) \ f(bluestore_meta_onode) \ f(bluestore_meta_other) \ + f(bluestore_alloc) \ f(bluefs) // give them integer ids diff --git a/src/os/bluestore/Allocator.h b/src/os/bluestore/Allocator.h index 340d0b6b7adc6..40262d5c7ed63 100644 --- a/src/os/bluestore/Allocator.h +++ b/src/os/bluestore/Allocator.h @@ -41,17 +41,17 @@ public: */ virtual int alloc_extents(uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, int64_t hint, - std::vector *extents, int *count) = 0; + AllocExtentVector *extents, int *count) = 0; int alloc_extents(uint64_t want_size, uint64_t alloc_unit, - int64_t hint, std::vector *extents, int *count) { + int64_t hint, AllocExtentVector *extents, int *count) { return alloc_extents(want_size, alloc_unit, want_size, hint, extents, count); } virtual int release( uint64_t offset, uint64_t length) = 0; - virtual int release_extents(std::vector *extents, int count) { + virtual int release_extents(AllocExtentVector *extents, int count) { int res = 0; for (int i = 0; i < count; i++) { res = release((*extents)[i].offset, (*extents)[i].length); diff --git a/src/os/bluestore/BitAllocator.cc b/src/os/bluestore/BitAllocator.cc index 993d5f9b7ca85..99745e18f15c0 100644 --- a/src/os/bluestore/BitAllocator.cc +++ b/src/os/bluestore/BitAllocator.cc @@ -23,6 +23,13 @@ #include #include +MEMPOOL_DEFINE_OBJECT_FACTORY(BitMapArea, BitMapArea, bluestore_alloc); +MEMPOOL_DEFINE_OBJECT_FACTORY(BitMapAreaIN, BitMapAreaIN, bluestore_alloc); +MEMPOOL_DEFINE_OBJECT_FACTORY(BitMapAreaLeaf, BitMapAreaLeaf, bluestore_alloc); +MEMPOOL_DEFINE_OBJECT_FACTORY(BitMapZone, BitMapZone, bluestore_alloc); +MEMPOOL_DEFINE_OBJECT_FACTORY(BmapEntry, BmapEntry, bluestore_alloc); +MEMPOOL_DEFINE_OBJECT_FACTORY(BitAllocator, BitAllocator, bluestore_alloc); + int64_t BitMapAreaLeaf::count = 0; int64_t BitMapZone::count = 0; int64_t BitMapZone::total_blocks = 0; @@ -350,7 +357,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())); - std::vector *bmaps = new std::vector (num_bmaps, BmapEntry(def)); + BmapEntryVector *bmaps = new BmapEntryVector(num_bmaps, BmapEntry(def)); m_bmap_list = bmaps; incr_count(); } diff --git a/src/os/bluestore/BitAllocator.h b/src/os/bluestore/BitAllocator.h index 2a0916c5ebf4c..8b601a27f0a50 100644 --- a/src/os/bluestore/BitAllocator.h +++ b/src/os/bluestore/BitAllocator.h @@ -26,6 +26,7 @@ #define alloc_dbg_assert(x) (static_cast (0)) #endif + class BitAllocatorStats { public: std::atomic m_total_alloc_calls; @@ -71,7 +72,8 @@ public: template class BitMapEntityIter { - std::vector *m_list; + typedef mempool::bluestore_alloc::vector BitMapEntityVector; + BitMapEntityVector *m_list; int64_t m_start_idx; int64_t m_cur_idx; bool m_wrap; @@ -79,7 +81,7 @@ class BitMapEntityIter { bool m_end; public: - void init(std::vector *list, bool wrap, int64_t start_idx) { + void init(BitMapEntityVector *list, bool wrap, int64_t start_idx) { m_list = list; m_wrap = wrap; m_start_idx = start_idx; @@ -88,10 +90,10 @@ public: m_end = false; } - BitMapEntityIter(std::vector *list, int64_t start_idx) { + BitMapEntityIter(BitMapEntityVector *list, int64_t start_idx) { init(list, false, start_idx); } - BitMapEntityIter(std::vector *list, int64_t start_idx, bool wrap) { + BitMapEntityIter(BitMapEntityVector *list, int64_t start_idx, bool wrap) { init(list, wrap, start_idx); } @@ -145,6 +147,7 @@ private: bmap_t m_bits; public: + MEMPOOL_CLASS_HELPERS(); static bmap_t full_bmask(); static int64_t size(); static bmap_t empty_bmask(); @@ -194,6 +197,7 @@ protected: bmap_area_type_t m_type; public: + MEMPOOL_CLASS_HELPERS(); static int64_t get_zone_size(); static int64_t get_span_size(); bmap_area_type_t level_to_type(int level); @@ -313,14 +317,17 @@ public: void decr_idx(); }; +typedef mempool::bluestore_alloc::vector BmapEntryVector; + class BitMapZone: public BitMapArea{ private: std::atomic m_used_blocks; - std::vector *m_bmap_list; + BmapEntryVector *m_bmap_list; std::mutex m_lock; public: + MEMPOOL_CLASS_HELPERS(); static int64_t count; static int64_t total_blocks; static void incr_count() { count++;} @@ -419,6 +426,7 @@ protected: int64_t blk_off, ExtentList *block_list); public: + MEMPOOL_CLASS_HELPERS(); BitMapAreaIN(); BitMapAreaIN(int64_t zone_num, int64_t total_blocks); BitMapAreaIN(int64_t zone_num, int64_t total_blocks, bool def); @@ -458,6 +466,7 @@ private: bool def); public: + MEMPOOL_CLASS_HELPERS(); static int64_t count; static void incr_count() { count++;} BitMapAreaLeaf() { } @@ -520,6 +529,7 @@ private: int64_t hint, int64_t area_blk_off, ExtentList *block_list); public: + MEMPOOL_CLASS_HELPERS(); BitAllocator(int64_t total_blocks, int64_t zone_size_block, bmap_alloc_mode_t mode); BitAllocator(int64_t total_blocks, int64_t zone_size_block, bmap_alloc_mode_t mode, bool def); diff --git a/src/os/bluestore/BitMapAllocator.cc b/src/os/bluestore/BitMapAllocator.cc index c686ca7ddbcfe..b0b7d036d1bac 100644 --- a/src/os/bluestore/BitMapAllocator.cc +++ b/src/os/bluestore/BitMapAllocator.cc @@ -150,7 +150,7 @@ int BitMapAllocator::allocate( int BitMapAllocator::alloc_extents( uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, - int64_t hint, std::vector *extents, int *count) + int64_t hint, mempool::bluestore_alloc::vector *extents, int *count) { assert(!(alloc_unit % m_block_size)); assert(alloc_unit); @@ -177,7 +177,7 @@ int BitMapAllocator::alloc_extents( */ int BitMapAllocator::alloc_extents_cont( uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, int64_t hint, - std::vector *extents, int *count) + mempool::bluestore_alloc::vector *extents, int *count) { *count = 0; assert(alloc_unit); @@ -215,7 +215,7 @@ int BitMapAllocator::alloc_extents_cont( int BitMapAllocator::alloc_extents_dis( uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, - int64_t hint, std::vector *extents, int *count) + int64_t hint, mempool::bluestore_alloc::vector *extents, int *count) { ExtentList block_list = ExtentList(extents, m_block_size, max_alloc_size); int64_t nblks = (want_size + m_block_size - 1) / m_block_size; diff --git a/src/os/bluestore/BitMapAllocator.h b/src/os/bluestore/BitMapAllocator.h index a478d176835a2..629b4185a0b61 100644 --- a/src/os/bluestore/BitMapAllocator.h +++ b/src/os/bluestore/BitMapAllocator.h @@ -25,10 +25,10 @@ class BitMapAllocator : public Allocator { void insert_free(uint64_t offset, uint64_t len); int alloc_extents_cont(uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, - int64_t hint, std::vector *extents, int *count); + int64_t hint, mempool::bluestore_alloc::vector *extents, int *count); int alloc_extents_dis(uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, - int64_t hint, std::vector *extents, int *count); + int64_t hint, mempool::bluestore_alloc::vector *extents, int *count); public: BitMapAllocator(); @@ -44,7 +44,7 @@ public: int alloc_extents( uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, - int64_t hint, std::vector *extents, int *count); + int64_t hint, mempool::bluestore_alloc::vector *extents, int *count); int release( uint64_t offset, uint64_t length); diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index 41491a2e0dfb3..9d32697343f2e 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -1748,8 +1748,7 @@ int BlueFS::_allocate(uint8_t id, uint64_t len, } int count = 0; - std::vector extents = - std::vector(left / min_alloc_size); + AllocExtentVector extents = AllocExtentVector(left / min_alloc_size); r = alloc[id]->alloc_extents(left, min_alloc_size, hint, &extents, &count); diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 1667f5bf34104..f54b49b70501a 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -7882,8 +7882,7 @@ int BlueStore::_do_alloc_write( } int count = 0; - std::vector extents = - std::vector(final_length / min_alloc_size); + AllocExtentVector extents = AllocExtentVector(final_length / min_alloc_size); int r = alloc->alloc_extents(final_length, min_alloc_size, max_alloc_size, hint, &extents, &count); diff --git a/src/os/bluestore/StupidAllocator.cc b/src/os/bluestore/StupidAllocator.cc index 1f40ae1504c34..780c6972eda48 100644 --- a/src/os/bluestore/StupidAllocator.cc +++ b/src/os/bluestore/StupidAllocator.cc @@ -203,8 +203,12 @@ int StupidAllocator::allocate( } int StupidAllocator::alloc_extents( - uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, - int64_t hint, std::vector *extents, int *count) + uint64_t want_size, + uint64_t alloc_unit, + uint64_t max_alloc_size, + int64_t hint, + mempool::bluestore_alloc::vector *extents, + int *count) { uint64_t allocated_size = 0; uint64_t offset = 0; diff --git a/src/os/bluestore/StupidAllocator.h b/src/os/bluestore/StupidAllocator.h index 59ffdcefc811c..69ab47934589b 100644 --- a/src/os/bluestore/StupidAllocator.h +++ b/src/os/bluestore/StupidAllocator.h @@ -36,7 +36,7 @@ public: int alloc_extents( uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size, - int64_t hint, std::vector *extents, int *count); + int64_t hint, mempool::bluestore_alloc::vector *extents, int *count); int allocate( uint64_t want_size, uint64_t alloc_unit, int64_t hint, diff --git a/src/os/bluestore/bluestore_types.h b/src/os/bluestore/bluestore_types.h index 123ad30b35bb4..4fca244a0a3d7 100644 --- a/src/os/bluestore/bluestore_types.h +++ b/src/os/bluestore/bluestore_types.h @@ -62,6 +62,8 @@ struct bluestore_cnode_t { }; WRITE_CLASS_DENC(bluestore_cnode_t) +class AllocExtent; +typedef mempool::bluestore_alloc::vector AllocExtentVector; class AllocExtent { public: uint64_t offset; @@ -79,24 +81,24 @@ public: }; class ExtentList { - std::vector *m_extents; + AllocExtentVector *m_extents; int64_t m_num_extents; int64_t m_block_size; uint64_t m_max_alloc_size; public: - void init(std::vector *extents, int64_t block_size, uint64_t max_alloc_size) { + void init(AllocExtentVector *extents, int64_t block_size, uint64_t max_alloc_size) { m_extents = extents; m_num_extents = 0; m_block_size = block_size; m_max_alloc_size = max_alloc_size; } - ExtentList(std::vector *extents, int64_t block_size) { + ExtentList(AllocExtentVector *extents, int64_t block_size) { init(extents, block_size, 0); } - ExtentList(std::vector *extents, int64_t block_size, uint64_t max_alloc_size) { + ExtentList(AllocExtentVector *extents, int64_t block_size, uint64_t max_alloc_size) { init(extents, block_size, max_alloc_size); } @@ -106,7 +108,7 @@ public: void add_extents(int64_t start, int64_t count); - std::vector *get_extents() { + AllocExtentVector *get_extents() { return m_extents; } diff --git a/src/test/objectstore/Allocator_test.cc b/src/test/objectstore/Allocator_test.cc index a003fdbc74460..6b854f3f3a3be 100644 --- a/src/test/objectstore/Allocator_test.cc +++ b/src/test/objectstore/Allocator_test.cc @@ -67,7 +67,7 @@ TEST_P(AllocTest, test_alloc_min_alloc) { alloc->init_add_free(0, block_size * 4); EXPECT_EQ(alloc->reserve(block_size * 4), 0); - std::vector extents = std::vector + AllocExtentVector extents = AllocExtentVector (4, AllocExtent(0, 0)); EXPECT_EQ(alloc->alloc_extents(4 * (uint64_t)block_size, (uint64_t) block_size, @@ -84,7 +84,7 @@ TEST_P(AllocTest, test_alloc_min_alloc) alloc->init_add_free(0, block_size * 2); alloc->init_add_free(3 * block_size, block_size * 2); EXPECT_EQ(alloc->reserve(block_size * 4), 0); - std::vector extents = std::vector + AllocExtentVector extents = AllocExtentVector (4, AllocExtent(0, 0)); EXPECT_EQ(alloc->alloc_extents(4 * (uint64_t)block_size, (uint64_t) block_size, @@ -112,7 +112,7 @@ TEST_P(AllocTest, test_alloc_min_max_alloc) { alloc->init_add_free(0, block_size * 4); EXPECT_EQ(alloc->reserve(block_size * 4), 0); - std::vector extents = std::vector + AllocExtentVector extents = AllocExtentVector (4, AllocExtent(0, 0)); EXPECT_EQ(alloc->alloc_extents(4 * (uint64_t)block_size, (uint64_t) block_size, @@ -131,7 +131,7 @@ TEST_P(AllocTest, test_alloc_min_max_alloc) { alloc->init_add_free(0, block_size * 4); EXPECT_EQ(alloc->reserve(block_size * 4), 0); - std::vector extents = std::vector + AllocExtentVector extents = AllocExtentVector (2, AllocExtent(0, 0)); EXPECT_EQ(alloc->alloc_extents(4 * (uint64_t)block_size, (uint64_t) block_size, @@ -148,7 +148,7 @@ TEST_P(AllocTest, test_alloc_min_max_alloc) { alloc->init_add_free(0, block_size * 16); EXPECT_EQ(alloc->reserve(block_size * 16), 0); - std::vector extents = std::vector + AllocExtentVector extents = AllocExtentVector (8, AllocExtent(0, 0)); EXPECT_EQ(alloc->alloc_extents(16 * (uint64_t)block_size, (uint64_t) block_size, @@ -174,7 +174,7 @@ TEST_P(AllocTest, test_alloc_failure) alloc->init_add_free(block_size * 512, block_size * 256); EXPECT_EQ(alloc->reserve(block_size * 512), 0); - std::vector extents = std::vector + AllocExtentVector extents = AllocExtentVector (4, AllocExtent(0, 0)); EXPECT_EQ(alloc->alloc_extents(512 * (uint64_t)block_size, (uint64_t) block_size * 256, @@ -201,7 +201,7 @@ TEST_P(AllocTest, test_alloc_hint_bmap) init_alloc(blocks, 1); alloc->init_add_free(0, blocks); - auto extents = std::vector + auto extents = AllocExtentVector (zone_size * 4, AllocExtent(-1, -1)); alloc->reserve(blocks); diff --git a/src/test/objectstore/BitAllocator_test.cc b/src/test/objectstore/BitAllocator_test.cc index 5ebec8ea53c8c..16f12fff97dd4 100644 --- a/src/test/objectstore/BitAllocator_test.cc +++ b/src/test/objectstore/BitAllocator_test.cc @@ -49,7 +49,7 @@ TEST(BitAllocator, test_bmap_iter) }; BmapEntityTmp *obj = NULL; int i = 0; - std::vector *arr = new std::vector(num_items); + mempool::bstore_balloc::vector *arr = new mempool::bstore_balloc::vector(num_items); for (i = 0; i < num_items; i++) { (*arr)[i].init(i); } @@ -91,7 +91,7 @@ TEST(BitAllocator, test_bmap_iter) num_items = 4; off = num_items - 1; - arr = new std::vector(num_items); + arr = new mempool::bstore_balloc::vector(num_items); for (i = 0; i < num_items; i++) { (*arr)[i].init(i); } @@ -364,7 +364,7 @@ TEST(BitAllocator, test_zone_alloc) } int64_t blk_size = 1024; - std::vector extents = std::vector + AllocExtentVector extents = AllocExtentVector (zone->size() / 2, AllocExtent(-1, -1)); ExtentList *block_list = new ExtentList(&extents, blk_size); @@ -388,7 +388,7 @@ TEST(BitAllocator, test_zone_alloc) { int64_t blk_size = 1024; - std::vector extents = std::vector + AllocExtentVector extents = AllocExtentVector (zone->size() / 2, AllocExtent(-1, -1)); ExtentList *block_list = new ExtentList(&extents, blk_size); @@ -486,7 +486,7 @@ TEST(BitAllocator, test_bmap_alloc) } int64_t blk_size = 1024; - auto extents = std::vector + auto extents = AllocExtentVector (alloc->size(), AllocExtent(-1, -1)); ExtentList *block_list = new ExtentList(&extents, blk_size); @@ -584,7 +584,7 @@ bool alloc_extents_max_block(BitAllocator *alloc, int64_t allocated = 0; int64_t verified = 0; int64_t count = 0; - std::vector extents = std::vector + AllocExtentVector extents = AllocExtentVector (total_alloc, AllocExtent(-1, -1)); ExtentList *block_list = new ExtentList(&extents, blk_size, max_alloc); @@ -671,7 +671,7 @@ do_work_dis(BitAllocator *alloc) int64_t alloced = 0; int64_t num_blocks = alloc->size() / NUM_THREADS; - std::vector extents = std::vector + AllocExtentVector extents = AllocExtentVector (num_blocks, AllocExtent(-1, -1)); ExtentList *block_list = new ExtentList(&extents, 4096); -- 2.39.5