valkey icon indicating copy to clipboard operation
valkey copied to clipboard

Refactor of LFU/LRU code for modularity

Open JimB123 opened this issue 1 month ago • 0 comments

General cleanup on LRU/LFU code. Improve modularity and maintainability.

Specifically:

  • Consolidates the mathematical logic for LRU/LFU into lrulfu.c, with an API in lrulfu.h. Knowledge of the LRU/LFU implementation was previously spread out across db.c, evict.c, object.c, server.c, and server.h.
  • Separates knowledge of the LRU from knowledge of the object containing the LRU value. lrulfu.c knows about the LRU/LFU algorithms, without knowing about the robj. object.c knows about the robj without knowing about the details of the LRU/LFU algorithms.
  • Eliminated server.lruclock, instead using server.unixtime. This also eliminates the periodic need to call mstime() to maintain the lru clock.
  • Fixed a minor computation bug in the old LFUTimeElapsed function (off by 1 after rollover).
  • Eliminate specific IF checks for rollover, using defined behavior for unsigned rollover instead.
  • Fixed a bug in debug.c which would perform LFU modification on an LRU value.

JimB123 avatar Nov 19 '25 18:11 JimB123