From owner-freebsd-current Wed Mar 13 22:52:55 2002 Delivered-To: freebsd-current@freebsd.org Received: from harrier.prod.itd.earthlink.net (harrier.mail.pas.earthlink.net [207.217.120.12]) by hub.freebsd.org (Postfix) with ESMTP id 1688837B405 for ; Wed, 13 Mar 2002 22:52:53 -0800 (PST) Received: from pool0432.cvx21-bradley.dialup.earthlink.net ([209.179.193.177] helo=mindspring.com) by harrier.prod.itd.earthlink.net with esmtp (Exim 3.33 #1) id 16lP5F-0007gK-00; Wed, 13 Mar 2002 22:51:29 -0800 Message-ID: <3C904853.B89968B4@mindspring.com> Date: Wed, 13 Mar 2002 22:50:59 -0800 From: Terry Lambert X-Mailer: Mozilla 4.7 [en]C-CCK-MCD {Sony} (Win98; U) X-Accept-Language: en MIME-Version: 1.0 To: David Greenman Cc: Poul-Henning Kamp , John Indra , freebsd-current@FreeBSD.ORG Subject: Re: malloc() and the stock Perl in -CURRENT (and -STABLE) References: <20020314104525.B8244@office.naver.co.id> <40628.1016085846@critter.freebsd.dk> <20020313222518.J27616@nexus.root.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG David Greenman wrote: > >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? It's the other order, since it has to copy the prior contents... the new memory is malloc'ed, and the old is freed. Poul is right that a remmap() would be useful, in order to move only the mappings, leaving the pages intact, to grow the mmap'ed region and relocate it at the same time. Another thing that's common in most malloc implementations that are less picky than phkmalloc is growth by power-of-2 on each allocation, causing the allocated region to double, after the first realloc, on each grow. The best performance that this will get, though, is the same performance that the per process open file table grow gets (i.e. pretty bad). The remmap is a better idea. It might be wedged into the exiting mmap for a malloc of the same object with a larger size (e.g. remapping MAP_ANON memory with a larger size and a non-zero address implies a zero address, same pages, larger allocation, since mapping over an existing mapping makes no sense). -- Terry To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message