diff options
author | zhaozhao.zz <zhaozhao.zz@alibaba-inc.com> | 2022-09-18 22:46:24 +0800 |
---|---|---|
committer | Oran Agra <oran@redislabs.com> | 2022-12-12 17:02:54 +0200 |
commit | 65ad4ff87e891767c4aa44f908d39286a075f4f5 (patch) | |
tree | d599c3162c659e9bde5dcabe99b855d0db75b80b | |
parent | ec5564a4cf0e6037f9db5f28cc10377b4370ba07 (diff) | |
download | redis-65ad4ff87e891767c4aa44f908d39286a075f4f5.tar.gz |
fix infinite sleep in performEvictions when have lazyfree jobs (#11237)
This bug is introduced in #7653. (Redis 6.2.0)
When `server.maxmemory_eviction_tenacity` is 100, `eviction_time_limit_us` is
`ULONG_MAX`, and if we cannot find the best key to delete (e.g. maxmemory-policy
is `volatile-lru` and all keys with ttl have been evicted), in `cant_free` redis will sleep
forever if some items are being freed in the lazyfree thread.
(cherry picked from commit 464aa04188c42c82f411ac7d43fabf0f6038c98e)
-rw-r--r-- | src/evict.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/evict.c b/src/evict.c index d3cdaaa80..ab46d1af6 100644 --- a/src/evict.c +++ b/src/evict.c @@ -549,7 +549,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, @@ -695,12 +695,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); } latencyEndMonitor(latency); |