This is the mail archive of the glibc-cvs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

GNU C Library master sources branch dj/malloc-tcache updated. glibc-2.24-668-g6b13755


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU C Library master sources".

The branch, dj/malloc-tcache has been updated
       via  6b13755a7fd5a95d1b1911955cce6041c1a782f0 (commit)
      from  42384e6b0926fea228e81e00cbe98a43340f966a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://sourceware.org/git/gitweb.cgi?p=glibc.git;a=commitdiff;h=6b13755a7fd5a95d1b1911955cce6041c1a782f0

commit 6b13755a7fd5a95d1b1911955cce6041c1a782f0
Author: DJ Delorie <dj@delorie.com>
Date:   Thu Jan 26 13:02:17 2017 -0500

    Formatting changes; remove list of caches
    
    Minor formatting changes to comments and indentation.
    
    Remove code to keep a list of tcaches (was used during debugging
    to enumerate all cache data) but keep the destructor hook as
    we might need to consider cleaning up after exiting threads
    at some point in the future.

diff --git a/malloc/malloc.c b/malloc/malloc.c
index 1699e5b..3da9f94 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -298,30 +298,30 @@ __malloc_assert (const char *assertion, const char *file, unsigned int line,
 #endif
 
 #ifndef USE_TCACHE
-#define USE_TCACHE 0
+# define USE_TCACHE 0
 #endif
 #if USE_TCACHE
-/* we want 64 entries */
-#define MAX_TCACHE_SIZE		(MALLOC_ALIGNMENT * 63)
-#define TCACHE_IDX		((MAX_TCACHE_SIZE / MALLOC_ALIGNMENT) + 1)
-#define size2tidx_(bytes)	(((bytes) + MALLOC_ALIGNMENT - 1) / MALLOC_ALIGNMENT)
+/* We want 64 entries.  This is an arbitrary limit, which tunables can reduce.  */
+# define MAX_TCACHE_SIZE	(MALLOC_ALIGNMENT * 63)
+# define TCACHE_IDX		((MAX_TCACHE_SIZE / MALLOC_ALIGNMENT) + 1)
+# define size2tidx_(bytes)	(((bytes) + MALLOC_ALIGNMENT - 1) / MALLOC_ALIGNMENT)
 
-#define tidx2csize(idx)		((idx)*MALLOC_ALIGNMENT + SIZE_SZ)
-#define tidx2usize(idx)		((idx)*MALLOC_ALIGNMENT)
+# define tidx2csize(idx)	((idx)*MALLOC_ALIGNMENT + SIZE_SZ)
+# define tidx2usize(idx)	((idx)*MALLOC_ALIGNMENT)
 
 /* When "x" is a user-provided size.  */
-#define usize2tidx(x) size2tidx_(x)
+# define usize2tidx(x) size2tidx_(x)
 /* When "x" is from chunksize().  */
-#define csize2tidx(x) size2tidx_((x)-SIZE_SZ)
+# define csize2tidx(x) size2tidx_((x)-SIZE_SZ)
 
 /* Rounds up, so...
    idx 0   bytes 0
    idx 1   bytes 1..8
    idx 2   bytes 9..16
-   etc
-*/
+   etc.  */
 
-#define TCACHE_FILL_COUNT 7
+/* This is another arbitrary limit, which tunables can change.  */
+# define TCACHE_FILL_COUNT 7
 #endif
 
 
@@ -1798,9 +1798,9 @@ static struct malloc_par mp_ =
 
 /*  Non public mallopt parameters.  */
 #if USE_TCACHE
-#define M_TCACHE_COUNT  -9
-#define M_TCACHE_MAX  -10
-#define M_TCACHE_UNSORTED_LIMIT  -11
+# define M_TCACHE_COUNT  -9
+# define M_TCACHE_MAX  -10
+# define M_TCACHE_UNSORTED_LIMIT  -11
 #endif
 
 /* Maximum size of memory handled in fastbins.  */
@@ -2932,33 +2932,27 @@ typedef struct TCacheEntry {
   struct TCacheEntry *next;
 } TCacheEntry;
 
+/* There is one of these for each thread, which contains the
+   per-thread cache (hence "TCache").  Keeping overall size low is
+   mildly important.  INITTED makes sure we don't use the cache when
+   we're shutting down the thread.  Note that COUNTS and ENTRIES are
+   redundant, this is for performance reasons.  */
 typedef struct TCache {
-  struct TCache *prev, *next;
-  char initted; /* 0 = uninitted, 1 = normal, anything else = shutting down */
+  /* 0 = uninitted, 1 = normal, anything else = shutting down */
+  char initted;
   char counts[TCACHE_IDX];
   TCacheEntry *entries[TCACHE_IDX];
 } TCache;
 
-static TCache *tcache_list = NULL;
-__libc_lock_define_initialized (static, tcache_mutex);
-
 static __thread TCache tcache = {0,0,0,{0},{0}};
 
 static void __attribute__ ((section ("__libc_thread_freeres_fn")))
 tcache_thread_freeres (void)
 {
+  /* We should flush the cache out to the main arena also, but most of
+     the time we're just exiting the process completely.  */
   if (tcache.initted == 1)
-    {
-      __libc_lock_lock (tcache_mutex);
-      tcache.initted = 2;
-      if (tcache.next)
-	tcache.next->prev = tcache.prev;
-      if (tcache.prev)
-	tcache.prev->next = tcache.next;
-      else
-	tcache_list = tcache.next;
-      __libc_lock_unlock (tcache_mutex);
-    }
+    tcache.initted = 2;
 }
 text_set_element (__libc_thread_subfreeres, tcache_thread_freeres);
 
@@ -2979,17 +2973,6 @@ __libc_malloc (size_t bytes)
   size_t tbytes = request2size(bytes);
   size_t tc_idx = csize2tidx (tbytes);
 
-  if (tcache.initted == 0)
-    {
-      tcache.initted = 1;
-      __libc_lock_lock (tcache_mutex);
-      tcache.next = tcache_list;
-      if (tcache.next)
-	tcache.next->prev = &tcache;
-      tcache_list = &tcache;
-      __libc_lock_unlock (tcache_mutex);
-    }
-
   if (tc_idx < mp_.tcache_max
       && tc_idx < TCACHE_IDX /* to appease gcc */
       && tcache.entries[tc_idx] != NULL
@@ -3509,7 +3492,7 @@ _int_malloc (mstate av, size_t bytes)
             }
           check_remalloced_chunk (av, victim, nb);
 #if USE_TCACHE
-	  /* While we're here, if we see other chunk of the same size,
+	  /* While we're here, if we see other chunks of the same size,
 	     stash them in the tcache.  */
 	  size_t tc_idx = csize2tidx (nb);
 	  if (tc_idx < mp_.tcache_max)
@@ -3579,7 +3562,7 @@ _int_malloc (mstate av, size_t bytes)
 		set_non_main_arena (victim);
               check_malloced_chunk (av, victim, nb);
 #if USE_TCACHE
-	  /* While we're here, if we see other chunk of the same size,
+	  /* While we're here, if we see other chunks of the same size,
 	     stash them in the tcache.  */
 	  size_t tc_idx = csize2tidx (nb);
 	  if (tc_idx < mp_.tcache_max)

-----------------------------------------------------------------------

Summary of changes:
 malloc/malloc.c |   71 +++++++++++++++++++++----------------------------------
 1 files changed, 27 insertions(+), 44 deletions(-)


hooks/post-receive
-- 
GNU C Library master sources


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]