#endif
#include <libknot/error.h>
+#if ENABLE_JEMALLOC
+/* Make the jemalloc library needed.
+ *
+ * The problem is with --as-needed for linker which is added by default by meson.
+ * If we don't use any jemalloc-specific calls, linker will decide that
+ * it is not needed and won't link it. Making it needed seems better than
+ * trying to override the flag which might be useful in some other cases, etc.
+ *
+ * Exporting the function is a very easy way of ensuring that it's not optimized out.
+ */
+#include <jemalloc/jemalloc.h>
+KR_EXPORT void kr_jemalloc_unused(void)
+{
+ malloc_stats_print(NULL, NULL, NULL);
+}
+/* We don't use threads (or rarely in some parts), so multiple arenas don't make sense.
+ https://jemalloc.net/jemalloc.3.html
+ */
+KR_EXPORT const char *malloc_conf = "narenas:1";
+#endif
struct args the_args_value; /** Static allocation for the_args singleton. */
### Systemd
systemd_files = get_option('systemd_files')
libsystemd = dependency('libsystemd', required: systemd_files == 'enabled')
+
+### Allocator
+# use empty name to disable the dependency, but still compile the dependent kresd
+malloc_name = get_option('malloc') == 'disabled' ? '' : 'jemalloc'
+malloc = meson.get_compiler('c').find_library(
+ malloc_name,
+ required: get_option('malloc') == 'jemalloc',
+ #static: false, #TODO: add when bumping meson to >= 0.51;
+ # static linking would most likely cause issues.
+ # Fortunately it seems unlikely that dynamic wouldn't be found and static would be.
+)
+
message('---------------------------')
## Compiler args
conf_data.set('ENABLE_SENDMMSG', sendmmsg.to_int())
conf_data.set('ENABLE_XDP', xdp.to_int())
conf_data.set('ENABLE_CAP_NG', capng.found().to_int())
+conf_data.set('ENABLE_JEMALLOC', malloc.found().to_int())
conf_data.set('ENABLE_DOH2', nghttp2.found().to_int())
conf_data.set('DBG_ASSERTION_ABORT', get_option('debug').to_int())
if get_option('debug')
s_xdp = xdp ? 'enabled': 'disabled'
s_openssl = openssl.found() ? 'present': 'missing'
s_capng = capng.found() ? 'enabled': 'disabled'
+s_malloc = malloc.found() ? 'jemalloc' : 'libc default'
s_doh2 = nghttp2.found() ? 'enabled': 'disabled'
message('''
XDP (in libknot): @0@'''.format(s_xdp) + '''
openssl debug: @0@'''.format(s_openssl) + '''
capng: @0@'''.format(s_capng) + '''
+ malloc: @0@'''.format(s_malloc) + '''
doh2: @0@'''.format(s_doh2) + '''
=======================================================
description: 'build dnstap module',
)
+option(
+ 'malloc',
+ type: 'combo',
+ choices: [
+ 'auto', # 'jemalloc' if available
+ 'disabled', # default provided by libc
+ 'jemalloc',
+ ],
+ value: 'auto',
+ description: 'memory allocator to use in kresd',
+)
+
option(
'doc',
type: 'combo',