*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) {
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;
}
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.
*/