Date: Thu, 14 Mar 2002 07:40:04 +0100 From: Poul-Henning Kamp <phk@critter.freebsd.dk> To: David Greenman <dg@root.com> Cc: John Indra <maverick@office.naver.co.id>, freebsd-current@FreeBSD.ORG Subject: Re: malloc() and the stock Perl in -CURRENT (and -STABLE) Message-ID: <41161.1016088004@critter.freebsd.dk> In-Reply-To: Your message of "Wed, 13 Mar 2002 22:25:18 PST." <20020313222518.J27616@nexus.root.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <20020313222518.J27616@nexus.root.com>, David Greenman writes:
>>The above perl program results in a loop more or less like:
>>
>> n = 2
>> for (i = 0; i < 1000000; i++)
>> realloc(n++);
>>
>>Now, if you read _any_ malloc(3) man page, they will tell you that there
>>is no way it can be guaranteed that this does not result in a lot of
>>copying.
>
> Um, except that copying isn't what is causing the problem. The performance
>problem is apparantly caused by tens of thousands of page faults per second as
>the memory is freed and immediately reallocated again from the kernel. Doesn't
>phkmalloc keep a small pool of allocations around to avoid problems like
>this?
Yes it does, but it doesn't help here. Basically what happens is
that relloc() is called on to extend a string of one megabyte by
another page, so it allocates 1M+1p and copies the contents over.
Now, in this very particular cornercase, we might be able to optimize
for just being able to allocate the next page, but in all real-world
scenarioes I've seen, real usage is more like:
long loop {
realloc(n++);
do some other stuff involving malloc/free/realloc
}
which negates that optimization.
But if somebody wants to try to code this optimization, I'll be more
than happy to review the result. I just don't expect it to do much
in "real-life" as opposed to "silly benchmark" situations.
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?41161.1016088004>
