Skip to content

Commit

Permalink
update variable name to key_eviction_memory
Browse files Browse the repository at this point in the history
  • Loading branch information
hwware committed Dec 3, 2024
1 parent 1059ac0 commit 24324ab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions src/evict.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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. */
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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 {
Expand All @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 24324ab

Please sign in to comment.