*
* Caller must take exclusive lock on Zone.
*/
-int64_t BitMapZone::alloc_blocks(int64_t num_blocks, int64_t *start_block)
+int64_t BitMapZone::alloc_blocks(int64_t num_blocks, int64_t hint, int64_t *start_block)
{
- int64_t bmap_idx = 0;
- int bit_idx = 0;
+ int64_t bmap_idx = hint / BmapEntry::size();
+ int bit_idx = hint % BmapEntry::size();
BmapEntry *bmap = NULL;
int64_t allocated = 0;
debug_assert(check_locked());
- bit_idx = 0;
- bmap_idx = 0;
BitMapEntityIter <BmapEntry> iter = BitMapEntityIter<BmapEntry>(
m_bmap_list, bmap_idx);
* Allocate N blocks, dis-contiguous are fine
*/
int64_t BitMapZone::alloc_blocks_dis(int64_t num_blocks,
- int64_t hint,
+ int64_t hint,
int64_t zone_blk_off,
ExtentList *alloc_blocks)
{
if (allocated == num_blocks) {
break;
}
- bit = 0;
+ bit = 0;
}
add_used_blocks(allocated);
return true;
}
-int64_t BitMapAreaIN::alloc_blocks_int_work(bool wait, bool wrap,
- int64_t num_blocks, int64_t *start_block)
+int64_t BitMapAreaIN::alloc_blocks_int_work(bool wait, bool wrap, int64_t num_blocks,
+ int64_t hint, int64_t *start_block)
{
BitMapArea *child = NULL;
int64_t allocated = 0;
*start_block = 0;
BmapEntityListIter iter = BmapEntityListIter(
- m_child_list, 0, wrap);
+ m_child_list, hint / m_child_size_blocks, wrap);
while ((child = (BitMapArea *) iter.next())) {
if (!child_check_n_lock(child, num_blocks - allocated)) {
+ hint = 0;
continue;
}
- allocated = child->alloc_blocks(wait, num_blocks, start_block);
+ allocated = child->alloc_blocks(wait, num_blocks, hint % m_child_size_blocks, start_block);
child_unlock(child);
if (allocated == num_blocks) {
(*start_block) += child->get_index() * m_child_size_blocks;
}
child->free_blocks(*start_block, allocated);
+ hint = 0;
*start_block = 0;
allocated = 0;
}
return allocated;
}
-int64_t BitMapAreaIN::alloc_blocks_int(bool wait,
- int64_t num_blocks, int64_t *start_block)
+int64_t BitMapAreaIN::alloc_blocks_int(bool wait, int64_t num_blocks,
+ int64_t hint, int64_t *start_block)
{
- return alloc_blocks_int_work(wait, false, num_blocks, start_block);
+ return alloc_blocks_int_work(wait, false, num_blocks, hint, start_block);
}
-int64_t BitMapAreaIN::alloc_blocks(bool wait, int64_t num_blocks,
+int64_t BitMapAreaIN::alloc_blocks(bool wait, int64_t num_blocks, int64_t hint,
int64_t *start_block)
{
int64_t allocated = 0;
goto exit;
}
- allocated = alloc_blocks_int(wait, num_blocks, start_block);
+ allocated = alloc_blocks_int(wait, num_blocks, hint, start_block);
unreserve(num_blocks, allocated);
debug_assert((get_used_blocks() <= m_total_blocks));
while ((child = (BitMapArea *) iter.next())) {
if (!child_check_n_lock(child, 1)) {
+ hint = 0;
continue;
}
blk_off = child->get_index() * m_child_size_blocks + area_blk_off;
allocated += child->alloc_blocks_dis(wait, num_blocks - allocated,
hint % m_child_size_blocks, blk_off, block_list);
- hint = 0;
+ hint = 0;
child_unlock(child);
if (allocated == num_blocks) {
break;
int64_t BitMapAreaIN::alloc_blocks_dis_int(bool wait, int64_t num_blocks,
int64_t hint, int64_t area_blk_off, ExtentList *block_list)
{
- return alloc_blocks_dis_int_work(wait, true, num_blocks, hint,
- area_blk_off, block_list);
-
+ return alloc_blocks_dis_int_work(wait, false, num_blocks, hint,
+ area_blk_off, block_list);
}
int64_t BitMapAreaIN::alloc_blocks_dis(bool wait, int64_t num_blocks,
child->unlock();
}
-int64_t BitMapAreaLeaf::alloc_blocks_int(bool wait,
- int64_t num_blocks, int64_t *start_block)
+int64_t BitMapAreaLeaf::alloc_blocks_int(bool wait, int64_t num_blocks,
+ int64_t hint, int64_t *start_block)
{
BitMapArea *child = NULL;
int64_t allocated = 0;
*start_block = 0;
BmapEntityListIter iter = BmapEntityListIter(
- m_child_list, 0, false);
+ m_child_list, hint / m_child_size_blocks, false);
while ((child = iter.next())) {
if (!child_check_n_lock(child, num_blocks - allocated, false)) {
+ hint = 0;
continue;
}
debug_assert(child->get_type() == ZONE);
- allocated = child->alloc_blocks(num_blocks, start_block);
+ allocated = child->alloc_blocks(num_blocks, hint % m_child_size_blocks, start_block);
child_unlock(child);
if (allocated == num_blocks) {
(*start_block) += child->get_index() * m_child_size_blocks;
}
child->free_blocks(*start_block, allocated);
+ hint = 0;
*start_block = 0;
allocated = 0;
}
while ((child = (BitMapArea *) iter.next())) {
if (!child_check_n_lock(child, 1, false)) {
+ hint = 0;
continue;
}
blk_off = child->get_index() * m_child_size_blocks + area_blk_off;
- allocated += child->alloc_blocks_dis(num_blocks - allocated, hint, blk_off, block_list);
- hint = 0;
+ allocated += child->alloc_blocks_dis(num_blocks - allocated, hint % m_child_size_blocks,
+ blk_off, block_list);
child_unlock(child);
if (allocated == num_blocks) {
break;
}
+ hint = 0;
}
return allocated;
}
return true;
}
-int64_t BitAllocator::alloc_blocks_int(bool wait,
- int64_t num_blocks, int64_t *start_block)
+int64_t BitAllocator::alloc_blocks_int(bool wait, int64_t num_blocks,
+ int64_t hint, int64_t *start_block)
{
-
- return alloc_blocks_int_work(wait, true, num_blocks, start_block);
-#if 0
- BitMapArea *child = NULL;
- int64_t allocated = 0;
-
- *start_block = 0;
- BmapEntityListIter iter = BmapEntityListIter(
- m_child_list, 0, true);
-
- while ((child = (BitMapArea *) iter.next())) {
- if (!child_check_n_lock(child, num_blocks - allocated)) {
- continue;
- }
-
- allocated = child->alloc_blocks(wait, num_blocks, start_block);
- child_unlock(child);
- if (allocated == num_blocks) {
- (*start_block) += child->get_index() * m_child_size_blocks;
- break;
- }
-
- child->free_blocks(*start_block, allocated);
- *start_block = 0;
- allocated = 0;
- }
- return allocated;
-#endif
+ return alloc_blocks_int_work(wait, true, num_blocks, hint, start_block);
}
/*
* Interface to allocate blocks after reserve.
*/
-int64_t BitAllocator::alloc_blocks_res(int64_t num_blocks, int64_t *start_block)
+int64_t BitAllocator::alloc_blocks_res(int64_t num_blocks, int64_t hint, int64_t *start_block)
{
int scans = 1;
int64_t allocated = 0;
}
while (scans && !allocated) {
- allocated = alloc_blocks_int(false, num_blocks, start_block);
+ allocated = alloc_blocks_int(false, num_blocks, hint, start_block);
scans--;
}
unlock();
lock_excl();
serial_lock();
- allocated = alloc_blocks_int(false, num_blocks, start_block);
+ allocated = alloc_blocks_int(false, num_blocks, hint, start_block);
if (is_stats_on()) {
m_stats->add_serial_scans(1);
}
return allocated;
}
-int64_t BitAllocator::alloc_blocks(int64_t num_blocks, int64_t *start_block)
+int64_t BitAllocator::alloc_blocks(int64_t num_blocks, int64_t hint, int64_t *start_block)
{
int scans = 1;
int64_t allocated = 0;
}
while (scans && !allocated) {
- allocated = alloc_blocks_int(false, num_blocks, start_block);
+ allocated = alloc_blocks_int(false, num_blocks, hint, start_block);
scans--;
}
unlock();
lock_excl();
serial_lock();
- allocated = alloc_blocks_int(false, num_blocks, start_block);
+ allocated = alloc_blocks_int(false, num_blocks, hint, start_block);
if (!allocated) {
- allocated = alloc_blocks_int(false, num_blocks, start_block);
+ allocated = alloc_blocks_int(false, num_blocks, hint, start_block);
debug_assert(allocated);
}
if (is_stats_on()) {
int64_t BitAllocator::alloc_blocks_dis_int(bool wait, int64_t num_blocks,
int64_t hint, int64_t area_blk_off, ExtentList *block_list)
{
-
return alloc_blocks_dis_int_work(wait, true, num_blocks, hint,
- area_blk_off, block_list);
- #if 0
- BitMapArea *child = NULL;
- int64_t allocated = 0;
- int64_t blk_off = 0;
-
- BmapEntityListIter iter = BmapEntityListIter(
- m_child_list, hint / m_child_size_blocks, true);
-
- while ((child = (BitMapArea *) iter.next())) {
- if (!child_check_n_lock(child, 1)) {
- continue;
- }
-
- blk_off = child->get_index() * m_child_size_blocks + area_blk_off;
- allocated += child->alloc_blocks_dis(wait, num_blocks - allocated,
- hint % m_child_size_blocks, blk_off, block_list);
- hint = 0;
- child_unlock(child);
- if (allocated == num_blocks) {
- break;
- }
- }
-
- return allocated;
- #endif
+ area_blk_off, block_list);
}
int64_t BitAllocator::alloc_blocks_dis(int64_t num_blocks, int64_t hint, ExtentList *block_list)
unlock();
lock_excl();
serial_lock();
- allocated += alloc_blocks_dis_int(false, num_blocks - allocated, hint + allocated, blk_off, block_list);
+ allocated += alloc_blocks_dis_int(false, num_blocks - allocated, hint + allocated,
+ blk_off, block_list);
if (is_stats_on()) {
m_stats->add_serial_scans(1);
}
virtual int64_t get_used_blocks() = 0;
virtual void shutdown() = 0;
- virtual int64_t alloc_blocks(bool wait, int64_t num_blocks, int64_t *start_block) {
+ virtual int64_t alloc_blocks(bool wait, int64_t num_blocks,
+ int64_t hint, int64_t *start_block) {
debug_assert(0);
return 0;
}
- virtual int64_t alloc_blocks(int64_t num_blocks, int64_t *start_block) {
+ virtual int64_t alloc_blocks(int64_t num_blocks, int64_t hint, int64_t *start_block) {
debug_assert(0);
return 0;
}
~BitMapZone();
void shutdown();
- virtual int64_t alloc_blocks(bool wait, int64_t num_blocks, int64_t *start_block) {
+ virtual int64_t alloc_blocks(bool wait, int64_t num_blocks,
+ int64_t hint, int64_t *start_block) {
debug_assert(0);
return 0;
}
return 0;
}
- int64_t alloc_blocks(int64_t num_blocks, int64_t *start_block);
+ int64_t alloc_blocks(int64_t num_blocks, int64_t hint, int64_t *start_block);
using BitMapArea::alloc_blocks_dis;
int64_t alloc_blocks_dis(int64_t num_blocks, int64_t hint,
int64_t blk_off, ExtentList *block_list);
void init_common(int64_t total_blocks, int64_t zone_size_block, bool def);
int64_t alloc_blocks_int_work(bool wait, bool wrap,
- int64_t num_blocks, int64_t *start_block);
+ int64_t num_blocks, int64_t hint, int64_t *start_block);
int64_t alloc_blocks_dis_int_work(bool wait, bool wrap, int64_t num_blocks, int64_t hint,
int64_t blk_off, ExtentList *block_list);
return m_total_blocks;
}
- virtual int64_t alloc_blocks_int(bool wait,
- int64_t num_blocks, int64_t *start_block);
+ virtual int64_t alloc_blocks_int(bool wait, int64_t num_blocks,
+ int64_t hint, int64_t *start_block);
using BitMapArea::alloc_blocks; //non-wait version
using BitMapArea::alloc_blocks_dis; //non-wait version
- virtual int64_t alloc_blocks(bool wait, int64_t num_blocks, int64_t *start_block);
+ virtual int64_t alloc_blocks(bool wait, int64_t num_blocks, int64_t hint, int64_t *start_block);
virtual int64_t alloc_blocks_dis_int(bool wait, int64_t num_blocks, int64_t hint,
int64_t blk_off, ExtentList *block_list);
virtual int64_t alloc_blocks_dis(bool wait, int64_t num_blocks, int64_t hint,
bool child_check_n_lock(BitMapArea *child, int64_t required, bool lock);
void child_unlock(BitMapArea *child);
- int64_t alloc_blocks_int(bool wait,
- int64_t num_blocks, int64_t *start_block);
+ int64_t alloc_blocks_int(bool wait, int64_t num_blocks, int64_t hint, int64_t *start_block);
int64_t alloc_blocks_dis_int(bool wait, int64_t num_blocks, int64_t hint,
int64_t blk_off, ExtentList *block_list);
void free_blocks_int(int64_t start_block, int64_t num_blocks);
void init_check(int64_t total_blocks, int64_t zone_size_block,
bmap_alloc_mode_t mode, bool def, bool stats_on);
int64_t alloc_blocks_dis_work(int64_t num_blocks, int64_t hint, ExtentList *block_list, bool reserved);
+ int64_t alloc_blocks_int(bool wait, int64_t num_blocks, int64_t hint, int64_t *start_block);
+
+ int64_t alloc_blocks_dis_int(bool wait, int64_t num_blocks,
+ int64_t hint, int64_t area_blk_off, ExtentList *block_list);
public:
using BitMapAreaIN::alloc_blocks; //Wait version
using BitMapAreaIN::alloc_blocks_dis; //Wait version
- int64_t alloc_blocks(int64_t num_blocks, int64_t *start_block);
- int64_t alloc_blocks_res(int64_t num_blocks, int64_t *start_block);
+ int64_t alloc_blocks(int64_t num_blocks, int64_t hint, int64_t *start_block);
+ int64_t alloc_blocks_res(int64_t num_blocks, int64_t hint, int64_t *start_block);
void free_blocks(int64_t start_block, int64_t num_blocks);
void set_blocks_used(int64_t start_block, int64_t num_blocks);
void unreserve_blocks(int64_t blocks);
- int64_t alloc_blocks_int(bool wait,
- int64_t num_blocks, int64_t *start_block);
-
- int64_t alloc_blocks_dis_int(bool wait, int64_t num_blocks,
- int64_t hint, int64_t area_blk_off, ExtentList *block_list);
int64_t alloc_blocks_dis(int64_t num_blocks, int64_t hint, ExtentList *block_list);
int64_t alloc_blocks_dis_res(int64_t num_blocks, int64_t hint, ExtentList *block_list);
*offset = 0;
*length = 0;
- count = m_bit_alloc->alloc_blocks_res(nblks, &start_blk);
+ count = m_bit_alloc->alloc_blocks_res(nblks, hint / m_block_size, &start_blk);
if (count == 0) {
return -ENOSPC;
}
<< dendl;
if (alloc_unit > (uint64_t) m_block_size) {
- return alloc_extents_cont(want_size, alloc_unit, max_alloc_size, hint, extents, count);
+ return alloc_extents_cont(want_size, alloc_unit,
+ max_alloc_size, hint / m_block_size, extents, count);
} else {
- return alloc_extents_dis(want_size, alloc_unit, max_alloc_size, hint, extents, count);
+ return alloc_extents_dis(want_size, alloc_unit,
+ max_alloc_size, hint / m_block_size, extents, count);
}
}
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, &start_blk);
+ (max_blks && need_blks > max_blks) ? max_blks : need_blks, hint, &start_blk);
if (count == 0) {
break;
}
alloc->shutdown();
blocks = BitMapZone::get_total_blocks() * 2;
init_alloc(blocks, 1);
- ASSERT_EQ(alloc->get_free(), 0);
+ ASSERT_EQ(alloc->get_free(), (uint64_t) 0);
}
TEST_P(AllocTest, test_alloc_min_alloc)
}
}
+TEST_P(AllocTest, test_alloc_hint_bmap)
+{
+ if (GetParam() == std::string("stupid")) {
+ return;
+ }
+ int64_t blocks = BitMapArea::get_level_factor(2) * 4;
+ int count = 0;
+ int64_t allocated = 0;
+ int64_t zone_size = 1024;
+ g_conf->set_val("bluestore_bitmapallocator_blocks_per_zone", std::to_string(zone_size));
+
+ init_alloc(blocks, 1);
+ alloc->init_add_free(0, blocks);
+
+ auto extents = std::vector<AllocExtent>
+ (zone_size * 4, AllocExtent(-1, -1));
+ alloc->reserve(blocks);
+
+ allocated = alloc->alloc_extents(1, 1, 1, zone_size, &extents, &count);
+ ASSERT_EQ(0, allocated);
+ ASSERT_EQ(1, count);
+ ASSERT_EQ(extents[0].offset, (uint64_t) zone_size);
+
+ allocated = alloc->alloc_extents(1, 1, 1, zone_size * 2 - 1, &extents, &count);
+ EXPECT_EQ(0, allocated);
+ ASSERT_EQ(1, count);
+ EXPECT_EQ((int64_t) extents[0].offset, zone_size * 2 - 1);
+
+ /*
+ * Wrap around with hint
+ */
+ allocated = alloc->alloc_extents(zone_size * 2, 1, 1, blocks - zone_size * 2, &extents, &count);
+ EXPECT_EQ(0, allocated);
+ EXPECT_EQ(zone_size * 2, count);
+ EXPECT_EQ((int64_t)extents[0].offset, blocks - zone_size * 2);
+
+ allocated = alloc->alloc_extents(zone_size, 1, 1, blocks - zone_size, &extents, &count);
+ EXPECT_EQ(0, allocated);
+ EXPECT_EQ(zone_size, count);
+ EXPECT_EQ(extents[0].offset, (uint64_t) 0);
+}
+
+
INSTANTIATE_TEST_CASE_P(
Allocator,
AllocTest,
}
+
+
// Find few bits at end of bitmap and find those
bmap->clear_bits(0, 4);
bmap->clear_bits(BmapEntry::size() - 12, 5);
bmap_test_assert(bmap->is_allocated(start, 6));
delete bmap;
+
+ {
+
+ bmap = new BmapEntry(false);
+ start = -1;
+ scanned = 0;
+ allocated = 0;
+ allocated = bmap->find_first_set_bits(1, 1, &start, &scanned);
+ bmap_test_assert(allocated == 1);
+ bmap_test_assert(start == 1);
+
+ allocated = bmap->find_first_set_bits(1, BmapEntry::size() - 2, &start, &scanned);
+ bmap_test_assert(allocated == 1);
+ bmap_test_assert(start == BmapEntry::size() - 2);
+
+ bmap->clear_bits(0, BmapEntry::size());
+ bmap->set_bits(0, BmapEntry::size() / 4);
+ allocated = bmap->find_first_set_bits(4, 2, &start, &scanned);
+ bmap_test_assert(allocated == 4);
+ bmap_test_assert(start == BmapEntry::size() / 4);
+ delete bmap;
+ }
+
bmap = new BmapEntry(false);
bmap->set_bits(4, BmapEntry::size() - 4);
bmap_test_assert(bmap->is_allocated(4, BmapEntry::size() - 4));
bmap->set_bits(0, 4);
bmap_test_assert(bmap->is_allocated(0, BmapEntry::size()));
delete bmap;
+
}
TEST(BitAllocator, test_zone_alloc)
bmap_test_assert(lock);
for (int i = 0; i < total_blocks; i++) {
- allocated = zone->alloc_blocks(blks, &start_blk);
+ allocated = zone->alloc_blocks(blks, 0, &start_blk);
bmap_test_assert(last_blk + 1 == start_blk);
bmap_test_assert(allocated == blks);
last_blk = start_blk;
blks = 2;
last_blk = -2;
for (int i = 0; i < total_blocks/2; i++) {
- allocated = zone->alloc_blocks(blks, &start_blk);
+ allocated = zone->alloc_blocks(blks, 0, &start_blk);
bmap_test_assert(last_blk + 2 == start_blk);
last_blk = start_blk;
}
zone->free_blocks(BmapEntry::size() - blks, blks);
zone->free_blocks(BmapEntry::size(), blks);
- allocated = zone->alloc_blocks(blks * 2, &start_blk);
+ allocated = zone->alloc_blocks(blks * 2, 0, &start_blk);
bmap_test_assert(BmapEntry::size() - blks == start_blk);
bmap_test_assert(allocated == blks * 2);
blks = 4;
zone->free_blocks(BmapEntry::size() * 2 - blks, 2 * blks);
- allocated = zone->alloc_blocks(2 * blks, &start_blk);
+ allocated = zone->alloc_blocks(2 * blks, 0, &start_blk);
bmap_test_assert(BmapEntry::size() * 2 - blks == start_blk);
bmap_test_assert(allocated == blks * 2);
blks = BmapEntry::size() * 2;
zone->free_blocks(BmapEntry::size() * 6 - blks, blks);
- allocated = zone->alloc_blocks(blks, &start_blk);
+ allocated = zone->alloc_blocks(blks, 0, &start_blk);
bmap_test_assert(BmapEntry::size() * 6 - blks == start_blk);
// free blocks at distance 1, 2 up to 63 and allocate all of them
num_bits = 1;
int64_t start_block = 0;
for (int i = 0; i < zone->size() / BmapEntry::size() -1; i++) {
- allocated = zone->alloc_blocks(num_bits, &start_block);
+ allocated = zone->alloc_blocks(num_bits, 0, &start_block);
bmap_test_assert(num_bits == allocated);
bmap_test_assert(start_block == i * BmapEntry::size());
num_bits++;
lock = zone->lock_excl_try();
bmap_test_assert(lock);
for (int i = 0; i < zone->size(); i++) {
- allocated = zone->alloc_blocks(1, &start_block);
+ allocated = zone->alloc_blocks(1, 0, &start_block);
bmap_test_assert(allocated == 1);
}
for (int i = 0; i < zone->size(); i += 2) {
(zone->size() / 2, AllocExtent(-1, -1));
ExtentList *block_list = new ExtentList(&extents, blk_size);
- allocated = zone->alloc_blocks_dis(zone->size() / 2, 0, block_list);
+ allocated = zone->alloc_blocks_dis(zone->size() / 2, 0, 0, block_list);
bmap_test_assert(allocated == zone->size() / 2);
+
+ {
+ zone = new BitMapZone(total_blocks, 0);
+ lock = zone->lock_excl_try();
+ bmap_test_assert(lock);
+ for (int i = 0; i < zone->size(); i += 4) {
+ allocated = zone->alloc_blocks(1, i, &start_block);
+ bmap_test_assert(allocated == 1);
+ bmap_test_assert(start_block == i);
+ }
+
+ for (int i = 0; i < zone->size(); i += 4) {
+ zone->free_blocks(i, 1);
+ }
+ }
+
+ {
+ int64_t blk_size = 1024;
+ std::vector<AllocExtent> extents = std::vector<AllocExtent>
+ (zone->size() / 2, AllocExtent(-1, -1));
+
+ ExtentList *block_list = new ExtentList(&extents, blk_size);
+
+ zone = new BitMapZone(total_blocks, 0);
+ lock = zone->lock_excl_try();
+ bmap_test_assert(lock);
+ for (int i = 0; i < zone->size(); i += 4) {
+ block_list->reset();
+ allocated = zone->alloc_blocks_dis(1, i, 0, block_list);
+ bmap_test_assert(allocated == 1);
+ EXPECT_EQ(extents[0].offset, (uint64_t) i * blk_size);
+ }
+
+ for (int i = 0; i < zone->size(); i += 4) {
+ zone->free_blocks(i, 1);
+ }
+ }
}
TEST(BitAllocator, test_bmap_alloc)
for (int64_t iter = 0; iter < max_iter; iter++) {
for (int64_t i = 0; i < total_blocks; i++) {
- allocated = alloc->alloc_blocks(1, &start_block);
+ debug_assert(alloc->reserve_blocks(1));
+ allocated = alloc->alloc_blocks_res(1, 0, &start_block);
bmap_test_assert(allocated == 1);
bmap_test_assert(start_block == i);
}
for (int64_t iter = 0; iter < max_iter; iter++) {
for (int64_t i = 0; i < total_blocks / zone_size; i++) {
- allocated = alloc->alloc_blocks(zone_size, &start_block);
+ debug_assert(alloc->reserve_blocks(zone_size));
+ allocated = alloc->alloc_blocks_res(zone_size, 0, &start_block);
bmap_test_assert(allocated == zone_size);
bmap_test_assert(start_block == i * zone_size);
}
}
}
- allocated = alloc->alloc_blocks(1, &start_block);
+ allocated = alloc->alloc_blocks(1, 0, &start_block);
bmap_test_assert(allocated == 1);
- allocated = alloc->alloc_blocks(zone_size - 1, &start_block);
+ allocated = alloc->alloc_blocks(zone_size - 1, 0, &start_block);
bmap_test_assert(allocated == zone_size - 1);
bmap_test_assert(start_block == 1);
- allocated = alloc->alloc_blocks(1, &start_block);
+ allocated = alloc->alloc_blocks(1, 0, &start_block);
bmap_test_assert(allocated == 1);
- allocated = alloc->alloc_blocks(zone_size, &start_block);
+ allocated = alloc->alloc_blocks(zone_size, 0, &start_block);
bmap_test_assert(allocated == zone_size);
bmap_test_assert(start_block == zone_size * 2);
alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT);
for (int64_t i = 0; i < alloc->size(); i++) {
- allocated = alloc->alloc_blocks(1, &start_block);
+ allocated = alloc->alloc_blocks(1, 0, &start_block);
bmap_test_assert(allocated == 1);
}
for (int i = 0; i < alloc->size(); i += 2) {
ExtentList *block_list = new ExtentList(&extents, blk_size);
- allocated = alloc->alloc_blocks_dis(alloc->size()/2, block_list);
+ allocated = alloc->alloc_blocks_dis(alloc->size()/2, 0, block_list);
ASSERT_EQ(alloc->size()/2, allocated);
block_list->reset();
- allocated = alloc->alloc_blocks_dis(1, block_list);
+ allocated = alloc->alloc_blocks_dis(1, 0, block_list);
bmap_test_assert(allocated == 0);
alloc->free_blocks(alloc->size()/2, 1);
block_list->reset();
- allocated = alloc->alloc_blocks_dis(1, block_list);
+ allocated = alloc->alloc_blocks_dis(1, 0, block_list);
bmap_test_assert(allocated == 1);
bmap_test_assert((int64_t) extents[0].offset == alloc->size()/2 * blk_size);
for (int64_t iter = 0; iter < max_iter; iter++) {
for (int64_t i = 0; i < total_blocks; i++) {
- allocated = alloc->alloc_blocks(1, &start_block);
+ allocated = alloc->alloc_blocks(1, 0, &start_block);
bmap_test_assert(allocated == 1);
bmap_test_assert(start_block == i);
}
alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT, false);
for (int64_t iter = 0; iter < max_iter; iter++) {
for (int64_t i = 0; i < total_blocks / alloc_size; i++) {
- allocated = alloc->alloc_blocks(alloc_size, &start_block);
+ allocated = alloc->alloc_blocks(alloc_size, 0, &start_block);
bmap_test_assert(allocated == alloc_size);
bmap_test_assert(start_block == i * alloc_size);
}
alloc = new BitAllocator(1024, zone_size, CONCURRENT, true);
alloc->free_blocks(1, 1023);
- allocated = alloc->alloc_blocks(16, &start_block);
+ allocated = alloc->alloc_blocks(16, 0, &start_block);
bmap_test_assert(allocated == 16);
bmap_test_assert(start_block == 1);
delete alloc;
for (int64_t iter = 0; iter < max_iter; iter++) {
for (int64_t i = 0; i < total_blocks / alloc_size; i++) {
bmap_test_assert(alloc->reserve_blocks(alloc_size));
- allocated = alloc->alloc_blocks_res(alloc_size, &start_block);
+ allocated = alloc->alloc_blocks_res(alloc_size, 0, &start_block);
bmap_test_assert(allocated == alloc_size);
bmap_test_assert(start_block == i * alloc_size);
}
}
}
- delete alloc;
}
// restore to typical value
ExtentList *block_list = new ExtentList(&extents, blk_size, max_alloc);
- allocated = alloc->alloc_blocks_dis(total_alloc, block_list);
+ allocated = alloc->alloc_blocks_dis(total_alloc, 0, block_list);
EXPECT_EQ(allocated, total_alloc);
max_alloc = total_alloc > max_alloc? max_alloc: total_alloc;
return true;
}
-TEST(BitAllocator2, test_bmap_alloc)
+TEST(BitAllocator, test_bmap_alloc2)
{
int64_t total_blocks = 1024 * 4;
int64_t zone_size = 1024;
printf("Allocating in tid %d.\n", my_tid);
debug_assert(alloc->reserve_blocks(num_blocks));
for (int i = 0; i < num_blocks; i++) {
- alloced = alloc->alloc_blocks_res(1, &start_block);
+ alloced = alloc->alloc_blocks_res(1, 0, &start_block);
bmap_test_assert(alloced == 1);
total_alloced++;
allocated_blocks[i] = start_block;
while (num_iters--) {
debug_assert(alloc->reserve_blocks(num_blocks));
- alloced = alloc->alloc_blocks_dis_res(num_blocks, block_list);
+ alloced = alloc->alloc_blocks_dis_res(num_blocks, 0, block_list);
debug_assert(alloced == num_blocks);
debug_assert(alloc->is_allocated_dis(block_list, num_blocks));