summaryrefslogtreecommitdiff
path: root/src/zmalloc.c
diff options
context:
space:
mode:
authorOran Agra <oran@redislabs.com>2019-05-30 12:51:32 +0300
committerOran Agra <oran@redislabs.com>2019-06-02 15:33:14 +0300
commit09f99c2a925a0351985e799c106614082d6053cf (patch)
tree7fe3fe8c7fa499a70111fb6ce18dae37a95e3977 /src/zmalloc.c
parent2fec7d9c6c630db3bcb13a07a08c39404abad447 (diff)
downloadredis-09f99c2a925a0351985e799c106614082d6053cf.tar.gz
make redis purge jemalloc after flush, and enable background purging thread
jemalloc 5 doesn't immediately release memory back to the OS, instead there's a decaying mechanism, which doesn't work when there's no traffic (no allocations). this is most evident if there's no traffic after flushdb, the RSS will remain high. 1) enable jemalloc background purging 2) explicitly purge in flushdb
Diffstat (limited to 'src/zmalloc.c')
-rw-r--r--src/zmalloc.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/zmalloc.c b/src/zmalloc.c
index 5e6010278..58896a727 100644
--- a/src/zmalloc.c
+++ b/src/zmalloc.c
@@ -306,6 +306,7 @@ size_t zmalloc_get_rss(void) {
#endif
#if defined(USE_JEMALLOC)
+
int zmalloc_get_allocator_info(size_t *allocated,
size_t *active,
size_t *resident) {
@@ -327,13 +328,46 @@ int zmalloc_get_allocator_info(size_t *allocated,
je_mallctl("stats.allocated", allocated, &sz, NULL, 0);
return 1;
}
+
+void set_jemalloc_bg_thread(int enable) {
+ /* let jemalloc do purging asynchronously, required when there's no traffic
+ * after flushdb */
+ if (enable) {
+ char val = 1;
+ je_mallctl("background_thread", NULL, 0, &val, 1);
+ }
+}
+
+int jemalloc_purge() {
+ /* return all unused (reserved) pages to the OS */
+ char tmp[32];
+ unsigned narenas = 0;
+ size_t sz = sizeof(unsigned);
+ if (!je_mallctl("arenas.narenas", &narenas, &sz, NULL, 0)) {
+ sprintf(tmp, "arena.%d.purge", narenas);
+ if (!je_mallctl(tmp, NULL, 0, NULL, 0))
+ return 0;
+ }
+ return -1;
+}
+
#else
+
int zmalloc_get_allocator_info(size_t *allocated,
size_t *active,
size_t *resident) {
*allocated = *resident = *active = 0;
return 1;
}
+
+void set_jemalloc_bg_thread(int enable) {
+ ((void)(enable));
+}
+
+int jemalloc_purge() {
+ return 0;
+}
+
#endif
/* Get the sum of the specified field (converted form kb to bytes) in