2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 06:25:31 +00:00

Use system allocator when jemalloc is unavailable

This commit adds support for systems where the jemalloc library is not
available as a package, here's the quick summary:

  * On Linux - the jemalloc is usually available as a package, if
    configured --without-jemalloc, the shim would be used around
    malloc(), free(), realloc() and malloc_usable_size()

  * On macOS - the jemalloc is available from homebrew or macports, if
    configured --without-jemalloc, the shim would be used around
    malloc(), free(), realloc() and malloc_size()

  * On FreeBSD - the jemalloc is *the* system allocator, we just need
    to check for <malloc_np.h> header to get access to non-standard API

  * On NetBSD - the jemalloc is *the* system allocator, we just need to
    check for <jemalloc/jemalloc.h> header to get access to non-standard
    API

  * On a system hostile to users and developers (read OpenBSD) - the
    jemalloc API is emulated by using ((size_t *)ptr)[-1] field to hold
    the size information.  The OpenBSD developers care only for
    themselves, so why should we care about speed on OpenBSD?
This commit is contained in:
Ondřej Surý
2021-05-25 12:46:00 +02:00
parent 68a28cbc0a
commit e20cc41e56
6 changed files with 214 additions and 8 deletions

View File

@@ -42,8 +42,19 @@
#include <json_object.h>
#endif /* HAVE_JSON_C */
#if defined(HAVE_MALLOC_NP_H)
#include <malloc_np.h>
#elif defined(HAVE_JEMALLOC)
#include <jemalloc/jemalloc.h>
#if JEMALLOC_VERSION_MAJOR < 4
#define sdallocx(ptr, size, flags) dallocx(ptr, flags)
#endif /* JEMALLOC_VERSION_MAJOR < 4 */
#else
#include "jemalloc_shim.h"
#endif
#include "mem_p.h"
#define MCTXLOCK(m) LOCK(&m->lock)