jplevyak commented on code in PR #13893:
URL: https://github.com/apache/trafficserver/pull/13893#discussion_r4366122967


##########
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:
   Agreed. The cap was only meant to bound entry epoch differences. Fixed in 
833424347: entry epochs still advance by at most 32, which clears any 32-bit 
hit count, but `_average_value` now decays by the full interval count. The 
long-idle test asserts exactly 2⁻⁴⁰ after 40 intervals.



-- 
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]

Reply via email to