From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/526 Path: news.gmane.org!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: unneeded mremap calls in realloc Date: Wed, 16 Nov 2011 21:50:31 -0500 Message-ID: <20111117025031.GR132@brightrain.aerifal.cx> References: <20111116004536.GV24939@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1321499017 19457 80.91.229.12 (17 Nov 2011 03:03:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 17 Nov 2011 03:03:37 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-527-gllmg-musl=m.gmane.org@lists.openwall.com Thu Nov 17 04:03:31 2011 Return-path: Envelope-to: gllmg-musl@lo.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by lo.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1RQsG8-0001Fq-Qg for gllmg-musl@lo.gmane.org; Thu, 17 Nov 2011 04:03:28 +0100 Original-Received: (qmail 13407 invoked by uid 550); 17 Nov 2011 03:03:27 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 12139 invoked from network); 17 Nov 2011 03:03:12 -0000 Content-Disposition: inline In-Reply-To: <20111116004536.GV24939@port70.net> User-Agent: Mutt/1.5.21 (2010-09-15) Xref: news.gmane.org gmane.linux.lib.musl.general:526 Archived-At: On Wed, Nov 16, 2011 at 01:45:37AM +0100, Szabolcs Nagy wrote: > > as discussed on irc, in realloc there is a mremap > where newlen is pagesize adjusted but oldlen is not > so oldlen==newlen almost always fails > > run this simple test case with strace to see the issue: > > #include > int main(){ > char *p = 0; > int n; > > for (n = 0; n < 500000; n++) > p = realloc(p, n); > free(p); > return 0; > } > > the fix that significantly speeds up the above code: > (there might be better fix, eg why oldlen is not a > multiple of pagesize in the first place?) oldlen should always be a multiple of page size.. Need to check out why it's not... Rich