This commit is contained in:
Alex Cope 2023-06-30 09:49:59 -07:00 committed by Malavan Sotheeswaran
parent 65b7fafd29
commit 60d74262dc
3 changed files with 14 additions and 14 deletions

View File

@ -428,14 +428,14 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
if (g_pserver->FRdbSaveInProgress()) if (g_pserver->FRdbSaveInProgress())
maxmemory = static_cast<size_t>(maxmemory*1.2); maxmemory = static_cast<size_t>(maxmemory*1.2);
/* If free system memory is below a certain threshold, force eviction */ /* If available system memory is below a certain threshold, force eviction */
long sys_free_mem_buffer = 0; long sys_available_mem_buffer = 0;
if (g_pserver->force_eviction_percent && g_pserver->cron_malloc_stats.sys_total) { if (g_pserver->force_eviction_percent && g_pserver->cron_malloc_stats.sys_total) {
float free_mem_ratio = (float)(100 - g_pserver->force_eviction_percent)/100; float available_mem_ratio = (float)(100 - g_pserver->force_eviction_percent)/100;
size_t min_free_mem = static_cast<size_t>(g_pserver->cron_malloc_stats.sys_total * free_mem_ratio); size_t min_available_mem = static_cast<size_t>(g_pserver->cron_malloc_stats.sys_total * available_mem_ratio);
sys_free_mem_buffer = static_cast<long>(g_pserver->cron_malloc_stats.sys_free - min_free_mem); sys_available_mem_buffer = static_cast<long>(g_pserver->cron_malloc_stats.sys_available - min_available_mem);
if (sys_free_mem_buffer < 0) { if (sys_available_mem_buffer < 0) {
long mem_threshold = mem_reported + sys_free_mem_buffer; long mem_threshold = mem_reported + sys_available_mem_buffer;
maxmemory = ((long)maxmemory < mem_threshold) ? maxmemory : static_cast<size_t>(mem_threshold); maxmemory = ((long)maxmemory < mem_threshold) ? maxmemory : static_cast<size_t>(mem_threshold);
} }
} }
@ -450,9 +450,9 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
size_t overhead = freeMemoryGetNotCountedMemory(); size_t overhead = freeMemoryGetNotCountedMemory();
mem_used = (mem_used > overhead) ? mem_used-overhead : 0; mem_used = (mem_used > overhead) ? mem_used-overhead : 0;
/* If system free memory is too low, we want to force evictions no matter /* If system available memory is too low, we want to force evictions no matter
* what so we also offset the overhead from maxmemory. */ * what so we also offset the overhead from maxmemory. */
if (sys_free_mem_buffer < 0) { if (sys_available_mem_buffer < 0) {
maxmemory = (maxmemory > overhead) ? maxmemory-overhead : 0; maxmemory = (maxmemory > overhead) ? maxmemory-overhead : 0;
} }

View File

@ -2,7 +2,7 @@
#include <fstream> #include <fstream>
static size_t getMemKey(std::string key) { static size_t getMemKey(std::string key) {
# ifdef __linux__ // # ifdef __linux__
std::string token; std::string token;
std::ifstream f("/proc/meminfo"); std::ifstream f("/proc/meminfo");
while (f >> token) { while (f >> token) {
@ -15,11 +15,11 @@ static size_t getMemKey(std::string key) {
} }
f.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); f.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
} }
return 0; // nothing found
} }
# else
return 0; return 0;
# endif // # else
// return 0;
// # endif
} }
size_t getMemAvailable() { size_t getMemAvailable() {

View File

@ -2316,7 +2316,7 @@ void cronUpdateMemoryStats() {
if (g_pserver->force_eviction_percent) { if (g_pserver->force_eviction_percent) {
g_pserver->cron_malloc_stats.sys_available = getMemAvailable(); g_pserver->cron_malloc_stats.sys_available = getMemAvailable();
serverLog(LL_WARNING, "Setting sys_available:%llu", g_pserver->cron_malloc_stats.sys_available); serverLog(LL_WARNING, "Setting sys_available:%lu", g_pserver->cron_malloc_stats.sys_available);
} }
} }
} }