- When retrying after main arena failure, always retry in a

different arena. (#789238)
This commit is contained in:
Jeff Law 2012-04-02 21:24:18 -06:00
parent ca8adba640
commit c30958093b
2 changed files with 120 additions and 2 deletions

111
glibc-rh789238-2.patch Normal file
View File

@ -0,0 +1,111 @@
diff -rup c/malloc/arena.c d/malloc/arena.c
--- c/malloc/arena.c 2012-04-02 21:21:08.842818529 -0600
+++ d/malloc/arena.c 2012-04-02 21:22:25.943306724 -0600
@@ -121,14 +121,14 @@ int __malloc_initialized = -1;
if(ptr) \
(void)mutex_lock(&ptr->mutex); \
else \
- ptr = arena_get2(ptr, (size)); \
+ ptr = arena_get2(ptr, (size), false); \
} while(0)
#else
# define arena_lock(ptr, size) do { \
if(ptr && !mutex_trylock(&ptr->mutex)) { \
THREAD_STAT(++(ptr->stat_lock_direct)); \
} else \
- ptr = arena_get2(ptr, (size)); \
+ ptr = arena_get2(ptr, (size), false); \
} while(0)
#endif
@@ -782,7 +782,7 @@ get_free_list (void)
static mstate
-reused_arena (void)
+reused_arena (bool retrying)
{
mstate result;
static mstate next_to_use;
@@ -799,6 +799,15 @@ reused_arena (void)
}
while (result != next_to_use);
+ /* If we are retrying due to a failure to allocate in the main
+ arena, don't wait for the main arena to become available, select
+ another.
+
+ To really fix this right we would have to try the allocation
+ in every other arena, but that seems like severe overkill. */
+ if (retrying && result == &main_arena)
+ result = result->next;
+
/* No arena available. Wait for the next in line. */
(void)mutex_lock(&result->mutex);
@@ -813,7 +822,7 @@ reused_arena (void)
static mstate
internal_function
-arena_get2(mstate a_tsd, size_t size)
+arena_get2(mstate a_tsd, size_t size, bool retrying)
{
mstate a;
@@ -858,7 +867,7 @@ arena_get2(mstate a_tsd, size_t size)
catomic_decrement (&narenas);
}
else
- a = reused_arena ();
+ a = reused_arena (retrying);
}
#else
if(!a_tsd)
diff -rup c/malloc/malloc.c d/malloc/malloc.c
--- c/malloc/malloc.c 2012-04-02 21:21:08.984817776 -0600
+++ d/malloc/malloc.c 2012-04-02 21:21:39.533655779 -0600
@@ -2938,7 +2938,7 @@ public_mALLOc(size_t bytes)
/* ... or sbrk() has failed and there is still a chance to mmap() */
mstate prev = ar_ptr->next ? ar_ptr : 0;
(void)mutex_unlock(&ar_ptr->mutex);
- ar_ptr = arena_get2(prev, bytes);
+ ar_ptr = arena_get2(prev, bytes, true);
if(ar_ptr) {
victim = _int_malloc(ar_ptr, bytes);
(void)mutex_unlock(&ar_ptr->mutex);
@@ -3117,7 +3117,7 @@ public_mEMALIGn(size_t alignment, size_t
/* ... or sbrk() has failed and there is still a chance to mmap() */
mstate prev = ar_ptr->next ? ar_ptr : 0;
(void)mutex_unlock(&ar_ptr->mutex);
- ar_ptr = arena_get2(prev, bytes);
+ ar_ptr = arena_get2(prev, bytes, true);
if(ar_ptr) {
p = _int_memalign(ar_ptr, alignment, bytes);
(void)mutex_unlock(&ar_ptr->mutex);
@@ -3164,7 +3164,7 @@ public_vALLOc(size_t bytes)
/* ... or sbrk() has failed and there is still a chance to mmap() */
mstate prev = ar_ptr->next ? ar_ptr : 0;
(void)mutex_unlock(&ar_ptr->mutex);
- ar_ptr = arena_get2(prev, bytes);
+ ar_ptr = arena_get2(prev, bytes, true);
if(ar_ptr) {
p = _int_memalign(ar_ptr, pagesz, bytes);
(void)mutex_unlock(&ar_ptr->mutex);
@@ -3211,7 +3211,7 @@ public_pVALLOc(size_t bytes)
/* ... or sbrk() has failed and there is still a chance to mmap() */
mstate prev = ar_ptr->next ? ar_ptr : 0;
(void)mutex_unlock(&ar_ptr->mutex);
- ar_ptr = arena_get2(prev, bytes + 2*pagesz + MINSIZE);
+ ar_ptr = arena_get2(prev, bytes + 2*pagesz + MINSIZE, true);
if(ar_ptr) {
p = _int_memalign(ar_ptr, pagesz, rounded_bytes);
(void)mutex_unlock(&ar_ptr->mutex);
@@ -3298,7 +3298,7 @@ public_cALLOc(size_t n, size_t elem_size
/* ... or sbrk() has failed and there is still a chance to mmap() */
mstate prev = av->next ? av : 0;
(void)mutex_unlock(&av->mutex);
- av = arena_get2(prev, sz);
+ av = arena_get2(prev, sz, true);
if(av) {
mem = _int_malloc(av, sz);
(void)mutex_unlock(&av->mutex);

View File

@ -28,7 +28,7 @@
Summary: The GNU libc libraries Summary: The GNU libc libraries
Name: glibc Name: glibc
Version: %{glibcversion} Version: %{glibcversion}
Release: 30%{?dist} Release: 31%{?dist}
# GPLv2+ is used in a bunch of programs, LGPLv2+ is used for libraries. # GPLv2+ is used in a bunch of programs, LGPLv2+ is used for libraries.
# Things that are linked directly into dynamically linked programs # Things that are linked directly into dynamically linked programs
# and shared libraries (e.g. crt files, lib*_nonshared.a) have an additional # and shared libraries (e.g. crt files, lib*_nonshared.a) have an additional
@ -96,7 +96,7 @@ Patch30: %{name}-rh791161.patch
Patch31 : %{name}-rh697149.patch Patch31 : %{name}-rh697149.patch
# Submitted upstream BZ 9954 # Submitted upstream BZ 9954
Patch32 : %{name}-rh739743.patch Patch32 : %{name}-rh739743.patch
# Discussion started upstream, patch needs to be submitted # Submitted upstream, BZ13939
Patch33 : %{name}-rh789238.patch Patch33 : %{name}-rh789238.patch
# From upstream # From upstream
Patch34 : %{name}-rh794797.patch Patch34 : %{name}-rh794797.patch
@ -127,6 +127,8 @@ Patch46 : %{name}-rh806403.patch
Patch47 : %{name}-rh806070.patch Patch47 : %{name}-rh806070.patch
# Submitted upstream # Submitted upstream
Patch48 : %{name}-rh804792.patch Patch48 : %{name}-rh804792.patch
# Submitted upstream (BZ 13939)
Patch49 : %{name}-rh789238-2.patch
Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) Buildroot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
@ -394,6 +396,7 @@ rm -rf %{glibcportsdir}
%patch46 -p1 %patch46 -p1
%patch47 -p1 %patch47 -p1
%patch48 -p1 %patch48 -p1
%patch49 -p1
# A lot of programs still misuse memcpy when they have to use # A lot of programs still misuse memcpy when they have to use
# memmove. The memcpy implementation below is not tolerant at # memmove. The memcpy implementation below is not tolerant at
@ -1246,6 +1249,10 @@ rm -f *.filelist*
%endif %endif
%changelog %changelog
* Mon Apr 2 2012 Jeff Law <law@redhat.com> - 2.15-31
- When retrying after main arena failure, always retry in a
different arena. (#789238)
* Tue Mar 27 2012 Jeff Law <law@redhat.com> - 2.15-30 * Tue Mar 27 2012 Jeff Law <law@redhat.com> - 2.15-30
- Avoid unbound alloca usage in *-crypt routines (#804792) - Avoid unbound alloca usage in *-crypt routines (#804792)
- Fix data race in nscd (#806070) - Fix data race in nscd (#806070)