public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/2684] New: realloc fails to try other arenas
@ 2006-05-22 17:09 jan dot edler at indexengines dot com
  2006-05-22 17:11 ` [Bug libc/2684] " jan dot edler at indexengines dot com
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: jan dot edler at indexengines dot com @ 2006-05-22 17:09 UTC (permalink / raw)
  To: glibc-bugs

realloc does not try as hard as malloc when the current arena is full.
It is possible to have a situation where realloc will fail, but manually calling
malloc and copy will succeed.
I believe this problem does not manifest itself unless you call
mallopt(M_MMAP_MAX,0) to turn off use of mmap for large requests.

In the source file malloc.c, most calls to _int_malloc() are followed by a check
that allows switching to a new arena, but this is not true in _int_realloc().

Here is a patch, fixing the bug in public_rEALLOc() because locking
considerations make it more difficult to fix in _int_realloc():

--- glibc-20050524T1606/malloc/malloc.c 2006-05-19 13:48:27.000000000 -0400
+++ glibc-fix/malloc/malloc.c   2006-05-19 15:22:23.000000000 -0400
@@ -3507,6 +3507,17 @@
   (void)mutex_unlock(&ar_ptr->mutex);
   assert(!newp || chunk_is_mmapped(mem2chunk(newp)) ||
         ar_ptr == arena_for_chunk(mem2chunk(newp)));
+
+  if (!newp) {
+    /* Try other arenas */
+    newp = public_mALLOc(bytes);
+    if (newp) {
+      MALLOC_COPY(newp, oldmem, oldsize - 2*SIZE_SZ);
+      (void)mutex_lock(&ar_ptr->mutex);
+      _int_free(ar_ptr, oldmem);
+      (void)mutex_unlock(&ar_ptr->mutex);
+    }
+  }
   return newp;
 }
 #ifdef libc_hidden_def

-- 
           Summary: realloc fails to try other arenas
           Product: glibc
           Version: 2.3.6
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: jan dot edler at indexengines dot com
                CC: glibc-bugs at sources dot redhat dot com
  GCC host triplet: any


http://sourceware.org/bugzilla/show_bug.cgi?id=2684

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/2684] realloc fails to try other arenas
  2006-05-22 17:09 [Bug libc/2684] New: realloc fails to try other arenas jan dot edler at indexengines dot com
@ 2006-05-22 17:11 ` jan dot edler at indexengines dot com
  2006-05-25  5:03 ` jan dot edler at indexengines dot com
  2006-08-28  0:58 ` drepper at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jan dot edler at indexengines dot com @ 2006-05-22 17:11 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From jan dot edler at indexengines dot com  2006-05-22 17:11 -------
Created an attachment (id=1042)
 --> (http://sourceware.org/bugzilla/attachment.cgi?id=1042&action=view)
my patch as an attachment


-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=2684

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/2684] realloc fails to try other arenas
  2006-05-22 17:09 [Bug libc/2684] New: realloc fails to try other arenas jan dot edler at indexengines dot com
  2006-05-22 17:11 ` [Bug libc/2684] " jan dot edler at indexengines dot com
@ 2006-05-25  5:03 ` jan dot edler at indexengines dot com
  2006-08-28  0:58 ` drepper at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: jan dot edler at indexengines dot com @ 2006-05-25  5:03 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From jan dot edler at indexengines dot com  2006-05-25 05:02 -------
I have been unable so far to make a test program to demonstrate this problem
that we experience in a real app.  The problem does not arise unless some
additional arenas are created, something that I have not yet figured out how to
make happen on purpose.  Perhaps another way of looking at the problem is that
there may be a spurious failure of mmap, which seems to be the only way I can
see for additional arenas to be made, at least as configured in FC4.  Still, I
claim the bug is real and my patch corrects for it if/when such a spurious
failure occurs.

By the way, the code in question is essentially unchanged in glibc 2.4, but I'm
not running that, so I made the report vs. 2.3.6.

-- 


http://sourceware.org/bugzilla/show_bug.cgi?id=2684

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug libc/2684] realloc fails to try other arenas
  2006-05-22 17:09 [Bug libc/2684] New: realloc fails to try other arenas jan dot edler at indexengines dot com
  2006-05-22 17:11 ` [Bug libc/2684] " jan dot edler at indexengines dot com
  2006-05-25  5:03 ` jan dot edler at indexengines dot com
@ 2006-08-28  0:58 ` drepper at redhat dot com
  2 siblings, 0 replies; 4+ messages in thread
From: drepper at redhat dot com @ 2006-08-28  0:58 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From drepper at redhat dot com  2006-08-28 00:58 -------
I've taken the patch after some fixups.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


http://sourceware.org/bugzilla/show_bug.cgi?id=2684

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2006-08-28  0:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-22 17:09 [Bug libc/2684] New: realloc fails to try other arenas jan dot edler at indexengines dot com
2006-05-22 17:11 ` [Bug libc/2684] " jan dot edler at indexengines dot com
2006-05-25  5:03 ` jan dot edler at indexengines dot com
2006-08-28  0:58 ` drepper at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).