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

@ -421,10 +421,22 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev
if (total) *total = mem_reported; if (total) *total = mem_reported;
size_t maxmemory = g_pserver->maxmemory; size_t maxmemory = g_pserver->maxmemory;
if (fPreSnapshot) if (fPreSnapshot)
maxmemory = static_cast<size_t>(maxmemory * 0.9); // derate memory by 10% since we won't be able to free during snapshot maxmemory = static_cast<size_t>(maxmemory*0.9); // derate memory by 10% since we won't be able to free during snapshot
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 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. */ /* We may return ASAP if there is no need to compute the level. */
int return_ok_asap = !maxmemory || mem_reported <= maxmemory; int return_ok_asap = !maxmemory || mem_reported <= maxmemory;
if (return_ok_asap && !level) return C_OK; 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(); size_t overhead = freeMemoryGetNotCountedMemory();
mem_used = (mem_used > overhead) ? mem_used-overhead : 0; 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. */ /* Compute the ratio of memory usage. */
if (level) { if (level) {
if (!maxmemory) { if (!maxmemory) {

View File

@ -70,6 +70,7 @@
#ifdef __linux__ #ifdef __linux__
#include <sys/prctl.h> #include <sys/prctl.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/sysinfo.h>
#endif #endif
int g_fTestMode = false; int g_fTestMode = false;
@ -2312,6 +2313,15 @@ void cronUpdateMemoryStats() {
g_pserver->cron_malloc_stats.allocator_active = g_pserver->cron_malloc_stats.allocator_resident; g_pserver->cron_malloc_stats.allocator_active = g_pserver->cron_malloc_stats.allocator_resident;
if (!g_pserver->cron_malloc_stats.allocator_allocated) if (!g_pserver->cron_malloc_stats.allocator_allocated)
g_pserver->cron_malloc_stats.allocator_allocated = g_pserver->cron_malloc_stats.zmalloc_used; 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_allocated;
size_t allocator_active; size_t allocator_active;
size_t allocator_resident; size_t allocator_resident;
size_t sys_total;
}; };
typedef struct socketFds { typedef struct socketFds {