From owner-freebsd-hackers@FreeBSD.ORG Mon Nov 3 02:08:35 2003 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8AA7C16A4CE for ; Mon, 3 Nov 2003 02:08:35 -0800 (PST) Received: from gatekeeper.syskonnect.de (gatekeeper.syskonnect.de [213.144.13.149]) by mx1.FreeBSD.org (Postfix) with ESMTP id 328C043FE1 for ; Mon, 3 Nov 2003 02:08:34 -0800 (PST) (envelope-from gheinig@syskonnect.de) Received: from syskonnect.de (spock [10.9.15.1])hA3A8u69011993 for ; Mon, 3 Nov 2003 11:08:57 +0100 (MET) Received: from syskonnect.de (localhost [127.0.0.1]) by syskonnect.de (8.12.9/8.12.9) with ESMTP id hA3KfNKl029079 for ; Mon, 3 Nov 2003 21:41:28 +0100 (MET) X-Authentication-Warning: spock.skd.de: iscan owned process doing -bs Sender: gheinig@syskonnect.de Message-ID: <3FA6253E.9D727094@syskonnect.de> Date: Mon, 03 Nov 2003 10:51:58 +0100 From: Gerald Heinig Organization: SysKonnect GmbH X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.18 i686) X-Accept-Language: en MIME-Version: 1.0 To: hackers@freebsd.org Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: kernel malloc usage X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Nov 2003 10:08:35 -0000 Hi all, I have a question concerning the use of malloc to allocate small amounts of memory for packet wrappers for certain packets. Basically, I'm using malloc in much the same way as one would use it in a standard userland program: allocating small chunks and freeing them again a short(ish) time later. A colleague said this was a bad idea, since malloc should only really be used to allocate larger chunks (PAGE_SIZE and over) at driver initialisation. Management and partition of the allocated space should be done by the driver. His reason was that over time, the kernel heap memory gets progressively more fragmented until it becomes difficult to get larger blocks. Is this true? I seem to remember that FreeBSD has a slab allocator, which IIRC is particularly good at allocating small chunks. Is it a better idea to write my own allocators which use a larger block of memory allocated by malloc at driver start-time, or can I use malloc as in userland? Cheers, Gerald -- S y s K o n n e c t G m b H A Marvell Company Siemensstr. 23 D-76275 Ettlingen, Germany --------------------------------- Gerald Heinig Software Engineer ------------------------------------- phone: + 49 (0) 7243 502 354 fax: +49 (0) 7243 502 364 email: gheinig@syskonnect.de http://www.syskonnect.com