mirror of
https://codeberg.org/redict/redict.git
synced 2025-01-23 08:38:27 -05:00
performEvictions: mem_freed may be negative (#7908)
If 'delta' is negative 'mem_freed' may underflow and cause the while loop to exit prematurely (And not evicting enough memory) mem_freed can be negative when: 1. We use lazy free (consuming memory by appending to a list) 2. Thread doing an allocation between the two calls to zmalloc_used_memory.
This commit is contained in:
parent
f559a57206
commit
37fd3d40ae
@ -499,7 +499,8 @@ int performEvictions(void) {
|
|||||||
if (!isSafeToPerformEvictions()) return EVICT_OK;
|
if (!isSafeToPerformEvictions()) return EVICT_OK;
|
||||||
|
|
||||||
int keys_freed = 0;
|
int keys_freed = 0;
|
||||||
size_t mem_reported, mem_tofree, mem_freed;
|
size_t mem_reported, mem_tofree;
|
||||||
|
long long mem_freed; /* May be negative */
|
||||||
mstime_t latency, eviction_latency;
|
mstime_t latency, eviction_latency;
|
||||||
long long delta;
|
long long delta;
|
||||||
int slaves = listLength(server.slaves);
|
int slaves = listLength(server.slaves);
|
||||||
@ -520,7 +521,7 @@ int performEvictions(void) {
|
|||||||
monotime evictionTimer;
|
monotime evictionTimer;
|
||||||
elapsedStart(&evictionTimer);
|
elapsedStart(&evictionTimer);
|
||||||
|
|
||||||
while (mem_freed < mem_tofree) {
|
while (mem_freed < (long long)mem_tofree) {
|
||||||
int j, k, i;
|
int j, k, i;
|
||||||
static unsigned int next_db = 0;
|
static unsigned int next_db = 0;
|
||||||
sds bestkey = NULL;
|
sds bestkey = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user