Skip to content

Commit

Permalink
add Ping logic and do a little bit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
hwware committed Dec 3, 2024
1 parent 9c3068b commit 1059ac0
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/evict.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,14 @@ int performEvictions(void) {
if (!isSafeToPerformEvictions()) return EVICT_OK;

int keys_freed = 0;
size_t mem_reported, mem_tofree;
size_t mem_reported, mem_tofree, mem_used;
long long mem_freed = 0; /* Maybe become negative */
mstime_t latency, eviction_latency;
long long delta;
int replicas = listLength(server.replicas);
int result = EVICT_FAIL;

if (getMaxmemoryState(&mem_reported, NULL, &mem_tofree, NULL, server.maxmemory_soft) == C_OK) {
if (getMaxmemoryState(&mem_reported, &mem_used, &mem_tofree, NULL, server.maxmemory_soft) == C_OK) {
result = EVICT_OK;
goto update_metrics;
}
Expand Down Expand Up @@ -727,24 +727,16 @@ int performEvictions(void) {
}
}
} else {
if (server.maxmemory_soft_scale) {
break;
} else {
goto cant_free; /* nothing to free... */
}
break;
}
}
if (server.maxmemory_soft_scale) {
size_t mem_used = zmalloc_used_memory();
size_t overhead = freeMemoryGetNotCountedMemory();
mem_used = (mem_used > overhead) ? mem_used - overhead : 0;
if (mem_used < server.maxmemory_soft) {
result = EVICT_OK;
goto update_metrics;
}

if (mem_freed >= (long long)(mem_used - server.maxmemory_soft)) {
/* at this point, the memory is OK, or we have reached the time limit */
result = (isEvictionProcRunning) ? EVICT_RUNNING : EVICT_OK;
} else {
goto cant_free;
}
/* at this point, the memory is OK, or we have reached the time limit */
result = (isEvictionProcRunning) ? EVICT_RUNNING : EVICT_OK;

cant_free:
if (result == EVICT_FAIL) {
Expand Down

0 comments on commit 1059ac0

Please sign in to comment.