From: DJ Delorie Date: Thu, 21 Jul 2016 19:33:27 +0000 (-0400) Subject: Add various bin-related trace path flags X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b096a21663259fa02087697b919f54874e8e98f4;p=thirdparty%2Fglibc.git Add various bin-related trace path flags --- diff --git a/malloc/malloc.c b/malloc/malloc.c index 97537311741..dad7921f8e6 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1192,6 +1192,13 @@ __mtb_trace_entry (uint32_t type, size_t size, void *ptr1) trace_ptr->path_mmap = 0; trace_ptr->path_munmap = 0; trace_ptr->path_m_f_realloc = 0; + trace_ptr->path_hook = 0; + trace_ptr->path_unsorted_add = 0; + trace_ptr->path_unsorted_remove = 0; + trace_ptr->path_unsorted_empty = 0; + trace_ptr->path_fastbin_add = 0; + trace_ptr->path_fastbin_remove = 0; + trace_ptr->path_malloc_consolidate = 0; trace_ptr->path = 0; trace_ptr->ptr1 = ptr1; trace_ptr->ptr2 = 0; @@ -4284,6 +4291,7 @@ _int_malloc (mstate av, size_t bytes) } } #endif + __MTB_TRACE_PATH(fastbin_remove); void *p = chunk2mem (victim); alloc_perturb (p, bytes); return p; @@ -4415,6 +4423,7 @@ _int_malloc (mstate av, size_t bytes) int iters = 0; while ((victim = unsorted_chunks (av)->bk) != unsorted_chunks (av)) { + __MTB_TRACE_PATH(unsorted_remove); bck = victim->bk; if (__builtin_expect (victim->size <= 2 * SIZE_SZ, 0) || __builtin_expect (victim->size > av->system_mem, 0)) @@ -4436,6 +4445,7 @@ _int_malloc (mstate av, size_t bytes) (unsigned long) (size) > (unsigned long) (nb + MINSIZE)) { /* split and reattach remainder */ + __MTB_TRACE_PATH(unsorted_add); remainder_size = size - nb; remainder = chunk_at_offset (victim, nb); unsorted_chunks (av)->bk = unsorted_chunks (av)->fd = remainder; @@ -4574,6 +4584,9 @@ _int_malloc (mstate av, size_t bytes) if (++iters >= MAX_ITERS) break; } + if (unsorted_chunks (av)->bk == unsorted_chunks (av)) + __MTB_TRACE_PATH(unsorted_empty); + #if USE_TCACHE /* If all the small chunks we found ended up cached, return one now. */ @@ -4625,6 +4638,7 @@ _int_malloc (mstate av, size_t bytes) remainder = chunk_at_offset (victim, nb); /* We cannot assume the unsorted list is empty and therefore have to perform a complete insert here. */ + __MTB_TRACE_PATH(unsorted_add); bck = unsorted_chunks (av); fwd = bck->fd; if (__glibc_unlikely (fwd->bk != bck)) @@ -4737,6 +4751,7 @@ _int_malloc (mstate av, size_t bytes) /* We cannot assume the unsorted list is empty and therefore have to perform a complete insert here. */ + __MTB_TRACE_PATH(unsorted_add); bck = unsorted_chunks (av); fwd = bck->fd; if (__glibc_unlikely (fwd->bk != bck)) @@ -4959,6 +4974,7 @@ _int_free (mstate av, mchunkptr p, int have_lock) fb = &fastbin (av, idx); /* Atomically link P to its fastbin: P->FD = *FB; *FB = P; */ + __MTB_TRACE_PATH(fastbin_add); mchunkptr old = *fb, old2; unsigned int old_idx = ~0u; do @@ -5056,6 +5072,7 @@ _int_free (mstate av, mchunkptr p, int have_lock) been given one chance to be used in malloc. */ + __MTB_TRACE_PATH(unsorted_add); bck = unsorted_chunks(av); fwd = bck->fd; if (__glibc_unlikely (fwd->bk != bck)) @@ -5170,6 +5187,8 @@ static void malloc_consolidate(mstate av) mchunkptr bck; mchunkptr fwd; + __MTB_TRACE_PATH(malloc_consolidate); + /* If max_fast is 0, we know that av hasn't yet been initialized, in which case do so below @@ -5197,6 +5216,7 @@ static void malloc_consolidate(mstate av) check_inuse_chunk(av, p); nextp = p->fd; + __MTB_TRACE_PATH(fastbin_remove); /* Slightly streamlined version of consolidation code in free() */ size = p->size & ~(PREV_INUSE|NON_MAIN_ARENA); nextchunk = chunk_at_offset(p, size); @@ -5218,6 +5238,7 @@ static void malloc_consolidate(mstate av) } else clear_inuse_bit_at_offset(nextchunk, 0); + __MTB_TRACE_PATH(unsorted_add); first_unsorted = unsorted_bin->fd; unsorted_bin->fd = p; first_unsorted->bk = p; diff --git a/malloc/mtrace.h b/malloc/mtrace.h index 6ce663deb00..b151f479f81 100644 --- a/malloc/mtrace.h +++ b/malloc/mtrace.h @@ -34,7 +34,13 @@ struct __malloc_trace_buffer_s { uint32_t path_munmap:1; /* munmap was called */ uint32_t path_m_f_realloc:1; /* realloc became malloc/free (i.e. next few records) */ uint32_t path_hook:1; /* A hook was used to complete the request */ - uint32_t path:16; /* remaining bits */ + uint32_t path_unsorted_add:1; /* something was added to the unsorted bin */ + uint32_t path_unsorted_remove:1; /* something was removed from the unsorted bin */ + uint32_t path_unsorted_empty:1; /* the unsorted bin was emptied */ + uint32_t path_fastbin_add:1; /* something was added to a fastbin */ + uint32_t path_fastbin_remove:1; /* something was removed from a fastbin */ + uint32_t path_malloc_consolidate:1; /* something was removed from a fastbin */ + uint32_t path:10; /* remaining bits */ /* FREE - pointer to allocation to free. REALLOC - pointer to original allocation. diff --git a/malloc/trace_dump.c b/malloc/trace_dump.c index 7b691d9ed0e..95535cd59c2 100644 --- a/malloc/trace_dump.c +++ b/malloc/trace_dump.c @@ -77,7 +77,7 @@ dump_raw_trace (unsigned char *data, long n_data) default: /* Consider 'memalign' to be the largest API word we want to align on so make the name 8 chars wide at a minimum. */ - printf ("%08x %8s %c%c%c%c%c%c%c%c %016llx %016llx %016llx %016llx %016llx\n", + printf ("%08x %8s %c%c%c%c%c%c%c%c%c%c%c%c%c%c %016llx %016llx %016llx %016llx %016llx\n", t->thread, t->type == __MTB_TYPE_MAGIC ? "magic" : typenames[t->type], t->path_thread_cache ? 'T' : '-', @@ -88,6 +88,12 @@ dump_raw_trace (unsigned char *data, long n_data) t->path_munmap ? 'U' : '-', t->path_m_f_realloc ? 'R' : '-', t->path_hook ? 'H' : '-', + t->path_unsorted_add ? 'U' : '-', + t->path_unsorted_remove ? 'u' : '-', + t->path_unsorted_empty ? 'E' : '-', + t->path_fastbin_add ? 'F' : '-', + t->path_fastbin_remove ? 'f' : '-', + t->path_malloc_consolidate ? 'C' : '-', (long long unsigned int) (size_t) t->ptr1, (long long unsigned int) t->size, (long long unsigned int) (size_t) t->ptr2,