about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDJ Delorie <dj@delorie.com>2017-05-11 17:25:10 -0400
committerDJ Delorie <dj@delorie.com>2017-05-11 17:27:35 -0400
commit827734fa03eb4b55f74319a4ffaa0b00c9c2785d (patch)
tree3c015c1bb235a12289d0f1d80113c31f724854a7
parent4da80dbb06a7394581f74deae489858bf1607f90 (diff)
downloadglibc-dj/malloc-tcache.tar.gz
glibc-dj/malloc-tcache.tar.xz
glibc-dj/malloc-tcache.zip
Tweak Makefile, asserts, comments. dj/malloc-tcache
* Un-Wundef-ify -DUSE_TCACHE
* More asserts in tcache get/put functions
* Clarify redundancy in tcache structure
-rw-r--r--malloc/Makefile4
-rw-r--r--malloc/malloc.c4
2 files changed, 6 insertions, 2 deletions
diff --git a/malloc/Makefile b/malloc/Makefile
index dd8a43a6c7..e6ca11c76d 100644
--- a/malloc/Makefile
+++ b/malloc/Makefile
@@ -169,7 +169,9 @@ tst-malloc-usable-tunables-ENV = GLIBC_TUNABLES=glibc.malloc.check=3
 tst-malloc-usable-static-tunables-ENV = $(tst-malloc-usable-tunables-ENV)
 
 ifeq ($(experimental-malloc),yes)
-CPPFLAGS-malloc.c += -DUSE_TCACHE
+CPPFLAGS-malloc.c += -DUSE_TCACHE=1
+else
+CPPFLAGS-malloc.c += -DUSE_TCACHE=0
 endif
 # Uncomment this for test releases.  For public releases it is too expensive.
 #CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
diff --git a/malloc/malloc.c b/malloc/malloc.c
index 91551ae1f2..d904db894e 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -2927,7 +2927,8 @@ typedef struct tcache_entry {
 /* There is one of these for each thread, which contains the
    per-thread cache (hence "tcache_perthread_struct").  Keeping
    overall size low is mildly important.  Note that COUNTS and ENTRIES
-   are redundant, this is for performance reasons.  */
+   are redundant (we could have just counted the linked list each
+   time), this is for performance reasons.  */
 typedef struct tcache_perthread_struct {
   char counts[TCACHE_MAX_BINS];
   tcache_entry *entries[TCACHE_MAX_BINS];
@@ -2955,6 +2956,7 @@ tcache_get (size_t tc_idx)
 {
   tcache_entry *e = tcache->entries[tc_idx];
   assert (tc_idx < TCACHE_MAX_BINS);
+  assert (tcache->entries[tc_idx] > 0);
   tcache->entries[tc_idx] = e->next;
   --(tcache->counts[tc_idx]);
   return (void *) e;