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