Switch from opt.lg_tcache_max to opt.tcache_max
Though for convenience, keep parsing lg_tcache_max.
This commit is contained in:
parent
5ba861715a
commit
c8209150f9
@ -1301,21 +1301,23 @@ malloc_conf = "xmalloc:true";]]></programlisting>
|
|||||||
a certain size. Thread-specific caching allows many allocations to be
|
a certain size. Thread-specific caching allows many allocations to be
|
||||||
satisfied without performing any thread synchronization, at the cost of
|
satisfied without performing any thread synchronization, at the cost of
|
||||||
increased memory use. See the <link
|
increased memory use. See the <link
|
||||||
linkend="opt.lg_tcache_max"><mallctl>opt.lg_tcache_max</mallctl></link>
|
linkend="opt.tcache_max"><mallctl>opt.tcache_max</mallctl></link>
|
||||||
option for related tuning information. This option is enabled by
|
option for related tuning information. This option is enabled by
|
||||||
default.</para></listitem>
|
default.</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry id="opt.lg_tcache_max">
|
<varlistentry id="opt.tcache_max">
|
||||||
<term>
|
<term>
|
||||||
<mallctl>opt.lg_tcache_max</mallctl>
|
<mallctl>opt.tcache_max</mallctl>
|
||||||
(<type>size_t</type>)
|
(<type>size_t</type>)
|
||||||
<literal>r-</literal>
|
<literal>r-</literal>
|
||||||
</term>
|
</term>
|
||||||
<listitem><para>Maximum size class (log base 2) to cache in the
|
<listitem><para>Maximum size class to cache in the thread-specific cache
|
||||||
thread-specific cache (tcache). At a minimum, all small size classes
|
(tcache). At a minimum, all small size classes are cached; and at a
|
||||||
are cached; and at a maximum, size classes up to 8 MiB can be cached.
|
maximum, size classes up to 8 MiB can be cached. The default maximum is
|
||||||
The default maximum is 32 KiB (2^15).</para></listitem>
|
32 KiB (2^15). As a convenience, this may also be set by specifying
|
||||||
|
lg_tcache_max, which will be taken to be the base-2 logarithm of the
|
||||||
|
setting of tcache_max</para></listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
<varlistentry id="opt.thp">
|
<varlistentry id="opt.thp">
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#define JEMALLOC_INTERNAL_TCACHE_EXTERNS_H
|
#define JEMALLOC_INTERNAL_TCACHE_EXTERNS_H
|
||||||
|
|
||||||
extern bool opt_tcache;
|
extern bool opt_tcache;
|
||||||
extern ssize_t opt_lg_tcache_max;
|
extern size_t opt_tcache_max;
|
||||||
extern ssize_t opt_lg_tcache_nslots_mul;
|
extern ssize_t opt_lg_tcache_nslots_mul;
|
||||||
extern unsigned opt_tcache_nslots_small_min;
|
extern unsigned opt_tcache_nslots_small_min;
|
||||||
extern unsigned opt_tcache_nslots_small_max;
|
extern unsigned opt_tcache_nslots_small_max;
|
||||||
|
@ -109,7 +109,7 @@ CTL_PROTO(opt_zero)
|
|||||||
CTL_PROTO(opt_utrace)
|
CTL_PROTO(opt_utrace)
|
||||||
CTL_PROTO(opt_xmalloc)
|
CTL_PROTO(opt_xmalloc)
|
||||||
CTL_PROTO(opt_tcache)
|
CTL_PROTO(opt_tcache)
|
||||||
CTL_PROTO(opt_lg_tcache_max)
|
CTL_PROTO(opt_tcache_max)
|
||||||
CTL_PROTO(opt_tcache_nslots_small_min)
|
CTL_PROTO(opt_tcache_nslots_small_min)
|
||||||
CTL_PROTO(opt_tcache_nslots_small_max)
|
CTL_PROTO(opt_tcache_nslots_small_max)
|
||||||
CTL_PROTO(opt_tcache_nslots_large)
|
CTL_PROTO(opt_tcache_nslots_large)
|
||||||
@ -362,7 +362,7 @@ static const ctl_named_node_t opt_node[] = {
|
|||||||
{NAME("utrace"), CTL(opt_utrace)},
|
{NAME("utrace"), CTL(opt_utrace)},
|
||||||
{NAME("xmalloc"), CTL(opt_xmalloc)},
|
{NAME("xmalloc"), CTL(opt_xmalloc)},
|
||||||
{NAME("tcache"), CTL(opt_tcache)},
|
{NAME("tcache"), CTL(opt_tcache)},
|
||||||
{NAME("lg_tcache_max"), CTL(opt_lg_tcache_max)},
|
{NAME("tcache_max"), CTL(opt_tcache_max)},
|
||||||
{NAME("tcache_nslots_small_min"),
|
{NAME("tcache_nslots_small_min"),
|
||||||
CTL(opt_tcache_nslots_small_min)},
|
CTL(opt_tcache_nslots_small_min)},
|
||||||
{NAME("tcache_nslots_small_max"),
|
{NAME("tcache_nslots_small_max"),
|
||||||
@ -1837,7 +1837,7 @@ CTL_RO_NL_CGEN(config_fill, opt_zero, opt_zero, bool)
|
|||||||
CTL_RO_NL_CGEN(config_utrace, opt_utrace, opt_utrace, bool)
|
CTL_RO_NL_CGEN(config_utrace, opt_utrace, opt_utrace, bool)
|
||||||
CTL_RO_NL_CGEN(config_xmalloc, opt_xmalloc, opt_xmalloc, bool)
|
CTL_RO_NL_CGEN(config_xmalloc, opt_xmalloc, opt_xmalloc, bool)
|
||||||
CTL_RO_NL_GEN(opt_tcache, opt_tcache, bool)
|
CTL_RO_NL_GEN(opt_tcache, opt_tcache, bool)
|
||||||
CTL_RO_NL_GEN(opt_lg_tcache_max, opt_lg_tcache_max, ssize_t)
|
CTL_RO_NL_GEN(opt_tcache_max, opt_tcache_max, size_t)
|
||||||
CTL_RO_NL_GEN(opt_tcache_nslots_small_min, opt_tcache_nslots_small_min,
|
CTL_RO_NL_GEN(opt_tcache_nslots_small_min, opt_tcache_nslots_small_min,
|
||||||
unsigned)
|
unsigned)
|
||||||
CTL_RO_NL_GEN(opt_tcache_nslots_small_max, opt_tcache_nslots_small_max,
|
CTL_RO_NL_GEN(opt_tcache_nslots_small_max, opt_tcache_nslots_small_max,
|
||||||
|
@ -1170,15 +1170,18 @@ malloc_conf_init_helper(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS],
|
|||||||
#define CONF_DONT_CHECK_MAX(um, max) false
|
#define CONF_DONT_CHECK_MAX(um, max) false
|
||||||
#define CONF_CHECK_MAX(um, max) ((um) > (max))
|
#define CONF_CHECK_MAX(um, max) ((um) > (max))
|
||||||
|
|
||||||
|
#define CONF_VALUE_READ(max_t, result) \
|
||||||
|
char *end; \
|
||||||
|
set_errno(0); \
|
||||||
|
result = (max_t)malloc_strtoumax(v, &end, 0);
|
||||||
|
#define CONF_VALUE_READ_FAIL() \
|
||||||
|
(get_errno() != 0 || (uintptr_t)end - (uintptr_t)v != vlen)
|
||||||
|
|
||||||
#define CONF_HANDLE_T(t, max_t, o, n, min, max, check_min, check_max, clip) \
|
#define CONF_HANDLE_T(t, max_t, o, n, min, max, check_min, check_max, clip) \
|
||||||
if (CONF_MATCH(n)) { \
|
if (CONF_MATCH(n)) { \
|
||||||
max_t mv; \
|
max_t mv; \
|
||||||
char *end; \
|
CONF_VALUE_READ(max_t, mv) \
|
||||||
\
|
if (CONF_VALUE_READ_FAIL()) { \
|
||||||
set_errno(0); \
|
|
||||||
mv = (max_t)malloc_strtoumax(v, &end, 0); \
|
|
||||||
if (get_errno() != 0 || (uintptr_t)end -\
|
|
||||||
(uintptr_t)v != vlen) { \
|
|
||||||
CONF_ERROR("Invalid conf value",\
|
CONF_ERROR("Invalid conf value",\
|
||||||
k, klen, v, vlen); \
|
k, klen, v, vlen); \
|
||||||
} else if (clip) { \
|
} else if (clip) { \
|
||||||
@ -1379,8 +1382,24 @@ malloc_conf_init_helper(sc_data_t *sc_data, unsigned bin_shard_sizes[SC_NBINS],
|
|||||||
CONF_HANDLE_BOOL(opt_xmalloc, "xmalloc")
|
CONF_HANDLE_BOOL(opt_xmalloc, "xmalloc")
|
||||||
}
|
}
|
||||||
CONF_HANDLE_BOOL(opt_tcache, "tcache")
|
CONF_HANDLE_BOOL(opt_tcache, "tcache")
|
||||||
CONF_HANDLE_SSIZE_T(opt_lg_tcache_max, "lg_tcache_max",
|
CONF_HANDLE_SIZE_T(opt_tcache_max, "tcache_max",
|
||||||
-1, (sizeof(size_t) << 3) - 1)
|
0, TCACHE_MAXCLASS_LIMIT, CONF_DONT_CHECK_MIN,
|
||||||
|
CONF_CHECK_MAX, /* clip */ true)
|
||||||
|
if (CONF_MATCH("lg_tcache_max")) {
|
||||||
|
size_t m;
|
||||||
|
CONF_VALUE_READ(size_t, m)
|
||||||
|
if (CONF_VALUE_READ_FAIL()) {
|
||||||
|
CONF_ERROR("Invalid conf value",
|
||||||
|
k, klen, v, vlen);
|
||||||
|
} else {
|
||||||
|
/* clip if necessary */
|
||||||
|
if (m > TCACHE_LG_MAXCLASS_LIMIT) {
|
||||||
|
m = TCACHE_LG_MAXCLASS_LIMIT;
|
||||||
|
}
|
||||||
|
opt_tcache_max = (size_t)1 << m;
|
||||||
|
}
|
||||||
|
CONF_CONTINUE;
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
* Anyone trying to set a value outside -16 to 16 is
|
* Anyone trying to set a value outside -16 to 16 is
|
||||||
* deeply confused.
|
* deeply confused.
|
||||||
|
14
src/tcache.c
14
src/tcache.c
@ -11,11 +11,8 @@
|
|||||||
|
|
||||||
bool opt_tcache = true;
|
bool opt_tcache = true;
|
||||||
|
|
||||||
/*
|
/* tcache_maxclass is set to 32KB by default. */
|
||||||
* (1U << opt_lg_tcache_max) is used to compute tcache_maxclass. This choice
|
size_t opt_tcache_max = ((size_t)1) << 15;
|
||||||
* (32kb by default) works well as a default in practice.
|
|
||||||
*/
|
|
||||||
ssize_t opt_lg_tcache_max = 15;
|
|
||||||
|
|
||||||
/* Reasonable defaults for min and max values. */
|
/* Reasonable defaults for min and max values. */
|
||||||
unsigned opt_tcache_nslots_small_min = 20;
|
unsigned opt_tcache_nslots_small_min = 20;
|
||||||
@ -935,14 +932,11 @@ tcache_ncached_max_compute(szind_t szind) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
tcache_boot(tsdn_t *tsdn, base_t *base) {
|
tcache_boot(tsdn_t *tsdn, base_t *base) {
|
||||||
/* If necessary, clamp opt_lg_tcache_max. */
|
tcache_maxclass = sz_s2u(opt_tcache_max);
|
||||||
tcache_maxclass = opt_lg_tcache_max < 0 ? 0 :
|
|
||||||
ZU(1) << opt_lg_tcache_max;
|
|
||||||
if (tcache_maxclass < SC_SMALL_MAXCLASS) {
|
if (tcache_maxclass < SC_SMALL_MAXCLASS) {
|
||||||
tcache_maxclass = SC_SMALL_MAXCLASS;
|
tcache_maxclass = SC_SMALL_MAXCLASS;
|
||||||
} else if (tcache_maxclass > TCACHE_MAXCLASS_LIMIT) {
|
|
||||||
tcache_maxclass = TCACHE_MAXCLASS_LIMIT;
|
|
||||||
}
|
}
|
||||||
|
assert(tcache_maxclass <= TCACHE_MAXCLASS_LIMIT);
|
||||||
nhbins = sz_size2index(tcache_maxclass) + 1;
|
nhbins = sz_size2index(tcache_maxclass) + 1;
|
||||||
|
|
||||||
if (malloc_mutex_init(&tcaches_mtx, "tcaches", WITNESS_RANK_TCACHES,
|
if (malloc_mutex_init(&tcaches_mtx, "tcaches", WITNESS_RANK_TCACHES,
|
||||||
|
@ -179,7 +179,7 @@ TEST_BEGIN(test_mallctl_opt) {
|
|||||||
TEST_MALLCTL_OPT(bool, xmalloc, xmalloc);
|
TEST_MALLCTL_OPT(bool, xmalloc, xmalloc);
|
||||||
TEST_MALLCTL_OPT(bool, tcache, always);
|
TEST_MALLCTL_OPT(bool, tcache, always);
|
||||||
TEST_MALLCTL_OPT(size_t, lg_extent_max_active_fit, always);
|
TEST_MALLCTL_OPT(size_t, lg_extent_max_active_fit, always);
|
||||||
TEST_MALLCTL_OPT(size_t, lg_tcache_max, always);
|
TEST_MALLCTL_OPT(size_t, tcache_max, always);
|
||||||
TEST_MALLCTL_OPT(const char *, thp, always);
|
TEST_MALLCTL_OPT(const char *, thp, always);
|
||||||
TEST_MALLCTL_OPT(const char *, zero_realloc, always);
|
TEST_MALLCTL_OPT(const char *, zero_realloc, always);
|
||||||
TEST_MALLCTL_OPT(bool, prof, prof);
|
TEST_MALLCTL_OPT(bool, prof, prof);
|
||||||
|
@ -393,7 +393,7 @@ test_tcache_bytes_for_usize(size_t usize) {
|
|||||||
TEST_BEGIN(test_stats_tcache_bytes_small) {
|
TEST_BEGIN(test_stats_tcache_bytes_small) {
|
||||||
test_skip_if(!config_stats);
|
test_skip_if(!config_stats);
|
||||||
test_skip_if(!opt_tcache);
|
test_skip_if(!opt_tcache);
|
||||||
test_skip_if((ZU(1) << opt_lg_tcache_max) < SC_SMALL_MAXCLASS);
|
test_skip_if(opt_tcache_max < SC_SMALL_MAXCLASS);
|
||||||
|
|
||||||
test_tcache_bytes_for_usize(SC_SMALL_MAXCLASS);
|
test_tcache_bytes_for_usize(SC_SMALL_MAXCLASS);
|
||||||
}
|
}
|
||||||
@ -402,7 +402,7 @@ TEST_END
|
|||||||
TEST_BEGIN(test_stats_tcache_bytes_large) {
|
TEST_BEGIN(test_stats_tcache_bytes_large) {
|
||||||
test_skip_if(!config_stats);
|
test_skip_if(!config_stats);
|
||||||
test_skip_if(!opt_tcache);
|
test_skip_if(!opt_tcache);
|
||||||
test_skip_if((ZU(1) << opt_lg_tcache_max) < SC_LARGE_MINCLASS);
|
test_skip_if(opt_tcache_max < SC_LARGE_MINCLASS);
|
||||||
|
|
||||||
test_tcache_bytes_for_usize(SC_LARGE_MINCLASS);
|
test_tcache_bytes_for_usize(SC_LARGE_MINCLASS);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user