Add --with-malloc-conf.
Add --with-malloc-conf, which makes it possible to embed a default options string during configuration.
This commit is contained in:
parent
ef349f3f94
commit
f829009929
8
INSTALL
8
INSTALL
@ -84,6 +84,14 @@ any of the following arguments (not a definitive list) to 'configure':
|
|||||||
versions of jemalloc can coexist in the same installation directory. For
|
versions of jemalloc can coexist in the same installation directory. For
|
||||||
example, libjemalloc.so.0 becomes libjemalloc<suffix>.so.0.
|
example, libjemalloc.so.0 becomes libjemalloc<suffix>.so.0.
|
||||||
|
|
||||||
|
--with-malloc-conf=<malloc_conf>
|
||||||
|
Embed <malloc_conf> as a run-time options string that is processed prior to
|
||||||
|
the malloc_conf global variable, the /etc/malloc.conf symlink, and the
|
||||||
|
MALLOC_CONF environment variable. For example, to change the default chunk
|
||||||
|
size to 256 KiB:
|
||||||
|
|
||||||
|
--with-malloc-conf=lg_chunk:18
|
||||||
|
|
||||||
--disable-cc-silence
|
--disable-cc-silence
|
||||||
Disable code that silences non-useful compiler warnings. This is mainly
|
Disable code that silences non-useful compiler warnings. This is mainly
|
||||||
useful during development when auditing the set of warnings that are being
|
useful during development when auditing the set of warnings that are being
|
||||||
|
10
configure.ac
10
configure.ac
@ -577,6 +577,15 @@ AC_ARG_WITH([install_suffix],
|
|||||||
install_suffix="$INSTALL_SUFFIX"
|
install_suffix="$INSTALL_SUFFIX"
|
||||||
AC_SUBST([install_suffix])
|
AC_SUBST([install_suffix])
|
||||||
|
|
||||||
|
dnl Specify default malloc_conf.
|
||||||
|
AC_ARG_WITH([malloc_conf],
|
||||||
|
[AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
|
||||||
|
[JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
|
||||||
|
[JEMALLOC_CONFIG_MALLOC_CONF=""]
|
||||||
|
)
|
||||||
|
config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
|
||||||
|
AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
|
||||||
|
|
||||||
dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
|
dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
|
||||||
dnl jemalloc_protos_jet.h easy.
|
dnl jemalloc_protos_jet.h easy.
|
||||||
je_="je_"
|
je_="je_"
|
||||||
@ -1726,6 +1735,7 @@ AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
|
|||||||
AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
|
AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
|
||||||
AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
|
AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
|
||||||
AC_MSG_RESULT([install_suffix : ${install_suffix}])
|
AC_MSG_RESULT([install_suffix : ${install_suffix}])
|
||||||
|
AC_MSG_RESULT([malloc_conf : ${config_malloc_conf}])
|
||||||
AC_MSG_RESULT([autogen : ${enable_autogen}])
|
AC_MSG_RESULT([autogen : ${enable_autogen}])
|
||||||
AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
|
AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
|
||||||
AC_MSG_RESULT([debug : ${enable_debug}])
|
AC_MSG_RESULT([debug : ${enable_debug}])
|
||||||
|
@ -455,19 +455,20 @@ for (i = 0; i < nbins; i++) {
|
|||||||
routines, the allocator initializes its internals based in part on various
|
routines, the allocator initializes its internals based in part on various
|
||||||
options that can be specified at compile- or run-time.</para>
|
options that can be specified at compile- or run-time.</para>
|
||||||
|
|
||||||
<para>The string pointed to by the global variable
|
<para>The string specified via <option>--with-malloc-conf</option>, the
|
||||||
<varname>malloc_conf</varname>, the “name” of the file
|
string pointed to by the global variable <varname>malloc_conf</varname>, the
|
||||||
referenced by the symbolic link named <filename
|
“name” of the file referenced by the symbolic link named
|
||||||
class="symlink">/etc/malloc.conf</filename>, and the value of the
|
<filename class="symlink">/etc/malloc.conf</filename>, and the value of the
|
||||||
environment variable <envar>MALLOC_CONF</envar>, will be interpreted, in
|
environment variable <envar>MALLOC_CONF</envar>, will be interpreted, in
|
||||||
that order, from left to right as options. Note that
|
that order, from left to right as options. Note that
|
||||||
<varname>malloc_conf</varname> may be read before
|
<varname>malloc_conf</varname> may be read before
|
||||||
<function>main<parameter/></function> is entered, so the declaration of
|
<function>main<parameter/></function> is entered, so the declaration of
|
||||||
<varname>malloc_conf</varname> should specify an initializer that contains
|
<varname>malloc_conf</varname> should specify an initializer that contains
|
||||||
the final value to be read by jemalloc. <varname>malloc_conf</varname> is
|
the final value to be read by jemalloc. <option>--with-malloc-conf</option>
|
||||||
a compile-time setting, whereas <filename
|
and <varname>malloc_conf</varname> are compile-time mechanisms, whereas
|
||||||
class="symlink">/etc/malloc.conf</filename> and <envar>MALLOC_CONF</envar>
|
<filename class="symlink">/etc/malloc.conf</filename> and
|
||||||
can be safely set any time prior to program invocation.</para>
|
<envar>MALLOC_CONF</envar> can be safely set any time prior to program
|
||||||
|
invocation.</para>
|
||||||
|
|
||||||
<para>An options string is a comma-separated list of option:value pairs.
|
<para>An options string is a comma-separated list of option:value pairs.
|
||||||
There is one key corresponding to each <link
|
There is one key corresponding to each <link
|
||||||
@ -776,6 +777,17 @@ for (i = 0; i < nbins; i++) {
|
|||||||
during build configuration.</para></listitem>
|
during build configuration.</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry id="config.malloc_conf">
|
||||||
|
<term>
|
||||||
|
<mallctl>config.malloc_conf</mallctl>
|
||||||
|
(<type>const char *</type>)
|
||||||
|
<literal>r-</literal>
|
||||||
|
</term>
|
||||||
|
<listitem><para>Embedded configure-time-specified run-time options
|
||||||
|
string, empty unless <option>--with-malloc-conf</option> was specified
|
||||||
|
during build configuration.</para></listitem>
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry id="config.munmap">
|
<varlistentry id="config.munmap">
|
||||||
<term>
|
<term>
|
||||||
<mallctl>config.munmap</mallctl>
|
<mallctl>config.munmap</mallctl>
|
||||||
|
@ -49,6 +49,7 @@ static const bool config_lazy_lock =
|
|||||||
false
|
false
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
static const char * const config_malloc_conf = JEMALLOC_CONFIG_MALLOC_CONF;
|
||||||
static const bool config_prof =
|
static const bool config_prof =
|
||||||
#ifdef JEMALLOC_PROF
|
#ifdef JEMALLOC_PROF
|
||||||
true
|
true
|
||||||
|
@ -259,4 +259,7 @@
|
|||||||
*/
|
*/
|
||||||
#undef JEMALLOC_EXPORT
|
#undef JEMALLOC_EXPORT
|
||||||
|
|
||||||
|
/* config.malloc_conf options string. */
|
||||||
|
#undef JEMALLOC_CONFIG_MALLOC_CONF
|
||||||
|
|
||||||
#endif /* JEMALLOC_INTERNAL_DEFS_H_ */
|
#endif /* JEMALLOC_INTERNAL_DEFS_H_ */
|
||||||
|
37
src/ctl.c
37
src/ctl.c
@ -77,6 +77,7 @@ CTL_PROTO(config_cache_oblivious)
|
|||||||
CTL_PROTO(config_debug)
|
CTL_PROTO(config_debug)
|
||||||
CTL_PROTO(config_fill)
|
CTL_PROTO(config_fill)
|
||||||
CTL_PROTO(config_lazy_lock)
|
CTL_PROTO(config_lazy_lock)
|
||||||
|
CTL_PROTO(config_malloc_conf)
|
||||||
CTL_PROTO(config_munmap)
|
CTL_PROTO(config_munmap)
|
||||||
CTL_PROTO(config_prof)
|
CTL_PROTO(config_prof)
|
||||||
CTL_PROTO(config_prof_libgcc)
|
CTL_PROTO(config_prof_libgcc)
|
||||||
@ -241,6 +242,7 @@ static const ctl_named_node_t config_node[] = {
|
|||||||
{NAME("debug"), CTL(config_debug)},
|
{NAME("debug"), CTL(config_debug)},
|
||||||
{NAME("fill"), CTL(config_fill)},
|
{NAME("fill"), CTL(config_fill)},
|
||||||
{NAME("lazy_lock"), CTL(config_lazy_lock)},
|
{NAME("lazy_lock"), CTL(config_lazy_lock)},
|
||||||
|
{NAME("malloc_conf"), CTL(config_malloc_conf)},
|
||||||
{NAME("munmap"), CTL(config_munmap)},
|
{NAME("munmap"), CTL(config_munmap)},
|
||||||
{NAME("prof"), CTL(config_prof)},
|
{NAME("prof"), CTL(config_prof)},
|
||||||
{NAME("prof_libgcc"), CTL(config_prof_libgcc)},
|
{NAME("prof_libgcc"), CTL(config_prof_libgcc)},
|
||||||
@ -1199,17 +1201,17 @@ label_return: \
|
|||||||
return (ret); \
|
return (ret); \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CTL_RO_BOOL_CONFIG_GEN(n) \
|
#define CTL_RO_CONFIG_GEN(n, t) \
|
||||||
static int \
|
static int \
|
||||||
n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \
|
n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \
|
||||||
void *newp, size_t newlen) \
|
void *newp, size_t newlen) \
|
||||||
{ \
|
{ \
|
||||||
int ret; \
|
int ret; \
|
||||||
bool oldval; \
|
t oldval; \
|
||||||
\
|
\
|
||||||
READONLY(); \
|
READONLY(); \
|
||||||
oldval = n; \
|
oldval = n; \
|
||||||
READ(oldval, bool); \
|
READ(oldval, t); \
|
||||||
\
|
\
|
||||||
ret = 0; \
|
ret = 0; \
|
||||||
label_return: \
|
label_return: \
|
||||||
@ -1241,20 +1243,21 @@ label_return:
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_cache_oblivious)
|
CTL_RO_CONFIG_GEN(config_cache_oblivious, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_debug)
|
CTL_RO_CONFIG_GEN(config_debug, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_fill)
|
CTL_RO_CONFIG_GEN(config_fill, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_lazy_lock)
|
CTL_RO_CONFIG_GEN(config_lazy_lock, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_munmap)
|
CTL_RO_CONFIG_GEN(config_malloc_conf, const char *)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_prof)
|
CTL_RO_CONFIG_GEN(config_munmap, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_prof_libgcc)
|
CTL_RO_CONFIG_GEN(config_prof, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_prof_libunwind)
|
CTL_RO_CONFIG_GEN(config_prof_libgcc, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_stats)
|
CTL_RO_CONFIG_GEN(config_prof_libunwind, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_tcache)
|
CTL_RO_CONFIG_GEN(config_stats, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_tls)
|
CTL_RO_CONFIG_GEN(config_tcache, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_utrace)
|
CTL_RO_CONFIG_GEN(config_tls, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_valgrind)
|
CTL_RO_CONFIG_GEN(config_utrace, bool)
|
||||||
CTL_RO_BOOL_CONFIG_GEN(config_xmalloc)
|
CTL_RO_CONFIG_GEN(config_valgrind, bool)
|
||||||
|
CTL_RO_CONFIG_GEN(config_xmalloc, bool)
|
||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
@ -902,10 +902,13 @@ malloc_conf_init(void)
|
|||||||
opt_tcache = false;
|
opt_tcache = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
/* Get runtime configuration. */
|
/* Get runtime configuration. */
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 0:
|
case 0:
|
||||||
|
opts = config_malloc_conf;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
if (je_malloc_conf != NULL) {
|
if (je_malloc_conf != NULL) {
|
||||||
/*
|
/*
|
||||||
* Use options that were compiled into the
|
* Use options that were compiled into the
|
||||||
@ -918,7 +921,7 @@ malloc_conf_init(void)
|
|||||||
opts = buf;
|
opts = buf;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1: {
|
case 2: {
|
||||||
int linklen = 0;
|
int linklen = 0;
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
int saved_errno = errno;
|
int saved_errno = errno;
|
||||||
@ -945,7 +948,7 @@ malloc_conf_init(void)
|
|||||||
buf[linklen] = '\0';
|
buf[linklen] = '\0';
|
||||||
opts = buf;
|
opts = buf;
|
||||||
break;
|
break;
|
||||||
} case 2: {
|
} case 3: {
|
||||||
const char *envname =
|
const char *envname =
|
||||||
#ifdef JEMALLOC_PREFIX
|
#ifdef JEMALLOC_PREFIX
|
||||||
JEMALLOC_CPREFIX"MALLOC_CONF"
|
JEMALLOC_CPREFIX"MALLOC_CONF"
|
||||||
|
@ -438,6 +438,8 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
|
|||||||
CTL_GET("config.debug", &bv, bool);
|
CTL_GET("config.debug", &bv, bool);
|
||||||
malloc_cprintf(write_cb, cbopaque, "Assertions %s\n",
|
malloc_cprintf(write_cb, cbopaque, "Assertions %s\n",
|
||||||
bv ? "enabled" : "disabled");
|
bv ? "enabled" : "disabled");
|
||||||
|
malloc_cprintf(write_cb, cbopaque,
|
||||||
|
"config.malloc_conf: \"%s\"\n", config_malloc_conf);
|
||||||
|
|
||||||
#define OPT_WRITE_BOOL(n) \
|
#define OPT_WRITE_BOOL(n) \
|
||||||
if (je_mallctl("opt."#n, &bv, &bsz, NULL, 0) == 0) { \
|
if (je_mallctl("opt."#n, &bv, &bsz, NULL, 0) == 0) { \
|
||||||
|
@ -117,8 +117,8 @@ TEST_END
|
|||||||
TEST_BEGIN(test_mallctl_config)
|
TEST_BEGIN(test_mallctl_config)
|
||||||
{
|
{
|
||||||
|
|
||||||
#define TEST_MALLCTL_CONFIG(config) do { \
|
#define TEST_MALLCTL_CONFIG(config, t) do { \
|
||||||
bool oldval; \
|
t oldval; \
|
||||||
size_t sz = sizeof(oldval); \
|
size_t sz = sizeof(oldval); \
|
||||||
assert_d_eq(mallctl("config."#config, &oldval, &sz, NULL, 0), \
|
assert_d_eq(mallctl("config."#config, &oldval, &sz, NULL, 0), \
|
||||||
0, "Unexpected mallctl() failure"); \
|
0, "Unexpected mallctl() failure"); \
|
||||||
@ -126,20 +126,21 @@ TEST_BEGIN(test_mallctl_config)
|
|||||||
assert_zu_eq(sz, sizeof(oldval), "Unexpected output size"); \
|
assert_zu_eq(sz, sizeof(oldval), "Unexpected output size"); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
TEST_MALLCTL_CONFIG(cache_oblivious);
|
TEST_MALLCTL_CONFIG(cache_oblivious, bool);
|
||||||
TEST_MALLCTL_CONFIG(debug);
|
TEST_MALLCTL_CONFIG(debug, bool);
|
||||||
TEST_MALLCTL_CONFIG(fill);
|
TEST_MALLCTL_CONFIG(fill, bool);
|
||||||
TEST_MALLCTL_CONFIG(lazy_lock);
|
TEST_MALLCTL_CONFIG(lazy_lock, bool);
|
||||||
TEST_MALLCTL_CONFIG(munmap);
|
TEST_MALLCTL_CONFIG(malloc_conf, const char *);
|
||||||
TEST_MALLCTL_CONFIG(prof);
|
TEST_MALLCTL_CONFIG(munmap, bool);
|
||||||
TEST_MALLCTL_CONFIG(prof_libgcc);
|
TEST_MALLCTL_CONFIG(prof, bool);
|
||||||
TEST_MALLCTL_CONFIG(prof_libunwind);
|
TEST_MALLCTL_CONFIG(prof_libgcc, bool);
|
||||||
TEST_MALLCTL_CONFIG(stats);
|
TEST_MALLCTL_CONFIG(prof_libunwind, bool);
|
||||||
TEST_MALLCTL_CONFIG(tcache);
|
TEST_MALLCTL_CONFIG(stats, bool);
|
||||||
TEST_MALLCTL_CONFIG(tls);
|
TEST_MALLCTL_CONFIG(tcache, bool);
|
||||||
TEST_MALLCTL_CONFIG(utrace);
|
TEST_MALLCTL_CONFIG(tls, bool);
|
||||||
TEST_MALLCTL_CONFIG(valgrind);
|
TEST_MALLCTL_CONFIG(utrace, bool);
|
||||||
TEST_MALLCTL_CONFIG(xmalloc);
|
TEST_MALLCTL_CONFIG(valgrind, bool);
|
||||||
|
TEST_MALLCTL_CONFIG(xmalloc, bool);
|
||||||
|
|
||||||
#undef TEST_MALLCTL_CONFIG
|
#undef TEST_MALLCTL_CONFIG
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user