arrfab / rpms / glibc

Forked from rpms/glibc 4 years ago
Clone

Blame SOURCES/glibc-rh1276753-0.patch

147e83
commit 5782a80f9f8ca86899b30161166f044b0b6b8590
147e83
Author: Ondřej Bílka <neleai@seznam.cz>
147e83
Date:   Tue Dec 10 17:56:59 2013 +0100
147e83
147e83
    Drop PER_THREAD conditionals from malloc.
147e83
147e83
Index: glibc-2.17-c758a686/malloc/Makefile
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/malloc/Makefile
147e83
+++ glibc-2.17-c758a686/malloc/Makefile
147e83
@@ -121,7 +121,6 @@ endif
147e83
 tst-mcheck-ENV = MALLOC_CHECK_=3
147e83
 tst-malloc-usable-ENV = MALLOC_CHECK_=3
147e83
 
147e83
-CPPFLAGS-malloc.c += -DPER_THREAD
147e83
 # Uncomment this for test releases.  For public releases it is too expensive.
147e83
 #CPPFLAGS-malloc.o += -DMALLOC_DEBUG=1
147e83
 
147e83
Index: glibc-2.17-c758a686/malloc/arena.c
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/malloc/arena.c
147e83
+++ glibc-2.17-c758a686/malloc/arena.c
147e83
@@ -78,10 +78,8 @@ extern int sanity_check_heap_info_alignm
147e83
 
147e83
 static tsd_key_t arena_key;
147e83
 static mutex_t list_lock = MUTEX_INITIALIZER;
147e83
-#ifdef PER_THREAD
147e83
 static size_t narenas = 1;
147e83
 static mstate free_list;
147e83
-#endif
147e83
 
147e83
 #if THREAD_STATS
147e83
 static int stat_n_heaps;
147e83
@@ -117,21 +115,12 @@ int __malloc_initialized = -1;
147e83
   ptr = (mstate)tsd_getspecific(arena_key, vptr); \
147e83
 } while(0)
147e83
 
147e83
-#ifdef PER_THREAD
147e83
 # define arena_lock(ptr, size) do { \
147e83
   if(ptr && !arena_is_corrupt (ptr)) \
147e83
     (void)mutex_lock(&ptr->mutex); \
147e83
   else \
147e83
     ptr = arena_get2(ptr, (size), NULL); \
147e83
 } while(0)
147e83
-#else
147e83
-# define arena_lock(ptr, size) do { \
147e83
-  if(ptr && !mutex_trylock(&ptr->mutex)) { \
147e83
-    THREAD_STAT(++(ptr->stat_lock_direct)); \
147e83
-  } else \
147e83
-    ptr = arena_get2(ptr, (size), NULL); \
147e83
-} while(0)
147e83
-#endif
147e83
 
147e83
 /* find the heap and corresponding arena for a given ptr */
147e83
 
147e83
@@ -297,17 +286,13 @@ ptmalloc_unlock_all2 (void)
147e83
   tsd_setspecific(arena_key, save_arena);
147e83
   __malloc_hook = save_malloc_hook;
147e83
   __free_hook = save_free_hook;
147e83
-#ifdef PER_THREAD
147e83
   free_list = NULL;
147e83
-#endif
147e83
   for(ar_ptr = &main_arena;;) {
147e83
     mutex_init(&ar_ptr->mutex);
147e83
-#ifdef PER_THREAD
147e83
     if (ar_ptr != save_arena) {
147e83
       ar_ptr->next_free = free_list;
147e83
       free_list = ar_ptr;
147e83
     }
147e83
-#endif
147e83
     ar_ptr = ar_ptr->next;
147e83
     if(ar_ptr == &main_arena) break;
147e83
   }
147e83
@@ -428,13 +413,10 @@ ptmalloc_init (void)
147e83
 		{
147e83
 		  if (memcmp (envline, "MMAP_MAX_", 9) == 0)
147e83
 		    __libc_mallopt(M_MMAP_MAX, atoi(&envline[10]));
147e83
-#ifdef PER_THREAD
147e83
 		  else if (memcmp (envline, "ARENA_MAX", 9) == 0)
147e83
 		    __libc_mallopt(M_ARENA_MAX, atoi(&envline[10]));
147e83
-#endif
147e83
 		}
147e83
 	      break;
147e83
-#ifdef PER_THREAD
147e83
 	    case 10:
147e83
 	      if (! __builtin_expect (__libc_enable_secure, 0))
147e83
 		{
147e83
@@ -442,7 +424,6 @@ ptmalloc_init (void)
147e83
 		    __libc_mallopt(M_ARENA_TEST, atoi(&envline[11]));
147e83
 		}
147e83
 	      break;
147e83
-#endif
147e83
 	    case 15:
