From owner-freebsd-arch@FreeBSD.ORG Mon Sep 6 10:45:32 2004 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 044FC16A4CE for ; Mon, 6 Sep 2004 10:45:32 +0000 (GMT) Received: from critter.freebsd.dk (critter.freebsd.dk [212.242.86.163]) by mx1.FreeBSD.org (Postfix) with ESMTP id 6100143D2D for ; Mon, 6 Sep 2004 10:45:31 +0000 (GMT) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.13.1/8.13.1) with ESMTP id i86AjT46046740 for ; Mon, 6 Sep 2004 12:45:29 +0200 (CEST) (envelope-from phk@critter.freebsd.dk) To: arch@freebsd.org From: Poul-Henning Kamp Date: Mon, 06 Sep 2004 12:45:29 +0200 Message-ID: <46739.1094467529@critter.freebsd.dk> Sender: phk@critter.freebsd.dk Subject: Thoughts about malloc(3) and threading. X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Sep 2004 10:45:32 -0000 A number of times the issue of memory allocation in threaded programs have come up in various fora. In order to not become a road block for this important area, I want to state my opinion on this matter for the record: For single-threaded programs and non-malloc intensive multi-threaded programs I am still of the opinion that phkmalloc is our best choice. The combination of strong error checking and focus on minimal working set size seems to me a good compromise between functionality and raw performance for a general purpose malloc in a general purpose operating system. For multi-threaded programs with a lot of malloc activity, phkmalloc does not work well since it requires one big lock around the entire thing and does not do anything to preserve processor affinity. I think we need a malloc which can service this hi-end segment effectively, but even though various suggestions for replacements of phkmalloc to address this have been made, I do not see any clear winner or even the full list of candidates yet. Since a malloc which is aware of multiple CPUs or which relies on per-cpu locks can not implement a strong level of error checking, my guess is that we will end up retaining phkmalloc as the default and have a "SMP malloc" for the heavy duty case. It can (and without doubt will) be argued that the "SMP malloc" should be a port, but lets not even go there until we have a candidate. So, short version of my position is: I am not and will not be researching this topic and that people with a serious interest in it should get started. Given the list of programs which have been found buggy by phkmalloc, I do not think we should default to a malloc which does not have strong error checking. If a malloc better than phkmalloc in performance and error checking is found/written, I'll be all for a replacement if that means we will only have one malloc. Anyone wanting to work on this is welcome to contact me for some hard-earned insight into what and how to benchmark etc. Poul-Henning -- 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.