mirror of
https://github.com/fluencelabs/redis
synced 2025-03-19 09:00:51 +00:00
LFU: Fix LFUDecrAndReturn() to just decrement.
Splitting the popularity in half actually just needs decrementing the counter because the counter is logarithmic.
This commit is contained in:
parent
9f131c9a89
commit
06ca9d6839
16
src/evict.c
16
src/evict.c
@ -335,19 +335,9 @@ uint8_t LFULogIncr(uint8_t counter) {
|
|||||||
unsigned long LFUDecrAndReturn(robj *o) {
|
unsigned long LFUDecrAndReturn(robj *o) {
|
||||||
unsigned long ldt = o->lru >> 8;
|
unsigned long ldt = o->lru >> 8;
|
||||||
unsigned long counter = o->lru & 255;
|
unsigned long counter = o->lru & 255;
|
||||||
long halve_times = server.lfu_decay_time ? LFUTimeElapsed(ldt) / server.lfu_decay_time : 0;
|
unsigned long num_periods = server.lfu_decay_time ? LFUTimeElapsed(ldt) / server.lfu_decay_time : 0;
|
||||||
if (halve_times > 0 && counter) {
|
if (num_periods)
|
||||||
if (halve_times == 1) {
|
counter = (num_periods > counter) ? 0 : counter - num_periods;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user