diff --git a/src/evict.c b/src/evict.c index 3c767a557..45ec95f1f 100644 --- a/src/evict.c +++ b/src/evict.c @@ -595,7 +595,7 @@ int performEvictions(void) { { struct evictionPoolEntry *pool = EvictionPoolLRU; - while(bestkey == NULL) { + while (bestkey == NULL) { unsigned long total_keys = 0, keys; /* We don't want to make local-db choices when expiring keys, @@ -738,12 +738,18 @@ cant_free: /* At this point, we have run out of evictable items. It's possible * that some items are being freed in the lazyfree thread. Perform a * short wait here if such jobs exist, but don't wait long. */ - if (bioPendingJobsOfType(BIO_LAZY_FREE)) { - usleep(eviction_time_limit_us); + mstime_t lazyfree_latency; + latencyStartMonitor(lazyfree_latency); + while (bioPendingJobsOfType(BIO_LAZY_FREE) && + elapsedUs(evictionTimer) < eviction_time_limit_us) { if (getMaxmemoryState(NULL,NULL,NULL,NULL) == C_OK) { result = EVICT_OK; + break; } + usleep(eviction_time_limit_us < 1000 ? eviction_time_limit_us : 1000); } + latencyEndMonitor(lazyfree_latency); + latencyAddSampleIfNeeded("eviction-lazyfree",lazyfree_latency); } serverAssert(server.core_propagates); /* This function should not be re-entrant */