]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add ability to set per jemalloc arena dirty and muzzy decay values
authorArtem Boldariev <artem@boldariev.com>
Fri, 11 Aug 2023 11:25:40 +0000 (14:25 +0300)
committerOndřej Surý <ondrej@isc.org>
Tue, 5 Sep 2023 13:02:30 +0000 (15:02 +0200)
This commit adds couple of functions to change "dirty_decay_ms" and
"muzzy_decay_ms" settings on arenas associated with memory contexts.

(cherry picked from commit 6e98b58d1554dff27cf5889ae757e79562d25786)

lib/isc/include/isc/mem.h
lib/isc/mem.c

index 72b965148f13ad1d0d8155904e80f78f9ed3a8c9..bd59f735b898798369c40ea664d4c8c54e5fcfa0 100644 (file)
@@ -198,13 +198,38 @@ void ISCMEMFUNC(create)(isc_mem_t **_ISC_MEM_FLARG);
 void
 isc__mem_create_arena(isc_mem_t **_ISC_MEM_FLARG);
 /*!<
- * \brief Create a memory context that routs all its operations to a dedicated
- * jemalloc arena (when available).
+ * \brief Create a memory context that routs all its operations to a
+ * dedicated jemalloc arena (when available). When jemalloc is not
+ * available, the function is, effectively, an alias to
+ * isc_mem_create().
  *
  * Requires:
  * mctxp != NULL && *mctxp == NULL */
 /*@}*/
 
+isc_result_t
+isc_mem_arena_set_muzzy_decay_ms(isc_mem_t *mctx, const ssize_t decay_ms);
+
+isc_result_t
+isc_mem_arena_set_dirty_decay_ms(isc_mem_t *mctx, const ssize_t decay_ms);
+/*!<
+ * \brief These two functions set the given parameters on the
+ * jemalloc arena associated with the memory context (if there is
+ * one). When jemalloc is not available, these are no-op.
+ *
+ * NOTE: The "muzzy_decay_ms" and "dirty_decay_ms" are the most common
+ * parameters to adjust when the defaults do not work well (per the
+ * official jemalloc tuning guide:
+ * https://github.com/jemalloc/jemalloc/blob/dev/TUNING.md).
+ *
+ * Requires:
+ * mctx - a valid memory context.
+ */
+/*@}*/
+
+void
+isc_mem_attach(isc_mem_t *, isc_mem_t **);
+
 /*@{*/
 void
 isc_mem_attach(isc_mem_t *, isc_mem_t **);
index c2bd21247458c7f2d7a5c262d0f43f8e84685e79..61a66f608723d4ce7fc8e8faeb2354aa38fab3d9 100644 (file)
@@ -1845,6 +1845,55 @@ isc__mem_create_arena(isc_mem_t **mctxp FLARG) {
 #endif /* ISC_MEM_TRACKLINES */
 }
 
+#if defined(JEMALLOC_API_SUPPORTED) && JEMALLOC_VERSION_MAJOR >= 4
+static bool
+jemalloc_set_ssize_value(const char *valname, ssize_t newval) {
+       int ret;
+
+       ret = mallctl(valname, NULL, NULL, &newval, sizeof(newval));
+       return (ret == 0);
+}
+#endif /* defined(JEMALLOC_API_SUPPORTED) && JEMALLOC_VERSION_MAJOR >= 4 */
+
+static isc_result_t
+mem_set_arena_ssize_value(isc_mem_t *mctx, const char *arena_valname,
+                         const ssize_t newval) {
+       REQUIRE(VALID_CONTEXT(mctx));
+#if defined(JEMALLOC_API_SUPPORTED) && JEMALLOC_VERSION_MAJOR >= 4
+       bool ret;
+       char buf[256] = { 0 };
+
+       if (mctx->jemalloc_arena == ISC_MEM_ILLEGAL_ARENA) {
+               return (ISC_R_UNEXPECTED);
+       }
+
+       (void)snprintf(buf, sizeof(buf), "arena.%u.%s", mctx->jemalloc_arena,
+                      arena_valname);
+
+       ret = jemalloc_set_ssize_value(buf, newval);
+
+       if (!ret) {
+               return (ISC_R_FAILURE);
+       }
+
+       return (ISC_R_SUCCESS);
+#else
+       UNUSED(arena_valname);
+       UNUSED(newval);
+       return (ISC_R_NOTIMPLEMENTED);
+#endif /* defined(JEMALLOC_API_SUPPORTED) && JEMALLOC_VERSION_MAJOR >= 4 */
+}
+
+isc_result_t
+isc_mem_arena_set_muzzy_decay_ms(isc_mem_t *mctx, const ssize_t decay_ms) {
+       return (mem_set_arena_ssize_value(mctx, "muzzy_decay_ms", decay_ms));
+}
+
+isc_result_t
+isc_mem_arena_set_dirty_decay_ms(isc_mem_t *mctx, const ssize_t decay_ms) {
+       return (mem_set_arena_ssize_value(mctx, "dirty_decay_ms", decay_ms));
+}
+
 void
 isc__mem_printactive(isc_mem_t *ctx, FILE *file) {
 #if ISC_MEM_TRACKLINES