Skip to content

Commit

Permalink
os/bluestore:Bluefs balance should use alloc_extent api with bluefs_a…
Browse files Browse the repository at this point in the history
…lloc_size

Signed-off-by: Ramesh Chander <Ramesh.Chander@sandisk.com>
  • Loading branch information
chhabaramesh committed Dec 8, 2016
1 parent 66953e3 commit 822fc22
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
8 changes: 5 additions & 3 deletions src/os/bluestore/BitMapAllocator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,26 +182,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) {
Expand Down
31 changes: 15 additions & 16 deletions src/os/bluestore/BlueStore.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3567,26 +3567,25 @@ int BlueStore::_balance_bluefs_freespace(vector<bluestore_pextent_t> *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;
}
Expand Down
18 changes: 18 additions & 0 deletions src/test/objectstore/Allocator_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 822fc22

Please sign in to comment.