From owner-freebsd-current@FreeBSD.ORG Tue Jan 6 08:19:33 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B32C016A4CE; Tue, 6 Jan 2004 08:19:33 -0800 (PST) Received: from mailout07.sul.t-online.com (mailout07.sul.t-online.com [194.25.134.83]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9245A43D1F; Tue, 6 Jan 2004 08:19:24 -0800 (PST) (envelope-from Alexander@Leidinger.net) Received: from fwd03.aul.t-online.de by mailout07.sul.t-online.com with smtp id 1Adttt-00075z-07; Tue, 06 Jan 2004 17:17:49 +0100 Received: from Andro-Beta.Leidinger.net (GQJPKiZcreESP0YXaVOvlPo3JKMWrn7WvXT3tjYfN4WUL95K2AIdry@[80.131.126.23]) by fmrl03.sul.t-online.com with esmtp id 1Adtti-0rhUAa0; Tue, 6 Jan 2004 17:17:38 +0100 Received: from Magellan.Leidinger.net (Magellan.Leidinger.net [192.168.1.1]) i06GHWJb051208; Tue, 6 Jan 2004 17:17:33 +0100 (CET) (envelope-from Alexander@Leidinger.net) Received: from Magellan.Leidinger.net (netchild@localhost [127.0.0.1]) i06GHfTL065300; Tue, 6 Jan 2004 17:17:41 +0100 (CET) (envelope-from Alexander@Leidinger.net) Date: Tue, 6 Jan 2004 17:17:40 +0100 From: Alexander Leidinger To: Holger.Kipp@alogis.com Message-Id: <20040106171740.201f6581@Magellan.Leidinger.net> In-Reply-To: <200401061536.i06FadY90540@alogis.com> References: <200401061536.i06FadY90540@alogis.com> X-Mailer: Sylpheed version 0.9.8claws (GTK+ 1.2.10; i386-portbld-freebsd5.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Seen: false X-ID: GQJPKiZcreESP0YXaVOvlPo3JKMWrn7WvXT3tjYfN4WUL95K2AIdry@t-dialin.net cc: stable@freebsd.org cc: current@freebsd.org Subject: Re: perl malloc slow? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jan 2004 16:19:33 -0000 On Tue, 06 Jan 2004 15:36:34 +0000 Holger Kipp wrote: > Kris Kennaway wrote: "For any algorithm one can come up with a workload that > makes it perform badly. The trick is making it perform well for > common workloads, which FreeBSD's malloc does." > (http://lists.freebsd.org/pipermail/freebsd-hackers/2003-September/003059.html) > > Even so, if Perl malloc and Linux malloc are O(n) with a small constant and > FreeBSD malloc behaves like O(n*n) or worse with a large constant in this > easy example (of a real-world applikation), this behaviour should imho be > investigated.... You need to make a context switch for every malloc call. AFAIK perls malloc has a resource pool, from which it allocates if possible. This saves a context switch for each malloc call which can be satisfied from the resource pool. If the Zlib module allocates alot of small memory regions with the same size one after another and frees alot of them after a short period of time, this results in a huge amount of context switches in the non-perl-malloc case and in nearly no context switch in the with-perl-malloc case. The right thing to do in such a case is to optimize the application to use e.g. a ring buffer. A static number of malloc() calls at startup, use them for a long time, free() them. Or to manage a malloc resource pool on it's own. This is what perl does in the with-perl-malloc case. AFAIK perl uses its own malloc on GNU/Linux... feel free to correct me (perl -V | grep usemymalloc). I tried to convince our perl maintainer to use perls malloc (5.6.1 doesn't use it by default) long ago, but I failed (but I got the WITH_PERL_MALLOC switch in the port). Somewhat (un)related: use perl malloc if you encounter problems in a perl application which uses signals. Bye, Alexander. -- I will be available to get hired in April 2004. http://www.Leidinger.net Alexander @ Leidinger.net GPG fingerprint = C518 BC70 E67F 143F BE91 3365 79E2 9C60 B006 3FE7