summaryrefslogtreecommitdiff
path: root/src/evict.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-11-27 19:04:58 +0100
committerantirez <antirez@gmail.com>2017-11-28 12:18:30 +0100
commit06ca9d683920da19ad53532f8cd55b54584027bc (patch)
treea218e34989188e51f5b7a7a0b0ac33d6a5803b45 /src/evict.c
parent9f131c9a895fac9418cceb3a340627f2dac2162a (diff)
downloadredis-06ca9d683920da19ad53532f8cd55b54584027bc.tar.gz
LFU: Fix LFUDecrAndReturn() to just decrement.
Splitting the popularity in half actually just needs decrementing the counter because the counter is logarithmic.
Diffstat (limited to 'src/evict.c')
-rw-r--r--src/evict.c16
1 files changed, 3 insertions, 13 deletions
diff --git a/src/evict.c b/src/evict.c
index 55b132123..bf485ddc5 100644
--- a/src/evict.c
+++ b/src/evict.c
@@ -335,19 +335,9 @@ uint8_t LFULogIncr(uint8_t counter) {
unsigned long LFUDecrAndReturn(robj *o) {
unsigned long ldt = o->lru >> 8;
unsigned long counter = o->lru & 255;
- long halve_times = server.lfu_decay_time ? LFUTimeElapsed(ldt) / server.lfu_decay_time : 0;
- if (halve_times > 0 && counter) {
- if (halve_times == 1) {
- if (counter > LFU_INIT_VAL*2) {
- counter /= 2;
- if (counter < LFU_INIT_VAL*2) counter = LFU_INIT_VAL*2;
- } else {
- counter--;
- }
- } else {
- counter = counter >> halve_times;
- }
- }
+ unsigned long num_periods = server.lfu_decay_time ? LFUTimeElapsed(ldt) / server.lfu_decay_time : 0;
+ if (num_periods)
+ counter = (num_periods > counter) ? 0 : counter - num_periods;
return counter;
}