Skip to content

Commit 2b05c95

Browse files
committed
MB-58576 [1/2]: Fix memory tracking in StrictQuotaItemPager
StrictQuotaItemPager - as introduced via MB-53053 for cross-Bucket frequency counter based eviction (specifically https://review.couchbase.org/c/kv_engine/+/183324) - constructs its base class GlobalTask via the ctor taking a Taskable, not the ctor taking a EventuallyPersistentEngine. This is problematic as when the task runs, the execution pools do not switch to the current engine (as GlobalTask::engine is null) - and as a result any (de)allocations made - say during paging - are not correctly accounted to the associated bucket - they end up being accounted to the 'NoBucket'. The bug is somewhat subtle, as ItemPager has it's /own/ 'engine' member variable (which is initialised correctly), however given this shadows the (null) base class one which is used by the ExecutorPool to setup the current engine, we end up with switched to a null engine. Fix by adding an ItemPager ctor taking an Engine and using that for StrictQuotaItemPager. Change-Id: I4e13d547e4e21f1e67e65bbe06d41f05bbc11ac9 Reviewed-on: https://review.couchbase.org/c/kv_engine/+/196871 Reviewed-by: Trond Norbye <[email protected]> Tested-by: Build Bot <[email protected]>
1 parent f8a7451 commit 2b05c95

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

engines/ep/src/item_pager.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ ItemPager::ItemPager(Taskable& t,
5858
sleepTime(sleepTime) {
5959
}
6060

61+
ItemPager::ItemPager(EventuallyPersistentEngine& engine,
62+
size_t numConcurrentPagers,
63+
std::chrono::milliseconds sleepTime)
64+
: ItemPager(engine.getTaskable(), numConcurrentPagers, sleepTime) {
65+
GlobalTask::engine = &engine;
66+
}
67+
6168
std::optional<VBucketFilter> ItemPager::createVBucketFilter(
6269
KVBucket& kvBucket, PermittedVBStates acceptedStates) {
6370
VBucketFilter filter;
@@ -93,11 +100,10 @@ PermittedVBStates ItemPager::getStatesForEviction(EvictionRatios ratios) const {
93100
StrictQuotaItemPager::StrictQuotaItemPager(EventuallyPersistentEngine& e,
94101
EPStats& st,
95102
size_t numConcurrentPagers)
96-
: ItemPager(e.getTaskable(),
103+
: ItemPager(e,
97104
numConcurrentPagers,
98105
std::chrono::milliseconds(
99106
e.getConfiguration().getPagerSleepTimeMs())),
100-
engine(e),
101107
stats(st) {
102108
}
103109

@@ -139,7 +145,7 @@ EvictionRatios StrictQuotaItemPager::getEvictionRatios(
139145
}
140146

141147
ItemPager::PageableMemInfo StrictQuotaItemPager::getPageableMemInfo() const {
142-
KVBucket* kvBucket = engine.getKVBucket();
148+
KVBucket* kvBucket = engine->getKVBucket();
143149
auto current = kvBucket->getPageableMemCurrent();
144150
auto upper = kvBucket->getPageableMemHighWatermark();
145151
auto lower = kvBucket->getPageableMemLowWatermark();
@@ -183,15 +189,15 @@ bool ItemPager::runInner(bool manuallyNotified) {
183189
std::function<std::unique_ptr<ItemEvictionStrategy>()>
184190
StrictQuotaItemPager::getEvictionStrategyFactory(
185191
EvictionRatios evictionRatios) {
186-
const auto& cfg = engine.getConfiguration();
192+
const auto& cfg = engine->getConfiguration();
187193

188194
auto strategy = cfg.getItemEvictionStrategy();
189195

190196
if (strategy == "upfront_mfu_only") {
191197
MFUHistogram activePendingMFUHist;
192198
MFUHistogram replicaMFUHist;
193199

194-
KVBucket* kvBucket = engine.getKVBucket();
200+
KVBucket* kvBucket = engine->getKVBucket();
195201
for (auto& vbucket : kvBucket->getVBuckets()) {
196202
switch (vbucket.getState()) {
197203
case vbucket_state_active:
@@ -278,7 +284,7 @@ size_t ItemPager::getEvictableBytes(KVBucket& kvBucket,
278284
}
279285

280286
void StrictQuotaItemPager::schedulePagingVisitors(std::size_t bytesToEvict) {
281-
auto* kvBucket = engine.getKVBucket();
287+
auto* kvBucket = engine->getKVBucket();
282288
if (kvBucket->getItemEvictionPolicy() == EvictionPolicy::Value) {
283289
doEvict = true;
284290
}

engines/ep/src/item_pager.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,16 @@ class Semaphore;
4242
*/
4343
class ItemPager : public NotifiableTask {
4444
public:
45+
// ctor when ItemPager is not associated with a specific bucket.
4546
ItemPager(Taskable& t,
4647
size_t numConcurrentPagers,
4748
std::chrono::milliseconds sleepTime);
4849

50+
// ctor when Item pager is associated with a specific bucket.
51+
ItemPager(EventuallyPersistentEngine& engine,
52+
size_t numConcurrentPagers,
53+
std::chrono::milliseconds sleepTime);
54+
4955
bool runInner(bool manuallyNotified) override;
5056

5157
std::chrono::microseconds getSleepTime() const override {
@@ -170,7 +176,6 @@ class StrictQuotaItemPager : public ItemPager {
170176
*/
171177
void resetPhase();
172178

173-
EventuallyPersistentEngine& engine;
174179
EPStats& stats;
175180
};
176181

0 commit comments

Comments
 (0)