Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit f829009

Browse files
Jason Evansjasone
Jason Evans
authored andcommittedFeb 20, 2016
Add --with-malloc-conf.
Add --with-malloc-conf, which makes it possible to embed a default options string during configuration.
1 parent ef349f3 commit f829009

File tree

9 files changed

+87
-44
lines changed

9 files changed

+87
-44
lines changed
 

‎INSTALL

+8
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ any of the following arguments (not a definitive list) to 'configure':
8484
versions of jemalloc can coexist in the same installation directory. For
8585
example, libjemalloc.so.0 becomes libjemalloc<suffix>.so.0.
8686

87+
--with-malloc-conf=<malloc_conf>
88+
Embed <malloc_conf> as a run-time options string that is processed prior to
89+
the malloc_conf global variable, the /etc/malloc.conf symlink, and the
90+
MALLOC_CONF environment variable. For example, to change the default chunk
91+
size to 256 KiB:
92+
93+
--with-malloc-conf=lg_chunk:18
94+
8795
--disable-cc-silence
8896
Disable code that silences non-useful compiler warnings. This is mainly
8997
useful during development when auditing the set of warnings that are being

‎configure.ac

+10
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,15 @@ AC_ARG_WITH([install_suffix],
577577
install_suffix="$INSTALL_SUFFIX"
578578
AC_SUBST([install_suffix])
579579

580+
dnl Specify default malloc_conf.
581+
AC_ARG_WITH([malloc_conf],
582+
[AS_HELP_STRING([--with-malloc-conf=<malloc_conf>], [config.malloc_conf options string])],
583+
[JEMALLOC_CONFIG_MALLOC_CONF="$with_malloc_conf"],
584+
[JEMALLOC_CONFIG_MALLOC_CONF=""]
585+
)
586+
config_malloc_conf="$JEMALLOC_CONFIG_MALLOC_CONF"
587+
AC_DEFINE_UNQUOTED([JEMALLOC_CONFIG_MALLOC_CONF], ["$config_malloc_conf"])
588+
580589
dnl Substitute @je_@ in jemalloc_protos.h.in, primarily to make generation of
581590
dnl jemalloc_protos_jet.h easy.
582591
je_="je_"
@@ -1726,6 +1735,7 @@ AC_MSG_RESULT([JEMALLOC_PREFIX : ${JEMALLOC_PREFIX}])
17261735
AC_MSG_RESULT([JEMALLOC_PRIVATE_NAMESPACE])
17271736
AC_MSG_RESULT([ : ${JEMALLOC_PRIVATE_NAMESPACE}])
17281737
AC_MSG_RESULT([install_suffix : ${install_suffix}])
1738+
AC_MSG_RESULT([malloc_conf : ${config_malloc_conf}])
17291739
AC_MSG_RESULT([autogen : ${enable_autogen}])
17301740
AC_MSG_RESULT([cc-silence : ${enable_cc_silence}])
17311741
AC_MSG_RESULT([debug : ${enable_debug}])

‎doc/jemalloc.xml.in

+20-8
Original file line numberDiff line numberDiff line change
@@ -455,19 +455,20 @@ for (i = 0; i < nbins; i++) {
455455
routines, the allocator initializes its internals based in part on various
456456
options that can be specified at compile- or run-time.</para>
457457

458-
<para>The string pointed to by the global variable
459-
<varname>malloc_conf</varname>, the &ldquo;name&rdquo; of the file
460-
referenced by the symbolic link named <filename
461-
class="symlink">/etc/malloc.conf</filename>, and the value of the
458+
<para>The string specified via <option>--with-malloc-conf</option>, the
459+
string pointed to by the global variable <varname>malloc_conf</varname>, the
460+
&ldquo;name&rdquo; of the file referenced by the symbolic link named
461+
<filename class="symlink">/etc/malloc.conf</filename>, and the value of the
462462
environment variable <envar>MALLOC_CONF</envar>, will be interpreted, in
463463
that order, from left to right as options. Note that
464464
<varname>malloc_conf</varname> may be read before
465465
<function>main<parameter/></function> is entered, so the declaration of
466466
<varname>malloc_conf</varname> should specify an initializer that contains
467-
the final value to be read by jemalloc. <varname>malloc_conf</varname> is
468-
a compile-time setting, whereas <filename
469-
class="symlink">/etc/malloc.conf</filename> and <envar>MALLOC_CONF</envar>
470-
can be safely set any time prior to program invocation.</para>
467+
the final value to be read by jemalloc. <option>--with-malloc-conf</option>
468+
and <varname>malloc_conf</varname> are compile-time mechanisms, whereas
469+
<filename class="symlink">/etc/malloc.conf</filename> and
470+
<envar>MALLOC_CONF</envar> can be safely set any time prior to program
471+
invocation.</para>
471472

472473
<para>An options string is a comma-separated list of option:value pairs.
473474
There is one key corresponding to each <link
@@ -776,6 +777,17 @@ for (i = 0; i < nbins; i++) {
776777
during build configuration.</para></listitem>
777778
</varlistentry>
778779

780+
<varlistentry id="config.malloc_conf">
781+
<term>
782+
<mallctl>config.malloc_conf</mallctl>
783+
(<type>const char *</type>)
784+
<literal>r-</literal>
785+
</term>
786+
<listitem><para>Embedded configure-time-specified run-time options
787+
string, empty unless <option>--with-malloc-conf</option> was specified
788+
during build configuration.</para></listitem>
789+
</varlistentry>
790+
779791
<varlistentry id="config.munmap">
780792
<term>
781793
<mallctl>config.munmap</mallctl>

‎include/jemalloc/internal/jemalloc_internal.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static const bool config_lazy_lock =
4949
false
5050
#endif
5151
;
52+
static const char * const config_malloc_conf = JEMALLOC_CONFIG_MALLOC_CONF;
5253
static const bool config_prof =
5354
#ifdef JEMALLOC_PROF
5455
true

‎include/jemalloc/internal/jemalloc_internal_defs.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,7 @@
259259
*/
260260
#undef JEMALLOC_EXPORT
261261

262+
/* config.malloc_conf options string. */
263+
#undef JEMALLOC_CONFIG_MALLOC_CONF
264+
262265
#endif /* JEMALLOC_INTERNAL_DEFS_H_ */

‎src/ctl.c

+20-17
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ CTL_PROTO(config_cache_oblivious)
7777
CTL_PROTO(config_debug)
7878
CTL_PROTO(config_fill)
7979
CTL_PROTO(config_lazy_lock)
80+
CTL_PROTO(config_malloc_conf)
8081
CTL_PROTO(config_munmap)
8182
CTL_PROTO(config_prof)
8283
CTL_PROTO(config_prof_libgcc)
@@ -241,6 +242,7 @@ static const ctl_named_node_t config_node[] = {
241242
{NAME("debug"), CTL(config_debug)},
242243
{NAME("fill"), CTL(config_fill)},
243244
{NAME("lazy_lock"), CTL(config_lazy_lock)},
245+
{NAME("malloc_conf"), CTL(config_malloc_conf)},
244246
{NAME("munmap"), CTL(config_munmap)},
245247
{NAME("prof"), CTL(config_prof)},
246248
{NAME("prof_libgcc"), CTL(config_prof_libgcc)},
@@ -1199,17 +1201,17 @@ label_return: \
11991201
return (ret); \
12001202
}
12011203

1202-
#define CTL_RO_BOOL_CONFIG_GEN(n) \
1204+
#define CTL_RO_CONFIG_GEN(n, t) \
12031205
static int \
12041206
n##_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp, \
12051207
void *newp, size_t newlen) \
12061208
{ \
12071209
int ret; \
1208-
bool oldval; \
1210+
t oldval; \
12091211
\
12101212
READONLY(); \
12111213
oldval = n; \
1212-
READ(oldval, bool); \
1214+
READ(oldval, t); \
12131215
\
12141216
ret = 0; \
12151217
label_return: \
@@ -1241,20 +1243,21 @@ epoch_ctl(const size_t *mib, size_t miblen, void *oldp, size_t *oldlenp,
12411243

12421244
/******************************************************************************/
12431245

1244-
CTL_RO_BOOL_CONFIG_GEN(config_cache_oblivious)
1245-
CTL_RO_BOOL_CONFIG_GEN(config_debug)
1246-
CTL_RO_BOOL_CONFIG_GEN(config_fill)
1247-
CTL_RO_BOOL_CONFIG_GEN(config_lazy_lock)
1248-
CTL_RO_BOOL_CONFIG_GEN(config_munmap)
1249-
CTL_RO_BOOL_CONFIG_GEN(config_prof)
1250-
CTL_RO_BOOL_CONFIG_GEN(config_prof_libgcc)
1251-
CTL_RO_BOOL_CONFIG_GEN(config_prof_libunwind)
1252-
CTL_RO_BOOL_CONFIG_GEN(config_stats)
1253-
CTL_RO_BOOL_CONFIG_GEN(config_tcache)
1254-
CTL_RO_BOOL_CONFIG_GEN(config_tls)
1255-
CTL_RO_BOOL_CONFIG_GEN(config_utrace)
1256-
CTL_RO_BOOL_CONFIG_GEN(config_valgrind)
1257-
CTL_RO_BOOL_CONFIG_GEN(config_xmalloc)
1246+
CTL_RO_CONFIG_GEN(config_cache_oblivious, bool)
1247+
CTL_RO_CONFIG_GEN(config_debug, bool)
1248+
CTL_RO_CONFIG_GEN(config_fill, bool)
1249+
CTL_RO_CONFIG_GEN(config_lazy_lock, bool)
1250+
CTL_RO_CONFIG_GEN(config_malloc_conf, const char *)
1251+
CTL_RO_CONFIG_GEN(config_munmap, bool)
1252+
CTL_RO_CONFIG_GEN(config_prof, bool)
1253+
CTL_RO_CONFIG_GEN(config_prof_libgcc, bool)
1254+
CTL_RO_CONFIG_GEN(config_prof_libunwind, bool)
1255+
CTL_RO_CONFIG_GEN(config_stats, bool)
1256+
CTL_RO_CONFIG_GEN(config_tcache, bool)
1257+
CTL_RO_CONFIG_GEN(config_tls, bool)
1258+
CTL_RO_CONFIG_GEN(config_utrace, bool)
1259+
CTL_RO_CONFIG_GEN(config_valgrind, bool)
1260+
CTL_RO_CONFIG_GEN(config_xmalloc, bool)
12581261

12591262
/******************************************************************************/
12601263

‎src/jemalloc.c

+6-3
Original file line numberDiff line numberDiff line change
@@ -902,10 +902,13 @@ malloc_conf_init(void)
902902
opt_tcache = false;
903903
}
904904

905-
for (i = 0; i < 3; i++) {
905+
for (i = 0; i < 4; i++) {
906906
/* Get runtime configuration. */
907907
switch (i) {
908908
case 0:
909+
opts = config_malloc_conf;
910+
break;
911+
case 1:
909912
if (je_malloc_conf != NULL) {
910913
/*
911914
* Use options that were compiled into the
@@ -918,7 +921,7 @@ malloc_conf_init(void)
918921
opts = buf;
919922
}
920923
break;
921-
case 1: {
924+
case 2: {
922925
int linklen = 0;
923926
#ifndef _WIN32
924927
int saved_errno = errno;
@@ -945,7 +948,7 @@ malloc_conf_init(void)
945948
buf[linklen] = '\0';
946949
opts = buf;
947950
break;
948-
} case 2: {
951+
} case 3: {
949952
const char *envname =
950953
#ifdef JEMALLOC_PREFIX
951954
JEMALLOC_CPREFIX"MALLOC_CONF"

‎src/stats.c

+2
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,8 @@ stats_print(void (*write_cb)(void *, const char *), void *cbopaque,
438438
CTL_GET("config.debug", &bv, bool);
439439
malloc_cprintf(write_cb, cbopaque, "Assertions %s\n",
440440
bv ? "enabled" : "disabled");
441+
malloc_cprintf(write_cb, cbopaque,
442+
"config.malloc_conf: \"%s\"\n", config_malloc_conf);
441443

442444
#define OPT_WRITE_BOOL(n) \
443445
if (je_mallctl("opt."#n, &bv, &bsz, NULL, 0) == 0) { \

‎test/unit/mallctl.c

+17-16
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,30 @@ TEST_END
117117
TEST_BEGIN(test_mallctl_config)
118118
{
119119

120-
#define TEST_MALLCTL_CONFIG(config) do { \
121-
bool oldval; \
120+
#define TEST_MALLCTL_CONFIG(config, t) do { \
121+
t oldval; \
122122
size_t sz = sizeof(oldval); \
123123
assert_d_eq(mallctl("config."#config, &oldval, &sz, NULL, 0), \
124124
0, "Unexpected mallctl() failure"); \
125125
assert_b_eq(oldval, config_##config, "Incorrect config value"); \
126126
assert_zu_eq(sz, sizeof(oldval), "Unexpected output size"); \
127127
} while (0)
128128

129-
TEST_MALLCTL_CONFIG(cache_oblivious);
130-
TEST_MALLCTL_CONFIG(debug);
131-
TEST_MALLCTL_CONFIG(fill);
132-
TEST_MALLCTL_CONFIG(lazy_lock);
133-
TEST_MALLCTL_CONFIG(munmap);
134-
TEST_MALLCTL_CONFIG(prof);
135-
TEST_MALLCTL_CONFIG(prof_libgcc);
136-
TEST_MALLCTL_CONFIG(prof_libunwind);
137-
TEST_MALLCTL_CONFIG(stats);
138-
TEST_MALLCTL_CONFIG(tcache);
139-
TEST_MALLCTL_CONFIG(tls);
140-
TEST_MALLCTL_CONFIG(utrace);
141-
TEST_MALLCTL_CONFIG(valgrind);
142-
TEST_MALLCTL_CONFIG(xmalloc);
129+
TEST_MALLCTL_CONFIG(cache_oblivious, bool);
130+
TEST_MALLCTL_CONFIG(debug, bool);
131+
TEST_MALLCTL_CONFIG(fill, bool);
132+
TEST_MALLCTL_CONFIG(lazy_lock, bool);
133+
TEST_MALLCTL_CONFIG(malloc_conf, const char *);
134+
TEST_MALLCTL_CONFIG(munmap, bool);
135+
TEST_MALLCTL_CONFIG(prof, bool);
136+
TEST_MALLCTL_CONFIG(prof_libgcc, bool);
137+
TEST_MALLCTL_CONFIG(prof_libunwind, bool);
138+
TEST_MALLCTL_CONFIG(stats, bool);
139+
TEST_MALLCTL_CONFIG(tcache, bool);
140+
TEST_MALLCTL_CONFIG(tls, bool);
141+
TEST_MALLCTL_CONFIG(utrace, bool);
142+
TEST_MALLCTL_CONFIG(valgrind, bool);
143+
TEST_MALLCTL_CONFIG(xmalloc, bool);
143144

144145
#undef TEST_MALLCTL_CONFIG
145146
}

0 commit comments

Comments
 (0)
This repository has been archived.