Skip to content

Commit

Permalink
MB-49469: Introduce CM::Counter::memFreedByCheckpointRemoval
Browse files Browse the repository at this point in the history
That accounts the memory released by CheckpointRemoval by a specific CM
instance.

The new quantity will be used in a follow-up for computing and exposing
new vb_{state} aggregates for the same quantity.

Change-Id: Iba966b559f7c7ced03bba234c66f83be906141f2
Reviewed-on: https://review.couchbase.org/c/kv_engine/+/169679
Tested-by: Build Bot <build@couchbase.com>
Reviewed-by: Richard de Mellow <richard.demellow@couchbase.com>
  • Loading branch information
paolococchi authored and daverigby committed Feb 4, 2022
1 parent d40f2a9 commit 0076f38
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
9 changes: 7 additions & 2 deletions engines/ep/src/checkpoint_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ CheckpointManager::CheckpointManager(EPStats& st,
maxVisibleSeqno(maxVisibleSeqno),
flusherCB(std::move(cb)),
checkpointDisposer(std::move(checkpointDisposer)),
memFreedByExpel(stats.memFreedByCheckpointItemExpel) {
memFreedByExpel(stats.memFreedByCheckpointItemExpel),
memFreedByCheckpointRemoval(stats.memFreedByCheckpointRemoval) {
std::lock_guard<std::mutex> lh(queueLock);

lastBySeqno.setLabel("CheckpointManager(" + vb.getId().to_string() +
Expand Down Expand Up @@ -559,7 +560,7 @@ CheckpointManager::updateStatsForCheckpointRemoval(
}
numItems.fetch_sub(numNonMetaItemsRemoved + numMetaItemsRemoved);
stats.itemsRemovedFromCheckpoints.fetch_add(numNonMetaItemsRemoved);
stats.memFreedByCheckpointRemoval += memoryReleased;
memFreedByCheckpointRemoval += memoryReleased;

EP_LOG_DEBUG(
"CheckpointManager::updateStatsForCheckpointRemoval: Removed {} "
Expand Down Expand Up @@ -2045,4 +2046,8 @@ CheckpointManager::Counter& CheckpointManager::Counter::operator-=(

size_t CheckpointManager::getMemFreedByItemExpel() const {
return memFreedByExpel;
}

size_t CheckpointManager::getMemFreedByCheckpointRemoval() const {
return memFreedByCheckpointRemoval;
}
5 changes: 5 additions & 0 deletions engines/ep/src/checkpoint_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,8 @@ class CheckpointManager {
// @return the amount of memory (in bytes) released by ItemExpel
size_t getMemFreedByItemExpel() const;

size_t getMemFreedByCheckpointRemoval() const;

/**
* Member std::function variable, to allow us to inject code into
* removeCursor() for unit MB36146
Expand Down Expand Up @@ -990,6 +992,9 @@ class CheckpointManager {
// Memory released by item expel in this CM
Counter memFreedByExpel;

// Memory released by checkpoint removal in this CM
Counter memFreedByCheckpointRemoval;

friend std::ostream& operator<<(std::ostream& os, const CheckpointManager& m);
};

Expand Down
2 changes: 1 addition & 1 deletion engines/ep/src/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ class EPStats {
Counter cursorsDropped;

//! Amount of memory we have freed by checkpoint removal
std::atomic<size_t> memFreedByCheckpointRemoval;
Counter memFreedByCheckpointRemoval;

//! Amount of memory we have freed by checkpoint item expel
Counter memFreedByCheckpointItemExpel;
Expand Down
10 changes: 9 additions & 1 deletion engines/ep/tests/module_tests/checkpoint_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3738,10 +3738,14 @@ TEST_P(CheckpointMemoryTrackingTest, CheckpointManagerMemUsageAtRemoval) {
testCheckpointManagerMemUsage();

// confirm that no items have been removed from the checkpoint manager
ASSERT_EQ(0, engine->getEpStats().itemsRemovedFromCheckpoints);
const auto& stats = engine->getEpStats();
ASSERT_EQ(0, stats.itemsRemovedFromCheckpoints);
ASSERT_EQ(0, stats.memFreedByCheckpointRemoval);

auto vb = store->getVBuckets().getBucket(vbid);
auto& manager = static_cast<MockCheckpointManager&>(*vb->checkpointManager);
ASSERT_EQ(0, manager.getMemFreedByCheckpointRemoval());

// set the eager checkpoint disposer to allow checkpoints to be destroyed
// "inline" when removed. This avoids needing to drive background tasks.
manager.setCheckpointDisposer(ImmediateCkptDisposer);
Expand Down Expand Up @@ -3812,6 +3816,10 @@ TEST_P(CheckpointMemoryTrackingTest, CheckpointManagerMemUsageAtRemoval) {
EXPECT_EQ(queued + index + queueOverhead,
engine->getEpStats().getCheckpointManagerEstimatedMemUsage());
EXPECT_EQ(queued + index + queueOverhead, manager.getEstimatedMemUsage());

EXPECT_GT(manager.getMemFreedByCheckpointRemoval(), 0);
EXPECT_EQ(manager.getMemFreedByCheckpointRemoval(),
stats.memFreedByCheckpointRemoval);
}

TEST_P(CheckpointMemoryTrackingTest, BackgroundTaskIsNotified) {
Expand Down

0 comments on commit 0076f38

Please sign in to comment.