From: Sage Weil Date: Tue, 30 Oct 2018 20:35:23 +0000 (-0500) Subject: common/mempool: tolerate sum < 0 X-Git-Tag: v14.1.0~996^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F14982%2Fhead;p=ceph.git 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 --- diff --git a/src/common/mempool.cc b/src/common/mempool.cc index cb9de40da09..fd9a42d8f52 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; }