Unverified Commit 2f6d4dab authored by Binbin's avatar Binbin Committed by GitHub
Browse files

Fix outdated LFU comments to eliminate confusion (#12244)

The decrement time was replaced by access time in
583c3147.

The halved and doubled LFU_INIT_VAL logic has been changed in
06ca9d68.
Now we just decrement the counter by num_periods. This has been
previously fixed in redis.conf, #11108.
parent 77e69d88
...@@ -252,42 +252,40 @@ int evictionPoolPopulate(int dbid, int slot, dict *sampledict, dict *keydict, st ...@@ -252,42 +252,40 @@ int evictionPoolPopulate(int dbid, int slot, dict *sampledict, dict *keydict, st
* *
* We split the 24 bits into two fields: * We split the 24 bits into two fields:
* *
* 16 bits 8 bits * 16 bits 8 bits
* +----------------+--------+ * +------------------+--------+
* + Last decr time | LOG_C | * + Last access time | LOG_C |
* +----------------+--------+ * +------------------+--------+
* *
* LOG_C is a logarithmic counter that provides an indication of the access * LOG_C is a logarithmic counter that provides an indication of the access
* frequency. However this field must also be decremented otherwise what used * frequency. However this field must also be decremented otherwise what used
* to be a frequently accessed key in the past, will remain ranked like that * to be a frequently accessed key in the past, will remain ranked like that
* forever, while we want the algorithm to adapt to access pattern changes. * forever, while we want the algorithm to adapt to access pattern changes.
* *
* So the remaining 16 bits are used in order to store the "decrement time", * So the remaining 16 bits are used in order to store the "access time",
* a reduced-precision Unix time (we take 16 bits of the time converted * a reduced-precision Unix time (we take 16 bits of the time converted
* in minutes since we don't care about wrapping around) where the LOG_C * in minutes since we don't care about wrapping around) where the LOG_C
* counter is halved if it has an high value, or just decremented if it * counter decays every minute by default (depends on lfu-decay-time).
* has a low value.
* *
* New keys don't start at zero, in order to have the ability to collect * New keys don't start at zero, in order to have the ability to collect
* some accesses before being trashed away, so they start at LFU_INIT_VAL. * some accesses before being trashed away, so they start at LFU_INIT_VAL.
* The logarithmic increment performed on LOG_C takes care of LFU_INIT_VAL * The logarithmic increment performed on LOG_C takes care of LFU_INIT_VAL
* when incrementing the key, so that keys starting at LFU_INIT_VAL * when incrementing the key, so that keys starting at LFU_INIT_VAL
* (or having a smaller value) have a very high chance of being incremented * (or having a smaller value) have a very high chance of being incremented
* on access. * on access. (The chance depends on counter and lfu-log-factor.)
* *
* During decrement, the value of the logarithmic counter is halved if * During decrement, the value of the logarithmic counter is decremented by
* its current value is greater than two times the LFU_INIT_VAL, otherwise * one when lfu-decay-time minutes elapsed.
* it is just decremented by one.
* --------------------------------------------------------------------------*/ * --------------------------------------------------------------------------*/
/* Return the current time in minutes, just taking the least significant /* Return the current time in minutes, just taking the least significant
* 16 bits. The returned time is suitable to be stored as LDT (last decrement * 16 bits. The returned time is suitable to be stored as LDT (last access
* time) for the LFU implementation. */ * time) for the LFU implementation. */
unsigned long LFUGetTimeInMinutes(void) { unsigned long LFUGetTimeInMinutes(void) {
return (server.unixtime/60) & 65535; return (server.unixtime/60) & 65535;
} }
/* Given an object last access time, compute the minimum number of minutes /* Given an object ldt (last access time), compute the minimum number of minutes
* that elapsed since the last access. Handle overflow (ldt greater than * that elapsed since the last access. Handle overflow (ldt greater than
* the current 16 bits minutes time) considering the time as wrapping * the current 16 bits minutes time) considering the time as wrapping
* exactly once. */ * exactly once. */
...@@ -309,10 +307,10 @@ uint8_t LFULogIncr(uint8_t counter) { ...@@ -309,10 +307,10 @@ uint8_t LFULogIncr(uint8_t counter) {
return counter; return counter;
} }
/* If the object decrement time is reached decrement the LFU counter but /* If the object's ldt (last access time) is reached, decrement the LFU counter but
* do not update LFU fields of the object, we update the access time * do not update LFU fields of the object, we update the access time
* and counter in an explicit way when the object is really accessed. * and counter in an explicit way when the object is really accessed.
* And we will times halve the counter according to the times of * And we will decrement the counter according to the times of
* elapsed time than server.lfu_decay_time. * elapsed time than server.lfu_decay_time.
* Return the object frequency counter. * Return the object frequency counter.
* *
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment