From: Sage Weil Date: Mon, 19 Aug 2019 15:09:36 +0000 (-0500) Subject: os/bluestore: try to gift large extents, then fall back to small extents X-Git-Tag: v12.2.13~146^2~2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=91a1fa17470b158ed1fe22a725cd42ac28344237;p=ceph.git os/bluestore: try to gift large extents, then fall back to small extents First try to gift using the larger alloc_size (normally bluefs_alloc_size, but here max(bluefs_alloc_size,bluefs_shared_alloc_size) just in case the settings are weird. If that fails, then try the shared_alloc_size. If that fails, fail and complain as before, with an more accurate error message. Signed-off-by: Sage Weil --- diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 06fdddd599d7..190189fb6bba 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -5346,21 +5346,40 @@ int BlueStore::_balance_bluefs_freespace(PExtentVector *extents) } if (gift) { - // round up to alloc size - gift = P2ROUNDUP(gift, cct->_conf->bluefs_alloc_size); - // hard cap to fit into 32 bits gift = MIN(gift, 1ull<<31); dout(10) << __func__ << " gifting " << gift << " (" << byte_u_t(gift) << ")" << dendl; - int64_t alloc_len = alloc->allocate(gift, - cct->_conf->bluefs_shared_alloc_size, + // first try to allocate larger chunks (usually the bluefs alloc + // size is larger, but behave regardless) + auto max_alloc_size = std::max( + cct->_conf->bluefs_alloc_size, + cct->_conf->bluefs_shared_alloc_size); + int64_t first_attempt = std::min(P2ROUNDUP(gift, max_alloc_size), + 1ull<<31); + int64_t alloc_len = alloc->allocate(first_attempt, max_alloc_size, 0, 0, extents); - if (alloc_len <= 0) { - dout(0) << __func__ << " no allocate on 0x" << std::hex << gift - << " min_alloc_size 0x" << min_alloc_size << std::dec << dendl; + // if that fails, then try the shared size... + int64_t second_attempt = + std::min(P2ROUNDUP(gift, cct->_conf->bluefs_shared_alloc_size), + 1ull<<31); + dout(10) << __func__ << " failed to alloc 0x " << std::hex << first_attempt + << " with larger chunks (0x" + << max_alloc_size + << "), fall back to 0x" << second_attempt + << " shared_alloc_size (0x" + << cct->_conf->bluefs_shared_alloc_size + << std::dec << ")" << dendl; + alloc_len = alloc->allocate( + second_attempt, + cct->_conf->bluefs_shared_alloc_size, + 0, 0, extents); + } + if (alloc_len <= 0 || alloc_len < gift) { + dout(0) << __func__ << " no allocate on 0x" << std::hex << gift << std::dec + << dendl; _dump_alloc_on_rebalance_failure(); return 0; } else if (alloc_len < (int64_t)gift) {