From owner-freebsd-hackers Thu Jan 28 13:57:36 1999 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA22918 for freebsd-hackers-outgoing; Thu, 28 Jan 1999 13:57:36 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from bright.fx.genx.net (bright.fx.genx.net [206.64.4.154]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA22910 for ; Thu, 28 Jan 1999 13:57:33 -0800 (PST) (envelope-from bright@hotjobs.com) Received: from localhost (bright@localhost) by bright.fx.genx.net (8.9.1/8.9.1) with ESMTP id RAA38653; Thu, 28 Jan 1999 17:04:06 -0500 (EST) (envelope-from bright@hotjobs.com) X-Authentication-Warning: bright.fx.genx.net: bright owned process doing -bs Date: Thu, 28 Jan 1999 17:04:06 -0500 (EST) From: Alfred Perlstein X-Sender: bright@bright.fx.genx.net To: Emmanuel Duros cc: freebsd-hackers@FreeBSD.ORG Subject: Re: rules to allocate buffers in device drivers In-Reply-To: <199901281349.OAA24119@chouette.inria.fr> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, 28 Jan 1999, Emmanuel Duros wrote: > > Hi, > > I am currently writing a network device driver for FreeBSD and it is > still unclear to me how to allocate memory. > > It seems that a common way of doing it is something like: > > u_char *buffer; > buffer = malloc( SIZE, M_DEVBUF, M_NOWAIT); > > However I have not seen something like this in a device driver: > > u_char buffer[SIZE]; > > Is there a particular reason for not allocating buffers statically ? > Pointing out files and line numbers in the code helps a lot, however as i understand it, the reason buffers aren't like: u_char buffer[SIZE]; is because there is a very limited intrupt stack (MSmith told me 16k?) if you exhaust that, it's not a very good thing. using malloc with NOwait set allows you to hopefully retry a transfer at a different time. however sometimes you will see something like: u_char stkbuffer[20]; u_char *buf; buf = ( nbytes <= 20 ) ? &(stkbuffer[0]) : (u_char*) malloc(...); the reason the above is done is to avoid a call to malloc if the amount of buffer space is usually going to be small and could be fit on the stack. > I have not found anything related to how to allocate memory in kernel > code (definitions of malloc parameters, etc.). Do you have any pointer > on that ? man 9 malloc Alfred Perlstein - Programmer, HotJobs Inc. - www.hotjobs.com -- There are operating systems, and then there's FreeBSD. -- http://www.freebsd.org/ 4.0-current To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message