Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Aug 1998 15:48:23 -0700 (PDT)
From:      Archie Cobbs <archie@whistle.com>
To:        Emmanuel.Duros@sophia.inria.fr (Emmanuel Duros)
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Allocating memory in a network device driver
Message-ID:  <199808122248.PAA09142@bubba.whistle.com>
In-Reply-To: <199808122122.XAA03579@chouette.inria.fr> from Emmanuel Duros at "Aug 12, 98 11:22:54 pm"

next in thread | previous in thread | raw e-mail | index | archive | help
Emmanuel Duros writes:
> I am currently writing a network device driver and I need clarification
> on how to allocate memory.
> 
> I have seen in many device drivers allocating memory in the following
> way:
> 
> 	u_char *buf;
> 	buf = malloc( BUFSIZ, M_DEVBUF, M_NOWAIT);
> 
> Do we get the same result with : ?
> 
> 	u_char buf[BUFSIZ];

The kernel malloc works just like the libc malloc .. man malloc(3).
The extra arguments are the type (you must specify the same type
when you free() the memory) and whether or not it's OK to put the
current process to sleep in order to get the memory. If you say
M_WAITOK, then malloc() never fails but may put the process to sleep.
If you say M_NOWAIT, then it may fail but will not put the process
to sleep.

In general, M_NOWAIT is required for any code running during an
interrupt (ie, the current process should not be put to sleep),
otherwise M_WAITOK is ok.

-Archie

___________________________________________________________________________
Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com

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?199808122248.PAA09142>