public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libc/5071] New: realloc(): do not remap() if same number of pages
@ 2007-09-26  9:42 tomash dot brechko at gmail dot com
  2007-10-02  3:52 ` [Bug libc/5071] " drepper at redhat dot com
  0 siblings, 1 reply; 2+ messages in thread
From: tomash dot brechko at gmail dot com @ 2007-09-26  9:42 UTC (permalink / raw)
  To: glibc-bugs

strace of the following program on Linux x86 (4096 bytes/page) shows that there
are lots of redundant calls to mremap() (old size and new size are equal).  The
bug is present in glibc up to and including 2.6.1 (bug report Version field
doesn't have 2.6).

#include <stdlib.h>

int
main()
{
  const size_t size = 256 * 1024 + 4050;
  void *p;
  int i;

  p = malloc(size);
  for (i = 0; i < 100; ++i)
    p = realloc(p, size + i);

  return 0;
}


The following patch fixes the problem (comment line is copied from the similar
check in _int_realloc()):

--- malloc/malloc.c-orig        2007-09-26 13:28:36.000000000 +0400
+++ malloc/malloc.c     2007-09-26 12:57:41.000000000 +0400
@@ -3503,6 +3503,10 @@ mremap_chunk(p, new_size) mchunkptr p; s
   /* Note the extra SIZE_SZ overhead as in mmap_chunk(). */
   new_size = (new_size + offset + SIZE_SZ + page_mask) & ~page_mask;

+  /* don't need to remap if still within same page */
+  if (size + offset == new_size)
+    return p;
+
   cp = (char *)mremap((char *)p - offset, size + offset, new_size,
                       MREMAP_MAYMOVE);

-- 
           Summary: realloc(): do not remap() if same number of pages
           Product: glibc
           Version: 2.4
            Status: NEW
          Severity: minor
          Priority: P3
         Component: libc
        AssignedTo: drepper at redhat dot com
        ReportedBy: tomash dot brechko at gmail dot com
                CC: glibc-bugs at sources dot redhat dot com
 GCC build triplet: i686-redhat-linux-gnu
  GCC host triplet: i686-redhat-linux-gnu
GCC target triplet: i686-redhat-linux-gnu


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

------- 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] 2+ messages in thread

* [Bug libc/5071] realloc(): do not remap() if same number of pages
  2007-09-26  9:42 [Bug libc/5071] New: realloc(): do not remap() if same number of pages tomash dot brechko at gmail dot com
@ 2007-10-02  3:52 ` drepper at redhat dot com
  0 siblings, 0 replies; 2+ messages in thread
From: drepper at redhat dot com @ 2007-10-02  3:52 UTC (permalink / raw)
  To: glibc-bugs


------- Additional Comments From drepper at redhat dot com  2007-10-02 03:52 -------
Applied to cvs.

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


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

------- 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] 2+ messages in thread

end of thread, other threads:[~2007-10-02  3:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-26  9:42 [Bug libc/5071] New: realloc(): do not remap() if same number of pages tomash dot brechko at gmail dot com
2007-10-02  3:52 ` [Bug libc/5071] " 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).