]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: assert on improper releases in AvlAllocator
authorIgor Fedotov <ifedotov@suse.com>
Mon, 22 Aug 2022 14:29:27 +0000 (17:29 +0300)
committerJoshua Baergen <jbaergen@digitalocean.com>
Wed, 9 Apr 2025 19:39:02 +0000 (13:39 -0600)
Let's assert on unexpected unit release before we damage internal data structures.
Plus uniforms some logging output for avl/hybrid allocator with bitmap one to enable replay
tool usage.

Signed-off-by: Igor Fedotov <igor.fedotov@croit.io>
src/os/bluestore/AvlAllocator.cc
src/os/bluestore/HybridAllocator.cc

index afa541862fb8f3f64043906338526da972b70ecf..949e037c1121a68bc90fbb0b353700f3d6fc1508 100644 (file)
@@ -105,6 +105,16 @@ void AvlAllocator::_add_to_tree(uint64_t start, uint64_t size)
     rs_before = std::prev(rs_after);
   }
 
+  if ((rs_before != range_tree.end() && rs_before->end > start) ||
+      (rs_after != range_tree.end() && rs_after->start < end)) {
+    derr << __func__ << " inconsistent tree state " << std::hex
+         << " 0x" << start << "~" << end - start
+         << std::dec << dendl;
+    _dump();
+  }
+  ceph_assert(rs_before == range_tree.end() || rs_before->end <= start);
+  ceph_assert(rs_after == range_tree.end() || rs_after->start >= end);
+
   bool merge_before = (rs_before != range_tree.end() && rs_before->end == start);
   bool merge_after = (rs_after != range_tree.end() && rs_after->start == end);
 
@@ -169,6 +179,14 @@ void AvlAllocator::_remove_from_tree(uint64_t start, uint64_t size)
 
   auto rs = range_tree.find(range_t{start, end}, range_tree.key_comp());
   /* Make sure we completely overlap with someone */
+  if (rs == range_tree.end() ||
+      rs->start > start ||
+      rs->end < end) {
+    derr << __func__ << " inconsistent tree state " << std::hex
+         << " 0x" << rs->start << "~" << rs->end - rs->start
+         << std::dec << dendl;
+    _dump();
+  }
   ceph_assert(rs != range_tree.end());
   ceph_assert(rs->start <= start);
   ceph_assert(rs->end >= end);
@@ -292,7 +310,9 @@ int AvlAllocator::_allocate(
   if (start == -1ULL) {
     return -ENOSPC;
   }
-
+  dout(20) << __func__ << " allocated 0x" << std::hex
+           << start << "~" << size
+           << std::dec << dendl;
   _remove_from_tree(start, size);
 
   *offset = start;
@@ -306,9 +326,9 @@ void AvlAllocator::_release(const interval_set<uint64_t>& release_set)
     const auto offset = p.get_start();
     const auto length = p.get_len();
     ceph_assert(offset + length <= uint64_t(device_size));
-    ldout(cct, 10) << __func__ << std::hex
-      << " offset 0x" << offset
-      << " length 0x" << length
+    ldout(cct, 20) << __func__ << std::hex
+      << " 0x" << offset
+      << "~" << length
       << std::dec << dendl;
     _add_to_tree(offset, length);
   }
@@ -316,9 +336,9 @@ void AvlAllocator::_release(const interval_set<uint64_t>& release_set)
 
 void AvlAllocator::_release(const PExtentVector& release_set) {
   for (auto& e : release_set) {
-    ldout(cct, 10) << __func__ << std::hex
-      << " offset 0x" << e.offset
-      << " length 0x" << e.length
+    ldout(cct, 20) << __func__ << std::hex
+      << " 0x" << e.offset
+      << "~" << e.length
       << std::dec << dendl;
     _add_to_tree(e.offset, e.length);
   }
@@ -346,14 +366,20 @@ AvlAllocator::AvlAllocator(CephContext* cct,
     cct->_conf.get_val<Option::size_t>("bluestore_avl_alloc_ff_max_search_bytes")),
   range_count_cap(max_mem / sizeof(range_seg_t)),
   cct(cct)
-{}
+{
+  ldout(cct, 10) << __func__ << " 0x" << std::hex << get_capacity() << "/"
+                 << get_block_size() << std::dec << dendl;
+}
 
 AvlAllocator::AvlAllocator(CephContext* cct,
                           int64_t device_size,
                           int64_t block_size,
                           std::string_view name) :
   AvlAllocator(cct, device_size, block_size, 0 /* max_mem */, name)
-{}
+{
+  ldout(cct, 10) << __func__ << " 0x" << std::hex << get_capacity() << "/"
+                 << get_block_size() << std::dec << dendl;
+}
 
 AvlAllocator::~AvlAllocator()
 {
@@ -368,10 +394,10 @@ int64_t AvlAllocator::allocate(
   PExtentVector* extents)
 {
   ldout(cct, 10) << __func__ << std::hex
-                 << " want 0x" << want
-                 << " unit 0x" << unit
-                 << " max_alloc_size 0x" << max_alloc_size
-                 << " hint 0x" << hint
+                 << " 0x" << want
+                 << "/" << unit
+                 << "," << max_alloc_size
+                 << "," << hint
                  << std::dec << dendl;
   ceph_assert(std::has_single_bit(unit));
   ceph_assert(want % unit == 0);
@@ -446,8 +472,8 @@ void AvlAllocator::_foreach(
 void AvlAllocator::init_add_free(uint64_t offset, uint64_t length)
 {
   ldout(cct, 10) << __func__ << std::hex
-                 << " offset 0x" << offset
-                 << " length 0x" << length
+                 << " 0x" << offset
+                 << "~" << length
                  << std::dec << dendl;
   if (!length)
     return;
@@ -459,8 +485,8 @@ void AvlAllocator::init_add_free(uint64_t offset, uint64_t length)
 void AvlAllocator::init_rm_free(uint64_t offset, uint64_t length)
 {
   ldout(cct, 10) << __func__ << std::hex
-                 << " offset 0x" << offset
-                 << " length 0x" << length
+                 << " 0x" << offset
+                 << "~" << length
                  << std::dec << dendl;
   if (!length)
     return;
index 448fdc7cfe944e250dca3e51e4ad3009628e52f2..4282c6d9df4098b59c0b767199dd80d9cdddc534 100644 (file)
@@ -23,10 +23,10 @@ int64_t HybridAllocator::allocate(
   PExtentVector* extents)
 {
   ldout(cct, 10) << __func__ << std::hex
-                 << " want 0x" << want
-                 << " unit 0x" << unit
-                 << " max_alloc_size 0x" << max_alloc_size
-                 << " hint 0x" << hint
+                 << " 0x" << want
+                 << "/" << unit
+                 << "," << max_alloc_size
+                 << "," << hint
                  << std::dec << dendl;
   ceph_assert(std::has_single_bit(unit));
   ceph_assert(want % unit == 0);