From: Sage Weil Date: Thu, 11 Aug 2016 21:12:58 +0000 (-0400) Subject: os/bluestore/BitMapAllocator: align to min_alloc_size on init_rm_free X-Git-Tag: ses5-milestone5~94^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f15b569abe311e952d4fedad684beb2695163f09;p=ceph.git os/bluestore/BitMapAllocator: align to min_alloc_size on init_rm_free In init_add_free we only use the min_alloc_size aligned portion of the provided extent. Since we have some callers that add in free space and then take it back, make init_rm_free do the same. That way we can, e.g, init_add_free 0x1000~0x400000000 (alloc will add 0x10000~0x3ffffff0000) and then init_rm_free 0x1000~0x100000 (alloc will remove 0x10000~0xf0000). Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BitMapAllocator.cc b/src/os/bluestore/BitMapAllocator.cc index 3ca40af418bd..6f49bdb27f65 100644 --- a/src/os/bluestore/BitMapAllocator.cc +++ b/src/os/bluestore/BitMapAllocator.cc @@ -303,13 +303,20 @@ void BitMapAllocator::init_rm_free(uint64_t offset, uint64_t length) << " length 0x" << length << std::dec << dendl; - assert(!(offset % m_block_size)); - assert(!(length % m_block_size)); + // we use the same adjustment/alignment that init_add_free does + // above so that we can yank back some of the space. + uint64_t offset_adj = ROUND_UP_TO(offset, m_block_size); + uint64_t length_adj = ((length - (offset_adj - offset)) / + m_block_size) * m_block_size; + + assert(!(offset_adj % m_block_size)); + assert(!(length_adj % m_block_size)); - int64_t first_blk = offset / m_block_size; - int64_t count = length / m_block_size; + int64_t first_blk = offset_adj / m_block_size; + int64_t count = length_adj / m_block_size; - m_bit_alloc->set_blocks_used(first_blk, count); + if (count) + m_bit_alloc->set_blocks_used(first_blk, count); }