From: Ramesh Chander Date: Mon, 6 Jun 2016 17:26:44 +0000 (-0700) Subject: remove truncation of unaligned blocks at init X-Git-Tag: v11.0.0~246^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4bc4b2bfa8b654999d83a0d18575d4b1baa717db;p=ceph.git remove truncation of unaligned blocks at init Signed-off-by: Ramesh Chander --- diff --git a/src/os/bluestore/BitAllocator.cc b/src/os/bluestore/BitAllocator.cc index c4d009dea2bd..d0c368e321e5 100644 --- a/src/os/bluestore/BitAllocator.cc +++ b/src/os/bluestore/BitAllocator.cc @@ -23,7 +23,6 @@ #include #define debug_assert assert -#define MIN(x, y) ((x) > (y) ? (y) : (x)) #define MAX_INT16 ((uint16_t) -1 >> 1) #define MAX_INT32 ((uint32_t) -1 >> 1) @@ -1231,7 +1230,7 @@ BitAllocator::BitAllocator(int64_t total_blocks, int64_t zone_size_block, void BitAllocator::init_check(int64_t total_blocks, int64_t zone_size_block, bmap_alloc_mode_t mode, bool def, bool stats_on) { - int64_t total_zones = 0; + int64_t unaligned_blocks = 0; if (mode != SERIAL && mode != CONCURRENT) { debug_assert(0); @@ -1253,12 +1252,9 @@ void BitAllocator::init_check(int64_t total_blocks, int64_t zone_size_block, debug_assert(0); } - truncated_blocks = total_blocks - (total_blocks / zone_size_block) * zone_size_block; - total_blocks = (total_blocks / zone_size_block) * zone_size_block; - total_zones = total_blocks / zone_size_block; + unaligned_blocks = total_blocks % zone_size_block; + total_blocks = ROUND_UP_TO(total_blocks, zone_size_block); - debug_assert(total_blocks > 0); - debug_assert(total_zones > 0); m_alloc_mode = mode; m_is_stats_on = stats_on; if (m_is_stats_on) { @@ -1267,6 +1263,13 @@ void BitAllocator::init_check(int64_t total_blocks, int64_t zone_size_block, pthread_rwlock_init(&m_rw_lock, NULL); init(total_blocks, 0, def); + if (!def && unaligned_blocks) { + /* + * Mark extra padded blocks used from begning. + */ + set_blocks_used(total_blocks - (zone_size_block - unaligned_blocks), + (zone_size_block - unaligned_blocks)); + } } void BitAllocator::lock_excl() @@ -1485,6 +1488,7 @@ void BitAllocator::free_blocks(int64_t start_block, int64_t num_blocks) return; } + debug_assert(start_block + num_blocks <= size()); if (is_stats_on()) { m_stats->add_free_calls(1); m_stats->add_freed(num_blocks); @@ -1506,6 +1510,7 @@ void BitAllocator::set_blocks_used(int64_t start_block, int64_t num_blocks) return; } + debug_assert(start_block + num_blocks <= size()); lock_shared(); serial_lock(); set_blocks_used_int(start_block, num_blocks); diff --git a/src/os/bluestore/BitAllocator.h b/src/os/bluestore/BitAllocator.h index 565472cf21bb..9e59edfc415c 100644 --- a/src/os/bluestore/BitAllocator.h +++ b/src/os/bluestore/BitAllocator.h @@ -17,6 +17,7 @@ #include #include #include +#include "include/intarith.h" class BitAllocatorStats { public: diff --git a/src/os/bluestore/BitMapAllocator.cc b/src/os/bluestore/BitMapAllocator.cc index 00aa078c5b96..57356704bec0 100644 --- a/src/os/bluestore/BitMapAllocator.cc +++ b/src/os/bluestore/BitMapAllocator.cc @@ -18,7 +18,6 @@ #undef dout_prefix #define dout_prefix *_dout << "bitmapalloc:" -#define NEXT_MULTIPLE(x, m) (!(x) ? 0: (((((x) - 1) / (m)) + 1) * (m))) BitMapAllocator::BitMapAllocator(int64_t device_size) : m_num_uncommitted(0), @@ -161,16 +160,8 @@ void BitMapAllocator::init_add_free(uint64_t offset, uint64_t length) dout(10) << __func__ <<" instance "<< (uint64_t) this << " offset " << offset << " length " << length << dendl; - offset = NEXT_MULTIPLE(offset, m_block_size); - - // bitallocator::init may decrease the size of blkdev. - uint64_t total_size = m_bit_alloc->size() * m_block_size; - if (offset + length > total_size) { - assert(offset + length < total_size + m_bit_alloc->get_truncated_blocks() * m_block_size); - length -= (offset + length) - total_size; - } - - insert_free(offset, (length / m_block_size) * m_block_size); + insert_free(ROUND_UP_TO(offset, m_block_size), + (length / m_block_size) * m_block_size); } void BitMapAllocator::init_rm_free(uint64_t offset, uint64_t length) diff --git a/src/test/objectstore/BitAllocator_test.cc b/src/test/objectstore/BitAllocator_test.cc index bb5f61eea586..dcff99b3fcf9 100644 --- a/src/test/objectstore/BitAllocator_test.cc +++ b/src/test/objectstore/BitAllocator_test.cc @@ -408,6 +408,22 @@ TEST(BitAllocator, test_bmap_alloc) alloc->free_blocks(0, alloc->size()); delete alloc; + // unaligned zones + total_blocks = 1024 * 2 + 11; + alloc = new BitAllocator(total_blocks, zone_size, CONCURRENT); + + for (int64_t iter = 0; iter < 4; iter++) { + for (int64_t i = 0; i < total_blocks; i++) { + allocated = alloc->alloc_blocks(1, &start_block); + bmap_test_assert(allocated == 1); + bmap_test_assert(start_block == i); + } + + for (int64_t i = 0; i < total_blocks; i++) { + alloc->free_blocks(i, 1); + } + } + // Make three > 3 levels tree and check allocations and dealloc // in a loop int64_t alloc_size = 16;