summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2016-07-18 14:19:38 +0200
committerantirez <antirez@gmail.com>2016-07-18 14:19:38 +0200
commitdbce190ad018fc757d9c494952531db31eaac700 (patch)
tree29288ae55f701a2a04c59aade6b641bb45eb16ee
parenta8e2d0849e2a40f8bec14cd1b7ff170c17f772c3 (diff)
downloadredis-dbce190ad018fc757d9c494952531db31eaac700.tar.gz
LFU: Fix bugs in frequency decay code.
-rw-r--r--src/evict.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/evict.c b/src/evict.c
index b48892b41..3025b3e9b 100644
--- a/src/evict.c
+++ b/src/evict.c
@@ -264,7 +264,7 @@ unsigned long LFUGetTimeInMinutes(void) {
* exactly once. */
unsigned long LFUTimeElapsed(unsigned long ldt) {
unsigned long now = LFUGetTimeInMinutes();
- if (now > ldt) return now-ldt;
+ if (now >= ldt) return now-ldt;
return 65535-ldt+now;
}
@@ -291,7 +291,7 @@ uint8_t LFULogIncr(uint8_t counter) {
unsigned long LFUDecrAndReturn(robj *o) {
unsigned long ldt = o->lru >> 8;
unsigned long counter = o->lru & 255;
- if (LFUTimeElapsed(ldt) > LFU_DECR_INTERVAL && counter) {
+ if (LFUTimeElapsed(ldt) >= LFU_DECR_INTERVAL && counter) {
if (counter > LFU_INIT_VAL*2) {
counter /= 2;
if (counter < LFU_INIT_VAL*2) counter = LFU_INIT_VAL*2;