147e83
 	      if (! __builtin_expect (__libc_enable_secure, 0))
147e83
 		{
147e83
@@ -750,18 +731,14 @@ _int_new_arena(size_t size)
147e83
   mutex_init(&a->mutex);
147e83
   (void)mutex_lock(&a->mutex);
147e83
 
147e83
-#ifdef PER_THREAD
147e83
   (void)mutex_lock(&list_lock);
147e83
-#endif
147e83
 
147e83
   /* Add the new arena to the global list.  */
147e83
   a->next = main_arena.next;
147e83
   atomic_write_barrier ();
147e83
   main_arena.next = a;
147e83
 
147e83
-#ifdef PER_THREAD
147e83
   (void)mutex_unlock(&list_lock);
147e83
-#endif
147e83
 
147e83
   THREAD_STAT(++(a->stat_lock_loop));
147e83
 
147e83
@@ -769,7 +746,6 @@ _int_new_arena(size_t size)
147e83
 }
147e83
 
147e83
 
147e83
-#ifdef PER_THREAD
147e83
 static mstate
147e83
 get_free_list (void)
147e83
 {
147e83
@@ -846,7 +822,6 @@ reused_arena (mstate avoid_arena)
147e83
 
147e83
   return result;
147e83
 }
147e83
-#endif
147e83
 
147e83
 static mstate
147e83
 internal_function
147e83
@@ -854,7 +829,6 @@ arena_get2(mstate a_tsd, size_t size, ms
147e83
 {
147e83
   mstate a;
147e83
 
147e83
-#ifdef PER_THREAD
147e83
   static size_t narenas_limit;
147e83
 
147e83
   a = get_free_list ();
147e83
@@ -897,54 +871,6 @@ arena_get2(mstate a_tsd, size_t size, ms
147e83
       else
147e83
 	a = reused_arena (avoid_arena);
147e83
     }
147e83
-#else
147e83
-  if(!a_tsd)
147e83
-    a = a_tsd = &main_arena;
147e83
-  else {
147e83
-    a = a_tsd->next;
147e83
-    if(!a) {
147e83
-      /* This can only happen while initializing the new arena. */
147e83
-      (void)mutex_lock(&main_arena.mutex);
147e83
-      THREAD_STAT(++(main_arena.stat_lock_wait));
147e83
-      return &main_arena;
147e83
-    }
147e83
-  }
147e83
-
147e83
-  /* Check the global, circularly linked list for available arenas. */
147e83
-  bool retried = false;
147e83
- repeat:
147e83
-  do {
147e83
-    if(!mutex_trylock(&a->mutex)) {
147e83
-      if (retried)
147e83
-	(void)mutex_unlock(&list_lock);
147e83
-      THREAD_STAT(++(a->stat_lock_loop));
147e83
-      LIBC_PROBE (memory_arena_reuse, 2, a, a_tsd);
147e83
-      tsd_setspecific(arena_key, (void *)a);
147e83
-      return a;
147e83
-    }
147e83
-    a = a->next;
147e83
-  } while(a != a_tsd);
147e83
-
147e83
-  /* If not even the list_lock can be obtained, try again.  This can
147e83
-     happen during `atfork', or for example on systems where thread
147e83
-     creation makes it temporarily impossible to obtain _any_
147e83
-     locks. */
147e83
-  if(!retried && mutex_trylock(&list_lock)) {
147e83
-    /* We will block to not run in a busy loop.  */
147e83
-    LIBC_PROBE (memory_arena_reuse_wait, 3, &list_lock, NULL, a_tsd);
147e83
-    (void)mutex_lock(&list_lock);
147e83
-
147e83
-    /* Since we blocked there might be an arena available now.  */
147e83
-    retried = true;
147e83
-    a = a_tsd;
147e83
-    goto repeat;
147e83
-  }
147e83
-
147e83
-  /* Nothing immediately available, so generate a new arena.  */
147e83
-  a = _int_new_arena(size);
147e83
-  (void)mutex_unlock(&list_lock);
147e83
-#endif
147e83
-
147e83
   return a;
147e83
 }
147e83
 
147e83
@@ -970,7 +896,6 @@ arena_get_retry (mstate ar_ptr, size_t b
147e83
   return ar_ptr;
147e83
 }
147e83
 
147e83
-#ifdef PER_THREAD
147e83
 static void __attribute__ ((section ("__libc_thread_freeres_fn")))
147e83
 arena_thread_freeres (void)
147e83
 {
147e83
@@ -987,7 +912,6 @@ arena_thread_freeres (void)
147e83
     }
147e83
 }
147e83
 text_set_element (__libc_thread_subfreeres, arena_thread_freeres);
147e83
-#endif
147e83
 
