From owner-freebsd-hackers@FreeBSD.ORG Thu Dec 16 01:39:32 2004 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 B789C16A4CE for ; Thu, 16 Dec 2004 01:39:32 +0000 (GMT) Received: from mail2.hqhost.net (mail2.hqhost.net [64.237.37.220]) by mx1.FreeBSD.org (Postfix) with ESMTP id 59B7343D2D for ; Thu, 16 Dec 2004 01:39:32 +0000 (GMT) (envelope-from kenny@gem-hs.org) Received: from [195.190.103.100] (spb-195-190-103-100.sovintel.ru [195.190.103.100] (may be forged)) (authenticated bits=0) by mail2.hqhost.net (8.12.11/8.12.11) with ESMTP id iBG1dTYA073037 for ; Thu, 16 Dec 2004 01:39:30 GMT (envelope-from kenny@gem-hs.org) Message-ID: <41C0E74F.1070404@gem-hs.org> Date: Thu, 16 Dec 2004 04:39:27 +0300 From: Kenny Chamber User-Agent: Mozilla Thunderbird 1.0 (Windows/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=ISO-8859-1; format=flowed 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: Thu, 16 Dec 2004 01:39:32 -0000 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? ----------------------- Kenny Chamber http://gem-hs.org/contact.html