|
|
d8307d |
commit f88c59f4657ac2e0bab8f51f60022ecbe7f12e2e
|
|
|
d8307d |
Author: Wilco Dijkstra <wdijkstr@arm.com>
|
|
|
d8307d |
Date: Fri May 17 18:16:20 2019 +0100
|
|
|
d8307d |
|
|
|
d8307d |
Small tcache improvements
|
|
|
d8307d |
|
|
|
d8307d |
Change the tcache->counts[] entries to uint16_t - this removes
|
|
|
d8307d |
the limit set by char and allows a larger tcache. Remove a few
|
|
|
d8307d |
redundant asserts.
|
|
|
d8307d |
|
|
|
d8307d |
bench-malloc-thread with 4 threads is ~15% faster on Cortex-A72.
|
|
|
d8307d |
|
|
|
d8307d |
Reviewed-by: DJ Delorie <dj@redhat.com>
|
|
|
d8307d |
|
|
|
d8307d |
* malloc/malloc.c (MAX_TCACHE_COUNT): Increase to UINT16_MAX.
|
|
|
d8307d |
(tcache_put): Remove redundant assert.
|
|
|
d8307d |
(tcache_get): Remove redundant asserts.
|
|
|
d8307d |
(__libc_malloc): Check tcache count is not zero.
|
|
|
d8307d |
* manual/tunables.texi (glibc.malloc.tcache_count): Update maximum.
|
|
|
d8307d |
|
|
|
d8307d |
(cherry picked from commit 1f50f2ad854c84ead522bfc7331b46dbe6057d53)
|
|
|
d8307d |
|
|
|
d8307d |
diff --git a/malloc/malloc.c b/malloc/malloc.c
|
|
|
d8307d |
index 998879aededf0d7c..e6a483d5cf7c4312 100644
|
|
|
d8307d |
--- a/malloc/malloc.c
|
|
|
d8307d |
+++ b/malloc/malloc.c
|
|
|
d8307d |
@@ -321,6 +321,10 @@ __malloc_assert (const char *assertion, const char *file, unsigned int line,
|
|
|
d8307d |
/* This is another arbitrary limit, which tunables can change. Each
|
|
|
d8307d |
tcache bin will hold at most this number of chunks. */
|
|
|
d8307d |
# define TCACHE_FILL_COUNT 7
|
|
|
d8307d |
+
|
|
|
d8307d |
+/* Maximum chunks in tcache bins for tunables. This value must fit the range
|
|
|
d8307d |
+ of tcache->counts[] entries, else they may overflow. */
|
|
|
d8307d |
+# define MAX_TCACHE_COUNT UINT16_MAX
|
|
|
d8307d |
#endif
|
|
|
d8307d |
|
|
|
d8307d |
|
|
|
d8307d |
@@ -2915,12 +2919,10 @@ typedef struct tcache_entry
|
|
|
d8307d |
time), this is for performance reasons. */
|
|
|
d8307d |
typedef struct tcache_perthread_struct
|
|
|
d8307d |
{
|
|
|
d8307d |
- char counts[TCACHE_MAX_BINS];
|
|
|
d8307d |
+ uint16_t counts[TCACHE_MAX_BINS];
|
|
|
d8307d |
tcache_entry *entries[TCACHE_MAX_BINS];
|
|
|
d8307d |
} tcache_perthread_struct;
|
|
|
d8307d |
|
|
|
d8307d |
-#define MAX_TCACHE_COUNT 127 /* Maximum value of counts[] entries. */
|
|
|
d8307d |
-
|
|
|
d8307d |
static __thread bool tcache_shutting_down = false;
|
|
|
d8307d |
static __thread tcache_perthread_struct *tcache = NULL;
|
|
|
d8307d |
|
|
|
d8307d |
@@ -2930,7 +2932,6 @@ static __always_inline void
|
|
|
d8307d |
tcache_put (mchunkptr chunk, size_t tc_idx)
|
|
|
d8307d |
{
|
|
|
d8307d |
tcache_entry *e = (tcache_entry *) chunk2mem (chunk);
|
|
|
d8307d |
- assert (tc_idx < TCACHE_MAX_BINS);
|
|
|
d8307d |
|
|
|
d8307d |
/* Mark this chunk as "in the tcache" so the test in _int_free will
|
|
|
d8307d |
detect a double free. */
|
|
|
d8307d |
@@ -2947,8 +2948,6 @@ static __always_inline void *
|
|
|
d8307d |
tcache_get (size_t tc_idx)
|
|
|
d8307d |
{
|
|
|
d8307d |
tcache_entry *e = tcache->entries[tc_idx];
|
|
|
d8307d |
- assert (tc_idx < TCACHE_MAX_BINS);
|
|
|
d8307d |
- assert (tcache->counts[tc_idx] > 0);
|
|
|
d8307d |
tcache->entries[tc_idx] = e->next;
|
|
|
d8307d |
--(tcache->counts[tc_idx]);
|
|
|
d8307d |
e->key = NULL;
|
|
|
d8307d |
@@ -3053,9 +3052,8 @@ __libc_malloc (size_t bytes)
|
|
|
d8307d |
|
|
|
d8307d |
DIAG_PUSH_NEEDS_COMMENT;
|
|
|
d8307d |
if (tc_idx < mp_.tcache_bins
|
|
|
d8307d |
- /*&& tc_idx < TCACHE_MAX_BINS*/ /* to appease gcc */
|
|
|
d8307d |
&& tcache
|
|
|
d8307d |
- && tcache->entries[tc_idx] != NULL)
|
|
|
d8307d |
+ && tcache->counts[tc_idx] > 0)
|
|
|
d8307d |
{
|
|
|
d8307d |
return tcache_get (tc_idx);
|
|
|
d8307d |
}
|
|
|
d8307d |
diff --git a/manual/tunables.texi b/manual/tunables.texi
|
|
|
d8307d |
index 9dccf2ee7f8eec17..f6c49250e3889ddd 100644
|
|
|
d8307d |
--- a/manual/tunables.texi
|
|
|
d8307d |
+++ b/manual/tunables.texi
|
|
|
d8307d |
@@ -188,7 +188,7 @@ per-thread cache. The default (and maximum) value is 1032 bytes on
|
|
|
d8307d |
|
|
|
d8307d |
@deftp Tunable glibc.malloc.tcache_count
|
|
|
d8307d |
The maximum number of chunks of each size to cache. The default is 7.
|
|
|
d8307d |
-The upper limit is 127. If set to zero, the per-thread cache is effectively
|
|
|
d8307d |
+The upper limit is 65535. If set to zero, the per-thread cache is effectively
|
|
|
d8307d |
disabled.
|
|
|
d8307d |
|
|
|
d8307d |
The approximate maximum overhead of the per-thread cache is thus equal
|