Copilot commented on code in PR #13893:
URL: https://github.com/apache/trafficserver/pull/13893#discussion_r4366103236
##########
src/iocore/cache/RamCacheCLFUS.cc:
##########
@@ -243,6 +247,38 @@ RamCacheCLFUS::init(int64_t abytes, StripeSM *astripe)
}
}
+// Advance one epoch for every full decay interval that has elapsed, so idle
+// periods age popularity as much as busy ones. Called from both get() and
+// put() so that hit-only traffic still ages entries.
+void
+RamCacheCLFUS::_decay_epochs()
+{
+ ink_hrtime now = ink_get_hrtime();
+ ink_hrtime elapsed = now - this->_last_decay_time;
+
+ if (elapsed < decay_interval) {
+ return;
+ }
+ // 32 or more epochs clears every hit count, so the advance can be capped
+ // without changing the result while keeping _epoch differences in range.
+ int epochs = static_cast<int>(std::min<ink_hrtime>(elapsed /
decay_interval, 32));
+ this->_epoch += epochs;
+ this->_average_value = std::ldexp(this->_average_value, -epochs);
Review Comment:
The 32-epoch cap clears `uint32_t` hit counts, but stops `_average_value`
from aging by all elapsed intervals. After 40 idle intervals, an average of 8
becomes approximately 1.86e-9 instead of 7.28e-12, leaving the threshold above
its intended value. Keep the capped advance for entry epochs, decay the average
by the full interval count, and assert the expected value in the long-idle test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]