From: DJ Delorie Date: Sat, 16 Jul 2016 01:39:30 +0000 (-0400) Subject: Add tunables for tcache count and max size X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4650ee4a81d530a3062621c65fcfc76c575ecbe;p=thirdparty%2Fglibc.git Add tunables for tcache count and max size --- diff --git a/malloc/README.copr.html b/malloc/README.copr.html index 543758cf644..7b53930c73d 100644 --- a/malloc/README.copr.html +++ b/malloc/README.copr.html @@ -155,6 +155,25 @@ see size = tc_ibytes | flags; flags |= PREV_INUSE; - for (i = 0; i < TCACHE_FILL_COUNT; i++) + for (i = 0; i < mp_.tcache_count; i++) { m = (mchunkptr) (ent + i * tc_ibytes + tc_bytes); e = (TCacheEntry *) (ent + i * tc_ibytes + tc_ibytes); @@ -3914,7 +3931,7 @@ _tcache_fill (mstate av, size_t original_nb, mchunkptr chunk) int tc_idx = size2tidx (original_nb - SIZE_SZ); int bits = chunk->size & SIZE_BITS; - if (original_nb-SIZE_SZ > MAX_TCACHE_SIZE) + if (tc_idx > mp_.tcache_max) return chunk; //_m_printf("_tcache_fill %p %x %d %d %p\n", chunk, (unsigned int)original_nb, n, MALLOC_ALIGNMENT, @@ -3949,11 +3966,11 @@ _tcache_fill (mstate av, size_t original_nb, mchunkptr chunk) static int _tcache_maxsize (INTERNAL_SIZE_T desired_size, INTERNAL_SIZE_T actual_size) { - if (desired_size-SIZE_SZ > MAX_TCACHE_SIZE) + if (size2tidx(desired_size-SIZE_SZ) > mp_.tcache_max) return desired_size; actual_size -= actual_size % desired_size; - if (actual_size > desired_size * TCACHE_FILL_COUNT) - actual_size = desired_size * TCACHE_FILL_COUNT; + if (actual_size > desired_size * mp_.tcache_count) + actual_size = desired_size * mp_.tcache_count; return actual_size; } #endif @@ -4043,14 +4060,14 @@ _int_malloc (mstate av, size_t bytes) #if USE_TCACHE /* While we're here, if we see other chunk of the same size, stash them in the tcache. */ - if (nb-SIZE_SZ < MAX_TCACHE_SIZE) + int tc_idx = size2tidx (nb-SIZE_SZ); + if (tc_idx < mp_.tcache_max) { - int tc_idx = size2tidx (nb-SIZE_SZ); mchunkptr tc_victim; int found = 0; /* While bin not empty and tcache not full, copy chunks over. */ - while (tcache.counts[tc_idx] < TCACHE_FILL_COUNT + while (tcache.counts[tc_idx] < mp_.tcache_count && (pp = *fb) != NULL) { do @@ -4113,14 +4130,14 @@ _int_malloc (mstate av, size_t bytes) #if USE_TCACHE /* While we're here, if we see other chunk of the same size, stash them in the tcache. */ - if (nb-SIZE_SZ < MAX_TCACHE_SIZE) + int tc_idx = size2tidx (nb-SIZE_SZ); + if (tc_idx < mp_.tcache_max) { - int tc_idx = size2tidx (nb-SIZE_SZ); mchunkptr tc_victim; int found = 0; /* While bin not empty and tcache not full, copy chunks over. */ - while (tcache.counts[tc_idx] < TCACHE_FILL_COUNT + while (tcache.counts[tc_idx] < mp_.tcache_count && (tc_victim = last(bin)) != bin) { if (tc_victim != 0) @@ -4186,11 +4203,11 @@ _int_malloc (mstate av, size_t bytes) #if USE_TCACHE INTERNAL_SIZE_T tcache_nb = 0; //INTERNAL_SIZE_T tcache_max = 0; - if (nb-SIZE_SZ <= MAX_TCACHE_SIZE) + if (size2tidx (nb-SIZE_SZ) <= mp_.tcache_max) { //int tc_idx = size2tidx (bytes); tcache_nb = nb; - //tcache_max = nb * (TCACHE_FILL_COUNT - tcache.counts[tc_idx]); + //tcache_max = nb * (mp_.tcache_count - tcache.counts[tc_idx]); } int tc_idx = size2tidx (nb-SIZE_SZ); int return_cached = 0; @@ -4261,7 +4278,7 @@ _int_malloc (mstate av, size_t bytes) #if 0 && USE_TCACHE /* This forces us to split up bigger chunks later */ && tcache_nb - && tcache.counts[tc_idx] < TCACHE_FILL_COUNT + && tcache.counts[tc_idx] < mp_.tcache_count #endif ) { @@ -4273,7 +4290,7 @@ _int_malloc (mstate av, size_t bytes) /* Fill cache first, return to user only if cache fills. We may return one of these chunks later. */ if (tcache_nb - && tcache.counts[tc_idx] < TCACHE_FILL_COUNT) + && tcache.counts[tc_idx] < mp_.tcache_count) { TCacheEntry *e = (TCacheEntry *) chunk2mem(victim); e->next = tcache.entries[tc_idx]; @@ -4685,8 +4702,8 @@ _int_free (mstate av, mchunkptr p, int have_lock) { int tc_idx = size2tidx (size - SIZE_SZ); - if (size - SIZE_SZ < MAX_TCACHE_SIZE - && tcache.counts[tc_idx] < TCACHE_FILL_COUNT + if (tc_idx < mp_.tcache_max + && tcache.counts[tc_idx] < mp_.tcache_count && tcache.initted == 1) { TCacheEntry *e = (TCacheEntry *) chunk2mem (p); @@ -5660,6 +5677,26 @@ __libc_mallopt (int param_number, int value) mp_.arena_max = value; } break; +#if USE_TCACHE + case M_TCACHE_COUNT: + if (value >= 0) + { + LIBC_PROBE (memory_mallopt_tcache_count, 2, value, mp_.tcache_count); + mp_.tcache_count = value; + } + break; + case M_TCACHE_MAX: + if (value >= 0) + { + value = size2tidx (value); + if (value < TCACHE_IDX) + { + LIBC_PROBE (memory_mallopt_tcache_max, 2, value, mp_.tcache_max); + mp_.tcache_max = value; + } + } + break; +#endif } (void) mutex_unlock (&av->mutex); return res;