Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
msotheeswaran-sc committed Jul 26, 2023
2 parents ce70e8c + aef0187 commit 441b74a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
5 changes: 2 additions & 3 deletions keydb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1145,9 +1145,8 @@ acllog-max-len 128
#
# active-expire-effort 1

# Force evictions when RSS memory reaches this percent of total system memory.
# This is useful as a safeguard to prevent OOM kills when RSS overhead is
# significant (0 to disable).
# Force evictions when used system memory reaches X% of total system memory.
# This is useful as a safeguard to prevent OOM kills (0 to disable).
#
# force-eviction-percent 0

Expand Down
17 changes: 8 additions & 9 deletions src/evict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,15 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
if (g_pserver->FRdbSaveInProgress() && !cserver.fForkBgSave)
maxmemory = static_cast<size_t>(maxmemory*1.2);

/* If rss memory exceeds configurable percent of system memory, force eviction */
bool mem_rss_max_exceeded;
/* If available system memory is below a certain threshold, force eviction */
long long sys_available_mem_buffer = 0;
if (g_pserver->force_eviction_percent && g_pserver->cron_malloc_stats.sys_total) {
float sys_total_ratio = (float)(g_pserver->force_eviction_percent)/100;
size_t mem_rss_max = static_cast<size_t>(g_pserver->cron_malloc_stats.sys_total * sys_total_ratio);
mem_rss_max_exceeded = g_pserver->cron_malloc_stats.process_rss > mem_rss_max;
if (mem_rss_max_exceeded) {
/* This will always set maxmemory < mem_reported */
float frag_ratio = (float)g_pserver->cron_malloc_stats.process_rss / (float)mem_reported;
maxmemory = static_cast<size_t>((float)mem_rss_max / frag_ratio);
float available_mem_ratio = (float)(100 - g_pserver->force_eviction_percent)/100;
size_t min_available_mem = static_cast<size_t>(g_pserver->cron_malloc_stats.sys_total * available_mem_ratio);
sys_available_mem_buffer = static_cast<long>(g_pserver->cron_malloc_stats.sys_available - min_available_mem);
if (sys_available_mem_buffer < 0) {
long long mem_threshold = mem_reported + sys_available_mem_buffer;
maxmemory = ((long long)maxmemory < mem_threshold) ? maxmemory : static_cast<size_t>(mem_threshold);
}
}

Expand Down

0 comments on commit 441b74a

Please sign in to comment.