Add jemalloc compat functions. (#456)

This adds the full set of jemalloc functions that FreeBSD's libc
exposes, including some (the `*allocm` family) that are gone from newer
versions of jemalloc and the `*allocx` family that replaced them.  These
are not necessarily efficient implementations but they should allow
snmalloc to replace jemalloc without any ABI breakage (in the loosest
possible sense).

Jemalloc provides a very generic sysctl-like mechanism for setting and
getting some values.  These are all implemented to return the
not-supported error code.  This may break code that expects that they
will succeed.

In particular, these APIs are used to register custom backing-store
allocators and to manage caches and arenas.  These concepts don't map
directly onto snmalloc and attempting to do so would almost certainly
not provide the same performance characteristics and so it's better to
`LD_PRELOAD` jemalloc (or explicitly link to it) for programs that gain
a significant speedup from this.
This commit is contained in:
David Chisnall
2022-02-09 10:49:02 +00:00
committed by GitHub
parent 20ddf8a150
commit 79ea08779b
4 changed files with 794 additions and 53 deletions

View File

@@ -348,14 +348,6 @@ int main(int argc, char** argv)
abort();
}
#ifndef __PIC__
snmalloc::debug_check_empty<snmalloc::Globals>();
void* bootstrap = __je_bootstrap_malloc(42);
if (bootstrap == nullptr)
{
printf("Failed to allocate from bootstrap malloc\n");
}
__je_bootstrap_free(bootstrap);
#endif
return 0;
}