]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: Improve _block_picker function
authorAdam Kupczyk <akupczyk@redhat.com>
Wed, 19 May 2021 10:49:37 +0000 (12:49 +0200)
committerMauricio Faria de Oliveira <mfo@canonical.com>
Wed, 10 Nov 2021 15:07:56 +0000 (12:07 -0300)
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 <akupczyk@redhat.com>
(cherry picked from commit c732060d3e3ef96c6da06c9dde3ed8c064a50965)
Signed-off-by: Mauricio Faria de Oliveira <mfo@canonical.com>
src/os/bluestore/AvlAllocator.cc

index 9b148b6810d9d8dc5bad3ea467eb256f427ac4fa..50ac77fd7597f83b3f2977f0a8ba8e67b723505a 100644 (file)
@@ -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)