port changes to 6.3

This commit is contained in:
Alex Cope 2023-06-27 14:18:14 -07:00 committed by Malavan Sotheeswaran
parent 821b39acac
commit 4c3d9341fd
3 changed files with 30 additions and 1 deletions

View File

@ -425,6 +425,18 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
if (g_pserver->FRdbSaveInProgress())
maxmemory = static_cast<size_t>(maxmemory*1.2);
/* If there is less than 10% free system memory, force eviction */
bool mem_rss_max_exceeded;
if (g_pserver->cron_malloc_stats.sys_total) {
size_t mem_rss_max = static_cast<size_t>(g_pserver->cron_malloc_stats.sys_total * 0.9);
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);
}
}
/* We may return ASAP if there is no need to compute the level. */
int return_ok_asap = !maxmemory || mem_reported <= maxmemory;
if (return_ok_asap && !level) return C_OK;
@ -435,6 +447,12 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
size_t overhead = freeMemoryGetNotCountedMemory();
mem_used = (mem_used > overhead) ? mem_used-overhead : 0;
/* If we've exceeded max RSS memory, we want to force evictions no matter
* what so we also offset the overhead from maxmemory. */
if (mem_rss_max_exceeded) {
maxmemory = (maxmemory > overhead) ? maxmemory-overhead : 0;
}
/* Compute the ratio of memory usage. */
if (level) {
if (!maxmemory) {

View File

@ -70,6 +70,7 @@
#ifdef __linux__
#include <sys/prctl.h>
#include <sys/mman.h>
#include <sys/sysinfo.h>
#endif
int g_fTestMode = false;
@ -2312,6 +2313,15 @@ void cronUpdateMemoryStats() {
g_pserver->cron_malloc_stats.allocator_active = g_pserver->cron_malloc_stats.allocator_resident;
if (!g_pserver->cron_malloc_stats.allocator_allocated)
g_pserver->cron_malloc_stats.allocator_allocated = g_pserver->cron_malloc_stats.zmalloc_used;
#ifdef __linux__
struct sysinfo sysinf;
memset(&sysinf, 0, sizeof sysinf);
if (!sysinfo(&sysinf)) {
g_pserver->cron_malloc_stats.sys_total = static_cast<size_t>(sysinf.totalram);
}
#endif
}
}

View File

@ -2014,6 +2014,7 @@ struct malloc_stats {
size_t allocator_allocated;
size_t allocator_active;
size_t allocator_resident;
size_t sys_total;
};
typedef struct socketFds {