Date: Fri, 29 Jan 1999 03:59:46 +0000 (GMT) From: Terry Lambert <tlambert@primenet.com> To: archie@whistle.com (Archie Cobbs) Cc: Emmanuel.Duros@sophia.inria.fr, freebsd-hackers@FreeBSD.ORG Subject: Re: rules to allocate buffers in device drivers Message-ID: <199901290359.UAA17862@usr07.primenet.com> In-Reply-To: <199901282019.MAA03434@bubba.whistle.com> from "Archie Cobbs" at Jan 28, 99 12:19:41 pm
next in thread | previous in thread | raw e-mail | index | archive | help
> > u_char *buffer; > > buffer = malloc( SIZE, M_DEVBUF, M_NOWAIT); > > Yes this works.. you also have to make sure buffer != NULL > after calling malloc, as it can be with M_NOWAIT. > > M_DEVBUF is the type. You must free it with the same type argument. > > M_NOWAIT or M_WAITOK are the latter choices. Don't use M_WAITOK > from within an interrupt context, because it can put you to sleep. > > Also, you should use the MALLOC() and FREE() macros in <sys/malloc.h> > instead. Just to add to what Archie has correctly pointed out here... you probably don't want to allocate things at interrupt, in any case, since it makes the interrupt servicing much slower. A better plan is to pre-allocate one resource at instantiation, and then use a mechanism (like NETISR) to preallocate the next resource to replace the one that was used. It'd be real nice if FreeBSD could be a little more deterministic about the time it takes to process an interrupt to completion before leaving interrupt mode... Terry Lambert terry@lambert.org --- Any opinions in this posting are my own and not those of my present or previous employers. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199901290359.UAA17862>