develooper Front page | perl.perl5.porters | Postings from March 2007

Re: Useless use of realloc

Thread Previous
From:
Nicholas Clark
Date:
March 21, 2007 11:02
Subject:
Re: Useless use of realloc
Message ID:
20070321180155.GY5748@plum.flirble.org
On Wed, Mar 21, 2007 at 06:08:44PM +0100, Rafael Garcia-Suarez wrote:
> Oh look :
> 
> $ strace -etrace=mremap perl -e '$s.="x"for 1..300_000' 2>&1 | head -1
> mremap(0xb7c3b000, 262144, 262144, MREMAP_MAYMOVE) = 0xb7c3b000

I can replicate this on Linux

> This is on linux. The mremap syscall is used by the glibc to implement
> realloc under linux. But here, the old size and the new size of the
> memory blocks are the same, which means that at some point we probably
> called realloc() without needing to.

We're not. After figuring out PERL_MEM_LOG* I can't find a call to realloc
that looks repeated, and on FreeBSD I see:

 74446 perl     CALL  break(0x8172000)
 74446 perl     RET   break 0
 74446 perl     CALL  break(0x8173000)
 74446 perl     RET   break 0
 74446 perl     CALL  break(0x8175000)
 74446 perl     RET   break 0
 74446 perl     CALL  break(0x8178000)
 74446 perl     RET   break 0

...

 74446 perl     CALL  break(0x81c8000)
 74446 perl     RET   break 0
 74446 perl     CALL  break(0x8210000)
 74446 perl     RET   break 0
 74446 perl     CALL  break(0x81ca000)
 74446 perl     RET   break 0
 74446 perl     CALL  break(0x8214000)
 74446 perl     RET   break 0


(I sandwiched the for loop between 2 warns to see what is going on)

So I infer that it's some sort of glibc rounding up to 262144 bytes, and
a glibc inability to avoid doing needless work.

Nicholas Clark

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About