147e83
 /*
147e83
  * Local variables:
147e83
Index: glibc-2.17-c758a686/malloc/hooks.c
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/malloc/hooks.c
147e83
+++ glibc-2.17-c758a686/malloc/hooks.c
147e83
@@ -464,11 +464,9 @@ __malloc_get_state(void)
147e83
   ms->max_mmapped_mem = mp_.max_mmapped_mem;
147e83
   ms->using_malloc_checking = using_malloc_checking;
147e83
   ms->max_fast = get_max_fast();
147e83
-#ifdef PER_THREAD
147e83
   ms->arena_test = mp_.arena_test;
147e83
   ms->arena_max = mp_.arena_max;
147e83
   ms->narenas = narenas;
147e83
-#endif
147e83
   (void)mutex_unlock(&main_arena.mutex);
147e83
   return (void*)ms;
147e83
 }
147e83
@@ -565,11 +563,9 @@ __malloc_set_state(void* msptr)
147e83
     }
147e83
   }
147e83
   if (ms->version >= 4) {
147e83
-#ifdef PER_THREAD
147e83
     mp_.arena_test = ms->arena_test;
147e83
     mp_.arena_max = ms->arena_max;
147e83
     narenas = ms->narenas;
147e83
-#endif
147e83
   }
147e83
   check_malloc_state(&main_arena);
147e83
 
147e83
Index: glibc-2.17-c758a686/malloc/malloc.c
147e83
===================================================================
147e83
--- glibc-2.17-c758a686.orig/malloc/malloc.c
147e83
+++ glibc-2.17-c758a686/malloc/malloc.c
147e83
@@ -1727,10 +1727,8 @@ struct malloc_state {
147e83
   /* Linked list */
147e83
   struct malloc_state *next;
147e83
 
147e83
-#ifdef PER_THREAD
147e83
   /* Linked list for free arenas.  */
147e83
   struct malloc_state *next_free;
147e83
-#endif
147e83
 
147e83
   /* Memory allocated from the system in this arena.  */
147e83
   INTERNAL_SIZE_T system_mem;
147e83
@@ -1742,10 +1740,8 @@ struct malloc_par {
147e83
   unsigned long    trim_threshold;
147e83
   INTERNAL_SIZE_T  top_pad;
147e83
   INTERNAL_SIZE_T  mmap_threshold;
147e83
-#ifdef PER_THREAD
147e83
   INTERNAL_SIZE_T  arena_test;
147e83
   INTERNAL_SIZE_T  arena_max;
147e83
-#endif
147e83
 
147e83
   /* Memory map support */
147e83
   int              n_mmaps;
147e83
@@ -1787,18 +1783,14 @@ static struct malloc_par mp_ =
147e83
     .n_mmaps_max    = DEFAULT_MMAP_MAX,
147e83
     .mmap_threshold = DEFAULT_MMAP_THRESHOLD,
147e83
     .trim_threshold = DEFAULT_TRIM_THRESHOLD,
147e83
-#ifdef PER_THREAD
147e83
 # define NARENAS_FROM_NCORES(n) ((n) * (sizeof(long) == 4 ? 2 : 8))
147e83
     .arena_test     = NARENAS_FROM_NCORES (1)
147e83
-#endif
147e83
   };
147e83
 
147e83
 
147e83
-#ifdef PER_THREAD
147e83
 /*  Non public mallopt parameters.  */
147e83
 #define M_ARENA_TEST -7
147e83
 #define M_ARENA_MAX  -8
147e83
-#endif
147e83
 
147e83
 
147e83
 /* Maximum size of memory handled in fastbins.  */
147e83
@@ -3008,11 +3000,6 @@ __libc_realloc(void* oldmem, size_t byte
147e83
   (void)mutex_lock(&ar_ptr->mutex);
147e83
 #endif
147e83
 
147e83
-#if !defined PER_THREAD
147e83
-  LIBC_PROBE (memory_arena_reuse_realloc, 1, ar_ptr);
147e83
-  /* As in malloc(), remember this arena for the next allocation. */
147e83
-  tsd_setspecific(arena_key, (void *)ar_ptr);
147e83
-#endif
147e83
 
147e83
   newp = _int_realloc(ar_ptr, oldp, oldsize, nb);
147e83
 
147e83
@@ -4823,7 +4810,6 @@ int __libc_mallopt(int param_number, int
147e83
     perturb_byte = value;
147e83
     break;
147e83
 
147e83
-#ifdef PER_THREAD
147e83
   case M_ARENA_TEST:
147e83
     if (value > 0)
147e83
       {
147e83
@@ -4839,7 +4825,6 @@ int __libc_mallopt(int param_number, int
147e83
 	mp_.arena_max = value;
147e83
       }
147e83
     break;
147e83
-#endif
147e83
   }
147e83
   (void)mutex_unlock(&av->mutex);
147e83
   return res;