]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/mempool: tolerate sum < 0 14982/head
authorSage Weil <sage@redhat.com>
Tue, 30 Oct 2018 20:35:23 +0000 (15:35 -0500)
committerSage Weil <sage@redhat.com>
Tue, 30 Oct 2018 20:35:23 +0000 (15:35 -0500)
If we are adding up the shards, and race with some allocations and
deallocations, we might get a negative sum.  E.g., with 2 shards, intially
[0,0],

- A: read shard 0 (0)
- B: allocate object on shard 0 (now 1)
- C: dallocate object on shard 1 (now -1)
- A: read shard 1 (-1)
- A: sum is -1

Signed-off-by: Sage Weil <sage@redhat.com>
src/common/mempool.cc

index cb9de40da093d22de2a208e3f4adc8e7731b01ef..fd9a42d8f52ba8d0a9f0049b6d082fe363f64f87 100644 (file)
@@ -70,7 +70,10 @@ size_t mempool::pool_t::allocated_bytes() const
   for (size_t i = 0; i < num_shards; ++i) {
     result += shard[i].bytes;
   }
-  ceph_assert(result >= 0);
+  if (result < 0) {
+    // we raced with some unbalanced allocations/deallocations
+    result = 0;
+  }
   return (size_t) result;
 }
 
@@ -80,7 +83,10 @@ size_t mempool::pool_t::allocated_items() const
   for (size_t i = 0; i < num_shards; ++i) {
     result += shard[i].items;
   }
-  ceph_assert(result >= 0);
+  if (result < 0) {
+    // we raced with some unbalanced allocations/deallocations
+    result = 0;
+  }
   return (size_t) result;
 }