From 6ad9814b93d5ff2e91876e4215f3267ad6c8f1ec Mon Sep 17 00:00:00 2001 From: Ramesh Chander Date: Tue, 6 Dec 2016 22:04:30 -0800 Subject: [PATCH] os/bluestore:Bluefs balance should use alloc_extent api with bluefs_alloc_size Signed-off-by: Ramesh Chander --- src/os/bluestore/BitMapAllocator.cc | 8 ++++--- src/os/bluestore/BlueStore.cc | 31 +++++++++++++------------- src/test/objectstore/Allocator_test.cc | 18 +++++++++++++++ 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/os/bluestore/BitMapAllocator.cc b/src/os/bluestore/BitMapAllocator.cc index 7b0f3a8beb1..8e9aa5c41f5 100644 --- a/src/os/bluestore/BitMapAllocator.cc +++ b/src/os/bluestore/BitMapAllocator.cc @@ -178,26 +178,28 @@ int BitMapAllocator::alloc_extents_cont( *count = 0; assert(alloc_unit); assert(!(alloc_unit % m_block_size)); + assert(!(want_size % alloc_unit)); assert(!(max_alloc_size % m_block_size)); int64_t nblks = (want_size + m_block_size - 1) / m_block_size; int64_t start_blk = 0; int64_t need_blks = nblks; - int64_t max_blks = max_alloc_size / m_block_size; + int64_t cont_blks = alloc_unit / m_block_size; ExtentList block_list = ExtentList(extents, m_block_size, max_alloc_size); while (need_blks > 0) { int64_t count = 0; - count = m_bit_alloc->alloc_blocks_res( - (max_blks && need_blks > max_blks) ? max_blks : need_blks, hint, &start_blk); + count = m_bit_alloc->alloc_blocks_res(cont_blks, hint, &start_blk); if (count == 0) { break; } + assert(cont_blks == count); dout(30) << __func__ <<" instance "<< (uint64_t) this << " offset " << start_blk << " length " << count << dendl; need_blks -= count; block_list.add_extents(start_blk, count); + hint = start_blk + count; } if (need_blks > 0) { diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 7b6084fdd79..fbe6d246da0 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -3592,26 +3592,25 @@ int BlueStore::_balance_bluefs_freespace(vector *extents) int r = alloc->reserve(gift); assert(r == 0); - uint64_t hint = 0; - while (gift > 0) { - uint64_t eoffset; - uint32_t elength; - r = alloc->allocate(gift, min_alloc_size, hint, &eoffset, &elength); - if (r < 0) { - derr << __func__ << " allocate failed on 0x" << std::hex << gift - << " min_alloc_size 0x" << min_alloc_size << std::dec << dendl; - alloc->dump(); - assert(0 == "allocate failed, wtf"); - return r; - } + int count = 0; + AllocExtentVector exts = AllocExtentVector(gift / min_alloc_size); + r = alloc->alloc_extents(gift, g_conf->bluefs_alloc_size, 0, 0, &exts, &count); - bluestore_pextent_t e(eoffset, elength); + if (r < 0) { + derr << __func__ << " allocate failed on 0x" << std::hex << gift + << " min_alloc_size 0x" << min_alloc_size << std::dec << dendl; + alloc->dump(); + assert(0 == "allocate failed, wtf"); + return r; + } + assert(count > 0); + + for (int i = 0; i < count; i++) { + bluestore_pextent_t e = bluestore_pextent_t(exts[i]); dout(1) << __func__ << " gifting " << e << " to bluefs" << dendl; extents->push_back(e); - gift -= e.length; - hint = e.end(); } - assert(gift == 0); // otherwise there is a reservation leak + gift = 0; ret = 1; } diff --git a/src/test/objectstore/Allocator_test.cc b/src/test/objectstore/Allocator_test.cc index ef9f0909594..d6564fbe262 100644 --- a/src/test/objectstore/Allocator_test.cc +++ b/src/test/objectstore/Allocator_test.cc @@ -141,6 +141,24 @@ TEST_P(AllocTest, test_alloc_min_max_alloc) EXPECT_EQ(count, 2); } + /* + * Make sure allocations are of min_alloc_size when min_alloc_size > block_size. + */ + { + alloc->init_add_free(0, block_size * 1024); + EXPECT_EQ(alloc->reserve(block_size * 1024), 0); + AllocExtentVector extents = AllocExtentVector + (1024, AllocExtent(0, 0)); + + EXPECT_EQ(alloc->alloc_extents(1024 * (uint64_t)block_size, (uint64_t) block_size * 4, + block_size * 4, (int64_t) 0, &extents, &count), 0); + + for (int i = 0; i < count; i++) { + EXPECT_EQ(extents[i].length, block_size * 4); + } + EXPECT_EQ(count, 1024 / 4); + } + /* * Allocate and free. */ -- 2.39.5