From 02949bb37d714a65183e89810e731713933d055c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 30 Oct 2018 15:35:23 -0500 Subject: [PATCH] common/mempool: tolerate sum < 0 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 --- src/common/mempool.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/common/mempool.cc b/src/common/mempool.cc index cb9de40da093d..fd9a42d8f52ba 100644 --- a/src/common/mempool.cc +++ b/src/common/mempool.cc @@ -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; } -- 2.39.5