olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1276753-0.patch

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