Skip to content

Commit

Permalink
cache dbNonEmptySlots
Browse files Browse the repository at this point in the history
  • Loading branch information
soloestoy committed Dec 5, 2023
1 parent 829239f commit 56dbef2
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/evict.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ int performEvictions(void) {
/* Evictions are performed on random keys that have nothing to do with the current command slot. */

while (mem_freed < (long long)mem_tofree) {
int j, k, i, l;
int j, k, i;
static unsigned int next_db = 0;
sds bestkey = NULL;
int bestdbid;
Expand Down Expand Up @@ -603,7 +603,9 @@ int performEvictions(void) {
if (current_db_keys == 0) continue;

total_keys += current_db_keys;
for (l = 0; l < dbNonEmptySlots(db, keyType); l++) {
int l = dbNonEmptySlots(db, keyType);
/* Do not exceed the number of non-empty slots when looping. */
while (l--) {
int slot = getFairRandomSlot(db, keyType);
dict = (keyType == DB_MAIN ? db->dict[slot] : db->expires[slot]);
sampled_keys += evictionPoolPopulate(i, slot, dict, db->dict[slot], pool);
Expand Down

0 comments on commit 56dbef2

Please sign in to comment.