From: Adam Kupczyk Date: Wed, 19 May 2021 10:49:37 +0000 (+0200) Subject: os/bluestore: Improve _block_picker function X-Git-Tag: v16.2.8~302^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=a3ea37622ee2d0df6f213ac835d00895ad55e8d4;p=ceph.git os/bluestore: Improve _block_picker function Make _block_picker function scan (*cursor, end) + (begin, *cursor) instead of (*cursor, end) + (begin, end). The second run over range (*cursor, end) could never yield any results. Signed-off-by: Adam Kupczyk (cherry picked from commit c732060d3e3ef96c6da06c9dde3ed8c064a50965) Signed-off-by: Mauricio Faria de Oliveira --- diff --git a/src/os/bluestore/AvlAllocator.cc b/src/os/bluestore/AvlAllocator.cc index 806545bf08f..fc5d91d3fb3 100644 --- a/src/os/bluestore/AvlAllocator.cc +++ b/src/os/bluestore/AvlAllocator.cc @@ -44,15 +44,19 @@ uint64_t AvlAllocator::_block_picker(const Tree& t, return offset; } } - /* - * If we know we've searched the whole tree (*cursor == 0), give up. - * Otherwise, reset the cursor to the beginning and try again. - */ - if (*cursor == 0 || rs_start == t.begin()) { - return -1ULL; - } - *cursor = 0; - return _block_picker(t, cursor, size, align); + if (*cursor == 0) { + // If we already started from beginning, don't bother with searching from beginning + return -1ULL; + } + // If we reached end, start from beginning till cursor. + for (auto rs = t.begin(); rs != rs_start; ++rs) { + uint64_t offset = p2roundup(rs->start, align); + if (offset + size <= rs->end) { + *cursor = offset + size; + return offset; + } + } + return -1ULL; } void AvlAllocator::_add_to_tree(uint64_t start, uint64_t size)