diff --git a/src/evict.c b/src/evict.c index d4ff192797..bdbc259572 100644 --- a/src/evict.c +++ b/src/evict.c @@ -389,7 +389,7 @@ size_t freeMemoryGetNotCountedMemory(void) { * limit. * (Populated both for C_ERR and C_OK) */ -int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *level, unsigned long long checked_maxmemory) { +int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *level, unsigned long long maxmemory) { size_t mem_reported, mem_used, mem_tofree; /* Check if we are over the memory usage limit. If we are not, no need @@ -398,12 +398,12 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev if (total) *total = mem_reported; /* We may return ASAP if there is no need to compute the level. */ - if (!checked_maxmemory) { + if (!maxmemory) { if (level) *level = 0; return C_OK; } - if (mem_reported <= checked_maxmemory && !level) return C_OK; + if (mem_reported <= maxmemory && !level) return C_OK; /* Remove the size of replicas output buffers and AOF buffer from the * count of used memory. */ @@ -416,15 +416,15 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev *level = (float)mem_used / (float)server.maxmemory; } - if (mem_reported <= checked_maxmemory) return C_OK; + if (mem_reported <= maxmemory) return C_OK; /* Check if we are still over the memory limit. */ /* if checked_maxmemory is equal to maxmemory and mem_used > checked_maxmemory then OOM */ /* if checked_maxmemory is equal to maxmemory_soft and mem_used > checked_maxmemory then there is no OOM but eviction happens */ - if (mem_used <= checked_maxmemory) return C_OK; + if (mem_used <= maxmemory) return C_OK; /* Compute how much memory we need to free. */ - mem_tofree = mem_used - server.maxmemory_soft; + mem_tofree = mem_used - server.key_eviction_memory; if (logical) *logical = mem_used; if (tofree) *tofree = mem_tofree; @@ -546,7 +546,7 @@ int performEvictions(void) { int replicas = listLength(server.replicas); int result = EVICT_FAIL; - if (getMaxmemoryState(&mem_reported, &mem_used, &mem_tofree, NULL, server.maxmemory_soft) == C_OK) { + if (getMaxmemoryState(&mem_reported, &mem_used, &mem_tofree, NULL, server.key_eviction_memory) == C_OK) { result = EVICT_OK; goto update_metrics; } @@ -712,7 +712,7 @@ int performEvictions(void) { * across the dbAsyncDelete() call, while the thread can * release the memory all the time. */ if (server.lazyfree_lazy_eviction) { - if (getMaxmemoryState(NULL, NULL, NULL, NULL, server.maxmemory_soft) == C_OK) { + if (getMaxmemoryState(NULL, NULL, NULL, NULL, server.key_eviction_memory) == C_OK) { break; } } @@ -731,7 +731,7 @@ int performEvictions(void) { } } - if (mem_freed >= (long long)(mem_used - server.maxmemory_soft)) { + if (mem_freed >= (long long)(mem_used - server.key_eviction_memory)) { /* at this point, the memory is OK, or we have reached the time limit */ result = (isEvictionProcRunning) ? EVICT_RUNNING : EVICT_OK; } else { @@ -746,7 +746,7 @@ int performEvictions(void) { mstime_t lazyfree_latency; latencyStartMonitor(lazyfree_latency); while (bioPendingJobsOfType(BIO_LAZY_FREE) && elapsedUs(evictionTimer) < eviction_time_limit_us) { - if (getMaxmemoryState(NULL, NULL, NULL, NULL, server.maxmemory_soft) == C_OK) { + if (getMaxmemoryState(NULL, NULL, NULL, NULL, server.key_eviction_memory) == C_OK) { result = EVICT_OK; break; } diff --git a/src/server.c b/src/server.c index a664bc714b..c458984012 100644 --- a/src/server.c +++ b/src/server.c @@ -5627,7 +5627,7 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) { char used_memory_scripts_hmem[64]; char used_memory_rss_hmem[64]; char maxmemory_hmem[64]; - char maxmemory_soft_hmem[64]; + char key_eviction_memory_hmem[64]; size_t zmalloc_used = zmalloc_used_memory(); size_t total_system_mem = server.system_memory_size; const char *evict_policy = evictPolicyToString(); @@ -5649,7 +5649,7 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) { bytesToHuman(used_memory_scripts_hmem, sizeof(used_memory_scripts_hmem), mh->lua_caches + mh->functions_caches); bytesToHuman(used_memory_rss_hmem, sizeof(used_memory_rss_hmem), server.cron_malloc_stats.process_rss); bytesToHuman(maxmemory_hmem, sizeof(maxmemory_hmem), server.maxmemory); - bytesToHuman(maxmemory_soft_hmem, sizeof(maxmemory_soft_hmem), server.maxmemory_soft); + bytesToHuman(key_eviction_memory_hmem, sizeof(key_eviction_memory_hmem), server.key_eviction_memory); if (sections++) info = sdscat(info, "\r\n"); info = sdscatprintf( @@ -5689,8 +5689,8 @@ sds genValkeyInfoString(dict *section_dict, int all_sections, int everything) { "maxmemory_human:%s\r\n", maxmemory_hmem, "maxmemory_policy:%s\r\n", evict_policy, "maxmemory_soft_scale:%d\r\n", server.maxmemory_soft_scale, - "maxmemory_soft:%lld\r\n", server.maxmemory_soft, - "maxmemory_soft_human:%s\r\n", maxmemory_soft_hmem, + "key_eviction_memory:%lld\r\n", server.key_eviction_memory, + "key_eviction_memory_human:%s\r\n", key_eviction_memory_hmem, "allocator_frag_ratio:%.2f\r\n", mh->allocator_frag, "allocator_frag_bytes:%zu\r\n", mh->allocator_frag_bytes, "allocator_rss_ratio:%.2f\r\n", mh->allocator_rss, diff --git a/src/server.h b/src/server.h index d42206dd9c..57d748accf 100644 --- a/src/server.h +++ b/src/server.h @@ -2102,7 +2102,7 @@ struct valkeyServer { int maxmemory_policy; /* Policy for key eviction */ int maxmemory_samples; /* Precision of random sampling */ int maxmemory_soft_scale; /* Percent of the soft maxmemory value */ - unsigned long long maxmemory_soft; /* Soft maxmemory value to store data */ + unsigned long long key_eviction_memory; /* Memory bytes to begin the key eviction process */ int maxmemory_eviction_tenacity; /* Aggressiveness of eviction processing */ int lfu_log_factor; /* LFU logarithmic counter factor. */ int lfu_decay_time; /* LFU counter decay factor. */ @@ -3038,7 +3038,7 @@ static inline int canUseSharedObject(void) { return server.maxmemory == 0 || !(server.maxmemory_policy & MAXMEMORY_FLAG_NO_SHARED_INTEGERS); } static inline void updateSoftMaxmemoryValue(void) { - server.maxmemory_soft = (unsigned long long)server.maxmemory / 100.0 * (100 - server.maxmemory_soft_scale); + server.key_eviction_memory = (unsigned long long)server.maxmemory / 100.0 * (100 - server.maxmemory_soft_scale); } #define sdsEncodedObject(objptr) (objptr->encoding == OBJ_ENCODING_RAW || objptr->encoding == OBJ_ENCODING_EMBSTR)