* Apart from that extents can vary between these lower and higher limits according
* to free block search algorithm and availability of contiguous space.
*/
- virtual int allocate(uint64_t want_size, uint64_t alloc_unit,
- uint64_t max_alloc_size, int64_t hint,
- AllocExtentVector *extents, int *count, uint64_t *ret_len) = 0;
+ virtual int64_t allocate(uint64_t want_size, uint64_t alloc_unit,
+ uint64_t max_alloc_size, int64_t hint,
+ AllocExtentVector *extents, int *count) = 0;
int allocate(uint64_t want_size, uint64_t alloc_unit,
- int64_t hint, AllocExtentVector *extents, int *count, uint64_t *ret_len) {
- return allocate(want_size, alloc_unit, want_size, hint, extents, count, ret_len);
+ int64_t hint, AllocExtentVector *extents, int *count) {
+ return allocate(want_size, alloc_unit, want_size, hint, extents, count);
}
virtual int release(
m_bit_alloc->unreserve_blocks(nblks);
}
-int BitMapAllocator::allocate(
+int64_t BitMapAllocator::allocate(
uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
- int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents, int *count, uint64_t *ret_len)
+ int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents, int *count)
{
assert(!(alloc_unit % m_block_size));
<< dendl;
return allocate_dis(want_size, alloc_unit / m_block_size,
- max_alloc_size, hint / m_block_size, extents, count, ret_len);
+ max_alloc_size, hint / m_block_size, extents, count);
}
-int BitMapAllocator::allocate_dis(
+int64_t BitMapAllocator::allocate_dis(
uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
- int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents, int *count, uint64_t *ret_len)
+ int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *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;
int64_t num = 0;
*count = 0;
- *ret_len = 0;
num = m_bit_alloc->alloc_blocks_dis_res(nblks, alloc_unit, hint, &block_list);
if (num == 0) {
return -ENOSPC;
}
*count = block_list.get_extent_count();
- *ret_len = num * m_block_size;
- return 0;
+ return num * m_block_size;
}
int BitMapAllocator::release(
void insert_free(uint64_t offset, uint64_t len);
- int allocate_dis(uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
- int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents, int *count, uint64_t *ret_len);
+ int64_t allocate_dis(
+ uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
+ int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents,
+ int *count);
public:
BitMapAllocator(CephContext* cct, int64_t device_size, int64_t block_size);
int reserve(uint64_t need);
void unreserve(uint64_t unused);
- int allocate(
+ int64_t allocate(
uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
- int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents, int *count, uint64_t *ret_len);
+ int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents,
+ int *count);
int release(
uint64_t offset, uint64_t length);
int r = alloc[id]->reserve(want);
assert(r == 0); // caller shouldn't ask for more than they can get
int count = 0;
- uint64_t got = 0;
- r = alloc[id]->allocate(want, cct->_conf->bluefs_alloc_size, 0,
- extents, &count, &got);
-
- assert(r >= 0);
- if (got < want)
+ int64_t got = alloc[id]->allocate(want, cct->_conf->bluefs_alloc_size, 0,
+ extents, &count);
+ assert(got > 0);
+ if (got < (int64_t)want)
alloc[id]->unreserve(want - got);
for (int i = 0; i < count; i++) {
}
int count = 0;
- uint64_t alloc_len = 0;
AllocExtentVector extents;
- r = alloc[id]->allocate(left, min_alloc_size, hint,
- &extents, &count, &alloc_len);
- if (r < 0 || alloc_len < left) {
+ int64_t alloc_len = alloc[id]->allocate(left, min_alloc_size, hint,
+ &extents, &count);
+ if (alloc_len < (int64_t)left) {
derr << __func__ << " allocate failed on 0x" << std::hex << left
<< " min_alloc_size 0x" << min_alloc_size << std::dec << dendl;
alloc[id]->dump();
assert(0 == "allocate failed... wtf");
- return r;
+ return -ENOSPC;
}
for (int i = 0; i < count; i++) {
assert(r == 0);
int count = 0;
- uint64_t alloc_len = 0;
AllocExtentVector exts;
- r = alloc->allocate(gift, cct->_conf->bluefs_alloc_size, 0, 0, &exts,
- &count, &alloc_len);
+ int64_t alloc_len = alloc->allocate(gift, cct->_conf->bluefs_alloc_size,
+ 0, 0, &exts, &count);
- if (r < 0 || alloc_len < gift) {
+ if (alloc_len < (int64_t)gift) {
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;
+ return -ENOSPC;
}
assert(count > 0);
}
int count = 0;
- uint64_t alloc_len = 0;
AllocExtentVector extents;
- int r = alloc->allocate(final_length, min_alloc_size, max_alloc_size,
- hint, &extents, &count, &alloc_len);
- assert(r == 0 && alloc_len == final_length);
- need -= final_length;
- txc->statfs_delta.allocated() += final_length;
- assert(count > 0);
- hint = extents[count - 1].end();
-
- for (int i = 0; i < count; i++) {
- bluestore_pextent_t e = bluestore_pextent_t(extents[i]);
+ int64_t got = alloc->allocate(final_length, min_alloc_size, max_alloc_size,
+ hint, &extents, &count);
+ assert(got == (int64_t)final_length);
+ need -= got;
+ txc->statfs_delta.allocated() += got;
+ for (auto& p : extents) {
+ bluestore_pextent_t e = bluestore_pextent_t(p);
txc->allocated.insert(e.offset, e.length);
dblob.extents.push_back(e);
+ hint = p.end();
}
dout(20) << __func__ << " blob " << *b
return p.get_len() - skew;
}
-int StupidAllocator::allocate_int(
+int64_t StupidAllocator::allocate_int(
uint64_t want_size, uint64_t alloc_unit, int64_t hint,
uint64_t *offset, uint32_t *length)
{
return 0;
}
-int StupidAllocator::allocate(
+int64_t StupidAllocator::allocate(
uint64_t want_size,
uint64_t alloc_unit,
uint64_t max_alloc_size,
int64_t hint,
mempool::bluestore_alloc::vector<AllocExtent> *extents,
- int *count,
- uint64_t *ret_len)
+ int *count)
{
uint64_t allocated_size = 0;
uint64_t offset = 0;
max_alloc_size = want_size;
}
*count = 0;
- *ret_len = 0;
ExtentList block_list = ExtentList(extents, 1, max_alloc_size);
}
*count = block_list.get_extent_count();
- *ret_len = allocated_size;
if (allocated_size == 0) {
return -ENOSPC;
}
-
- return 0;
+ return allocated_size;
}
int StupidAllocator::release(
int reserve(uint64_t need);
void unreserve(uint64_t unused);
- int allocate(
+ int64_t allocate(
uint64_t want_size, uint64_t alloc_unit, uint64_t max_alloc_size,
- int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents, int *count, uint64_t *ret_len);
+ int64_t hint, mempool::bluestore_alloc::vector<AllocExtent> *extents,
+ int *count);
- int allocate_int(
+ int64_t allocate_int(
uint64_t want_size, uint64_t alloc_unit, int64_t hint,
uint64_t *offset, uint32_t *length);