public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "tomash dot brechko at gmail dot com" <sourceware-bugzilla@sourceware.org> To: glibc-bugs@sources.redhat.com Subject: [Bug libc/5071] New: realloc(): do not remap() if same number of pages Date: Wed, 26 Sep 2007 09:42:00 -0000 [thread overview] Message-ID: <20070926094219.5071.tomash.brechko@gmail.com> (raw) 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.
next reply other threads:[~2007-09-26 9:42 UTC|newest] Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top 2007-09-26 9:42 tomash dot brechko at gmail dot com [this message] 2007-10-02 3:52 ` [Bug libc/5071] " drepper at redhat dot com
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20070926094219.5071.tomash.brechko@gmail.com \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sources.redhat.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).