From 4e22068f2f58e27d137bc081537149d7ece957d9 Mon Sep 17 00:00:00 2001 From: Alex Cope Date: Wed, 28 Jun 2023 17:31:40 -0700 Subject: [PATCH] with config --- src/config.cpp | 1 + src/evict.cpp | 7 ++++--- src/server.h | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 78cdb3877..129a23428 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -2953,6 +2953,7 @@ standardConfig configs[] = { createBoolConfig("soft-shutdown", NULL, MODIFIABLE_CONFIG, g_pserver->config_soft_shutdown, 0, NULL, NULL), createBoolConfig("flash-disable-key-cache", NULL, MODIFIABLE_CONFIG, g_pserver->flash_disable_key_cache, 0, NULL, NULL), createSizeTConfig("semi-ordered-set-bucket-size", NULL, MODIFIABLE_CONFIG, 0, 1024, g_semiOrderedSetTargetBucketSize, 0, INTEGER_CONFIG, NULL, NULL), + createIntConfig("force-eviction-percent", NULL, MODIFIABLE_CONFIG, 0, 100, g_pserver->force_eviction_percent, 0, INTEGER_CONFIG, NULL, NULL), #ifdef USE_OPENSSL createIntConfig("tls-port", NULL, MODIFIABLE_CONFIG, 0, 65535, g_pserver->tls_port, 0, INTEGER_CONFIG, NULL, updateTLSPort), /* TCP port. */ diff --git a/src/evict.cpp b/src/evict.cpp index aa6932e8b..2aa9337a2 100644 --- a/src/evict.cpp +++ b/src/evict.cpp @@ -425,10 +425,11 @@ int getMaxmemoryState(size_t *total, size_t *logical, size_t *tofree, float *lev if (g_pserver->FRdbSaveInProgress()) maxmemory = static_cast(maxmemory*1.2); - /* If there is less than 10% free system memory, force eviction */ + /* If there is less than a configurable percent of 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(g_pserver->cron_malloc_stats.sys_total * 0.9); + if (g_pserver->force_eviction_percent && g_pserver->cron_malloc_stats.sys_total) { + float sys_total_ratio = (float)(100 - g_pserver->force_eviction_percent)/100; + size_t mem_rss_max = static_cast(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 */ diff --git a/src/server.h b/src/server.h index 5f8a2e9e0..6d3580339 100644 --- a/src/server.h +++ b/src/server.h @@ -2571,6 +2571,7 @@ struct redisServer { int maxmemory_policy; /* Policy for key eviction */ int maxmemory_samples; /* Precision of random sampling */ int maxmemory_eviction_tenacity;/* Aggressiveness of eviction processing */ + int force_eviction_percent; /* Force eviction when this percent of system memory is remaining */ int lfu_log_factor; /* LFU logarithmic counter factor. */ int lfu_decay_time; /* LFU counter decay factor. */ long long proto_max_bulk_len; /* Protocol bulk length maximum size. */