#include <assert.h>
#include <math.h>
-#define debug_assert assert
-
int64_t BitMapAreaLeaf::count = 0;
int64_t BitMapZone::count = 0;
int64_t BitMapZone::total_blocks = 0;
*/
return NULL;
}
- debug_assert(cur_idx < m_list->size());
+ alloc_assert(cur_idx < m_list->size());
return m_list->get_nth_item(cur_idx);
}
void BmapEntityListIter::decr_idx()
{
m_cur_idx--;
- debug_assert(m_cur_idx >= 0);
+ alloc_assert(m_cur_idx >= 0);
}
/*
int count = 0;
*free_bit = 0;
- debug_assert(max_bits > 0);
+ alloc_assert(max_bits > 0);
/*
* Find free bit aligned to bit_align return the bit_num in free_bit.
{
m_area_index = zone_num;
BitMapZone::total_blocks = total_blocks;
- debug_assert(size() > 0);
+ alloc_assert(size() > 0);
m_type = ZONE;
m_used_blocks = def? total_blocks: 0;
int64_t num_bmaps = total_blocks / BmapEntry::size();
- debug_assert(num_bmaps < std::numeric_limits<int16_t>::max());
- debug_assert(total_blocks < std::numeric_limits<int32_t>::max());
- debug_assert(!(total_blocks % BmapEntry::size()));
+ alloc_assert(num_bmaps < std::numeric_limits<int16_t>::max());
+ alloc_assert(total_blocks < std::numeric_limits<int32_t>::max());
+ alloc_assert(!(total_blocks % BmapEntry::size()));
std::vector<BmapEntry> *bmaps = new std::vector<BmapEntry> (num_bmaps, BmapEntry(def));
m_bmap_list = bmaps;
bool BitMapZone::reserve_blocks(int64_t num_blocks)
{
- debug_assert(0);
+ alloc_assert(0);
return false;
}
void BitMapZone::unreserve(int64_t num_blocks, int64_t allocated)
{
- debug_assert(0);
+ alloc_assert(0);
}
int64_t BitMapZone::get_reserved_blocks()
{
- debug_assert(0);
+ alloc_assert(0);
return 0;
}
*/
bool BitMapZone::is_exhausted()
{
- debug_assert(check_locked());
+ alloc_assert(check_locked());
return get_used_blocks() == size();
}
{
BmapEntry *bmap = NULL;
int64_t required = num_blocks;
- debug_assert(check_locked());
+ alloc_assert(check_locked());
while ((bmap = (BmapEntry *) iter->next())) {
int64_t found = 0;
int64_t max_expected = MIN(required, BmapEntry::size());
BmapEntry *bmap = NULL;
int64_t allocated = 0;
- debug_assert(check_locked());
+ alloc_assert(check_locked());
BitMapEntityIter <BmapEntry> iter = BitMapEntityIter<BmapEntry>(
m_bmap_list, bmap_idx);
{
free_blocks_int(start_block, num_blocks);
sub_used_blocks(num_blocks);
- debug_assert(get_used_blocks() >= 0);
+ alloc_assert(get_used_blocks() >= 0);
}
/*
int64_t allocated = 0;
int64_t blk_off = 0;
- debug_assert(check_locked());
+ alloc_assert(check_locked());
BitMapEntityIter <BmapEntry> iter = BitMapEntityIter<BmapEntry>(
m_bmap_list, bmap_idx);
int64_t BitMapArea::get_level_factor(int level)
{
- debug_assert(level > 0);
+ alloc_assert(level > 0);
int64_t zone_size = get_zone_size();
if (level == 1) {
void BitMapAreaIN::init(int64_t total_blocks, int64_t area_idx, bool def)
{
int64_t num_child = 0;
- debug_assert(!(total_blocks % BmapEntry::size()));
+ alloc_assert(!(total_blocks % BmapEntry::size()));
init_common(total_blocks, area_idx, def);
int64_t level_factor = BitMapArea::get_level_factor(m_level);
num_child = (total_blocks + level_factor - 1) / level_factor;
- debug_assert(num_child < std::numeric_limits<int16_t>::max());
+ alloc_assert(num_child < std::numeric_limits<int16_t>::max());
m_child_size_blocks = level_factor;
int64_t used_blks = m_used_blocks;
m_used_blocks -= num_blocks;
- debug_assert(m_used_blocks >= 0);
+ alloc_assert(m_used_blocks >= 0);
return used_blks;
}
m_reserved_blocks += num;
res = true;
}
- debug_assert(m_used_blocks <= size());
+ alloc_assert(m_used_blocks <= size());
return res;
}
std::lock_guard<std::mutex> l(m_blocks_lock);
m_used_blocks -= (needed - allocated);
m_reserved_blocks -= needed;
- debug_assert(m_used_blocks >= 0);
- debug_assert(m_reserved_blocks >= 0);
+ alloc_assert(m_used_blocks >= 0);
+ alloc_assert(m_reserved_blocks >= 0);
}
int64_t BitMapAreaIN::get_reserved_blocks()
{
int64_t area_block_offset = 0;
int64_t falling_in_area = 0;
- debug_assert(start_block >= 0 &&
+ alloc_assert(start_block >= 0 &&
(start_block + num_blocks <= size()));
if (num_blocks == 0) {
allocated = alloc_blocks_int(wait, num_blocks, hint, start_block);
unreserve(num_blocks, allocated);
- debug_assert((get_used_blocks() <= m_total_blocks));
- debug_assert(is_allocated(*start_block, allocated));
+ alloc_assert((get_used_blocks() <= m_total_blocks));
+ alloc_dbg_assert(is_allocated(*start_block, allocated));
exit:
unlock();
int64_t blks = num_blocks;
int64_t start_blk = start_block;
- debug_assert(start_block >= 0);
+ alloc_assert(start_block >= 0);
while (blks) {
child = (BitMapArea *) m_child_list->get_nth_item(
}
add_used_blocks(num_blocks);
- debug_assert(is_allocated(start_block, num_blocks));
+ alloc_dbg_assert(is_allocated(start_block, num_blocks));
}
void BitMapAreaIN::set_blocks_used(int64_t start_block, int64_t num_blocks)
int64_t child_block_offset = 0;
int64_t falling_in_child = 0;
- debug_assert(start_block >= 0 &&
+ alloc_assert(start_block >= 0 &&
(start_block + num_blocks) <= size());
if (num_blocks == 0) {
return;
}
lock_shared();
- debug_assert(is_allocated(start_block, num_blocks));
+ alloc_dbg_assert(is_allocated(start_block, num_blocks));
free_blocks_int(start_block, num_blocks);
(void) sub_used_blocks(num_blocks);
bool def)
{
int64_t num_child = 0;
- debug_assert(!(total_blocks % BmapEntry::size()));
+ alloc_assert(!(total_blocks % BmapEntry::size()));
init_common(total_blocks, area_idx, def);
- debug_assert(m_level == 1);
+ alloc_assert(m_level == 1);
int zone_size_block = get_zone_size();
- debug_assert(zone_size_block > 0);
+ alloc_assert(zone_size_block > 0);
num_child = (total_blocks + zone_size_block - 1) / zone_size_block;
- debug_assert(num_child);
+ alloc_assert(num_child);
m_child_size_blocks = total_blocks / num_child;
- debug_assert(m_level == 1);
+ alloc_assert(m_level == 1);
BitMapArea **children = new BitMapArea*[num_child];
for (int i = 0; i < num_child; i++) {
children[i] = new BitMapZone(m_child_size_blocks, i, def);
hint = 0;
continue;
}
- debug_assert(child->get_type() == ZONE);
+ alloc_assert(child->get_type() == ZONE);
allocated = child->alloc_blocks(num_blocks, hint % m_child_size_blocks, start_block);
child_unlock(child);
int64_t child_block_offset = 0;
int64_t falling_in_child = 0;
- debug_assert(start_block >= 0 &&
+ alloc_assert(start_block >= 0 &&
(start_block + num_blocks) <= size());
if (num_blocks == 0) {
int64_t unaligned_blocks = 0;
if (mode != SERIAL && mode != CONCURRENT) {
- debug_assert(0);
+ alloc_assert(0);
}
if (total_blocks <= 0) {
- debug_assert(0);
+ alloc_assert(0);
}
if (zone_size_block == 0 ||
zone_size_block < BmapEntry::size()) {
- debug_assert(0);
+ alloc_assert(0);
}
zone_size_block = (zone_size_block / BmapEntry::size()) *
}
}
- debug_assert(is_allocated(*start_block, allocated));
+ alloc_dbg_assert(is_allocated(*start_block, allocated));
unreserve(num_blocks, allocated);
serial_unlock();
*start_block = 0;
if (!check_input(num_blocks)) {
- debug_assert(0);
+ alloc_assert(0);
return 0;
}
allocated = alloc_blocks_int(false, num_blocks, hint, start_block);
if (!allocated) {
allocated = alloc_blocks_int(false, num_blocks, hint, start_block);
- debug_assert(allocated);
+ alloc_assert(allocated);
}
if (is_stats_on()) {
m_stats->add_serial_scans(1);
}
unreserve(num_blocks, allocated);
- debug_assert((get_used_blocks() <= m_total_blocks));
- debug_assert(is_allocated(*start_block, allocated));
+ alloc_assert((get_used_blocks() <= m_total_blocks));
+ alloc_dbg_assert(is_allocated(*start_block, allocated));
exit:
serial_unlock();
return;
}
- debug_assert(start_block + num_blocks <= size());
+ alloc_assert(start_block + num_blocks <= size());
if (is_stats_on()) {
m_stats->add_free_calls(1);
m_stats->add_freed(num_blocks);
}
lock_shared();
- debug_assert(is_allocated(start_block, num_blocks));
+ alloc_dbg_assert(is_allocated(start_block, num_blocks));
free_blocks_int(start_block, num_blocks);
(void) sub_used_blocks(num_blocks);
return;
}
- debug_assert(start_block + num_blocks <= size());
+ alloc_assert(start_block + num_blocks <= size());
lock_shared();
serial_lock();
set_blocks_used_int(start_block, num_blocks);
}
unreserve(num_blocks, allocated);
- debug_assert(is_allocated_dis(block_list, allocated));
+ alloc_dbg_assert(is_allocated_dis(block_list, allocated));
exit:
serial_unlock();
}
}
- debug_assert(count == num_blocks);
+ alloc_assert(count == num_blocks);
return true;
}
freed += block_list->get_nth_extent(i).second;
}
- debug_assert(num_blocks == freed);
+ alloc_assert(num_blocks == freed);
sub_used_blocks(num_blocks);
- debug_assert(get_used_blocks() >= 0);
+ alloc_assert(get_used_blocks() >= 0);
unlock();
}
#ifndef CEPH_OS_BLUESTORE_BITALLOCATOR_H
#define CEPH_OS_BLUESTORE_BITALLOCATOR_H
-#define debug_assert assert
#include <assert.h>
#include <stdint.h>
#include "include/intarith.h"
#include "os/bluestore/bluestore_types.h"
+#define alloc_assert assert
+
+#ifdef BIT_ALLOCATOR_DEBUG
+#define alloc_dbg_assert(x) assert(x)
+#else
+#define alloc_dbg_assert(x) (static_cast<void> (0))
+#endif
class BitAllocatorStats {
public:
return NULL;
}
- debug_assert(cur_idx < (int64_t)m_list->size());
+ alloc_assert(cur_idx < (int64_t)m_list->size());
return &(*m_list)[cur_idx];
}
}
void decr_idx() {
m_cur_idx--;
- debug_assert(m_cur_idx >= 0);
+ alloc_assert(m_cur_idx >= 0);
}
};
virtual bool is_allocated(int64_t start_block, int64_t num_blocks) = 0;
virtual bool is_exhausted() = 0;
virtual bool child_check_n_lock(BitMapArea *child, int64_t required) {
- debug_assert(0);
+ alloc_assert(0);
return true;
}
virtual bool child_check_n_lock(BitMapArea *child, int64_t required, bool lock) {
- debug_assert(0);
+ alloc_assert(0);
return true;
}
virtual void child_unlock(BitMapArea *child) {
- debug_assert(0);
+ alloc_assert(0);
}
virtual void lock_excl() = 0;
virtual bool lock_excl_try() {
- debug_assert(0);
+ alloc_assert(0);
return false;
}
virtual void lock_shared() {
- debug_assert(0);
+ alloc_assert(0);
return;
}
virtual void unlock() = 0;
virtual void shutdown() = 0;
virtual int64_t alloc_blocks(bool wait, int64_t num_blocks,
int64_t hint, int64_t *start_block) {
- debug_assert(0);
+ alloc_assert(0);
return 0;
}
virtual int64_t alloc_blocks(int64_t num_blocks, int64_t hint, int64_t *start_block) {
- debug_assert(0);
+ alloc_assert(0);
return 0;
}
virtual int64_t alloc_blocks_dis(bool wait, int64_t num_blocks,
int64_t hint, int64_t blk_off, ExtentList *block_list) {
- debug_assert(0);
+ alloc_assert(0);
return 0;
}
virtual int64_t alloc_blocks_dis(int64_t num_blocks,
int64_t hint, int64_t blk_off, ExtentList *block_list) {
- debug_assert(0);
+ alloc_assert(0);
return 0;
}
virtual void set_blocks_used(int64_t start_block, int64_t num_blocks) = 0;
virtual int64_t alloc_blocks(bool wait, int64_t num_blocks,
int64_t hint, int64_t *start_block) {
- debug_assert(0);
+ alloc_assert(0);
return 0;
}
virtual int64_t alloc_blocks_dis(bool wait, int64_t num_blocks,
int64_t hint, int64_t blk_off, int64_t *block_list) {
- debug_assert(0);
+ alloc_assert(0);
return 0;
}
virtual bool is_exhausted();
bool child_check_n_lock(BitMapArea *child, int64_t required, bool lock) {
- debug_assert(0);
+ alloc_assert(0);
return false;
}
BitMapAreaLeaf(int64_t zone_num, int64_t total_blocks, bool def);
bool child_check_n_lock(BitMapArea *child, int64_t required) {
- debug_assert(0);
+ alloc_assert(0);
return false;
}