]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
os/bluestore: fix the demotion in StupidAllocator::init_rm_free 21995/head
authorKefu Chai <kchai@redhat.com>
Wed, 14 Feb 2018 04:17:06 +0000 (12:17 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 15 May 2018 06:15:35 +0000 (14:15 +0800)
* we should update the _size field when demotion kicks in, otherwise the
  interval_set::m and interval_set::_size won't be consistent.
* also rename post_process to claim, as it "steals" the leftover(s) of
chopped segment.

Fixes: https://tracker.ceph.com/issues/24051
Signed-off-by: Kefu Chai <kchai@redhat.com>
(cherry picked from commit d43c8da83329dd743c635869b1443366d03839fd)

src/include/interval_set.h
src/os/bluestore/StupidAllocator.cc

index 09475e52f15014f91d04bd8d5ff8ab424bf6af38..185285d6775f1efc820b3fdf9d4ebab24d820d7d 100644 (file)
@@ -517,8 +517,8 @@ class interval_set {
     erase(val, 1);
   }
 
-  void erase(T start, T len,
-    std::function<bool(T, T)> post_process = {}) {
+  void erase(T start, T len, 
+    std::function<bool(T, T)> claim = {}) {
     typename Map::iterator p = find_inc_m(start);
 
     _size -= len;
@@ -530,13 +530,22 @@ class interval_set {
     T before = start - p->first;
     assert(p->second >= before+len);
     T after = p->second - before - len;
-    if (before && (post_process ? post_process(p->first, before) : true)) {
-      p->second = before;        // shorten bit before
+    if (before) {
+      if (claim && claim(p->first, before)) {
+       _size -= before;
+       m.erase(p);
+      } else {
+       p->second = before;        // shorten bit before
+      }
     } else {
       m.erase(p);
     }
-    if (after && (post_process ? post_process(start + len, after) : true)) {
-      m[start + len] = after;
+    if (after) {
+      if (claim && claim(start + len, after)) {
+       _size -= after;
+      } else {
+       m[start + len] = after;
+      }
     }
   }
 
index 7e3402a720b6daf09c762a17dd91f125cfbe783f..65d7baf59d8b1b31cfdbc5d05af9f6f3367c6dc5 100644 (file)
@@ -306,9 +306,9 @@ void StupidAllocator::init_rm_free(uint64_t offset, uint64_t length)
               ldout(cct, 30) << __func__ << " demoting1 0x" << std::hex << off << "~" << len
                              << std::dec << " to bin " << newbin << dendl;
               _insert_free(off, len);
-              return false;
+              return true;
             }
-            return true;
+            return false;
           });
         ++it;
       }