Date: Tue, 10 Dec 2002 23:05:45 -0700 From: Scott Long <scott_long@btc.adaptec.com> To: yiding_wang@agilent.com Cc: freebsd-scsi@freebsd.org Subject: Re: Question on memory allocation Message-ID: <20021211060544.GA12582@hollin.btc.adaptec.com> In-Reply-To: <334DD5C2ADAB9245B60F213F49C5EBCD05D54F20@axcs03.cos.agilent.com> References: <334DD5C2ADAB9245B60F213F49C5EBCD05D54F20@axcs03.cos.agilent.com>
next in thread | previous in thread | raw e-mail | index | archive | help
I assume that you're trying to allocate memory that will be shared with the hardware, yes? If so, then you need to use the 'busdma' interface. Unfortunately, it isn't well documented. The only real reference is the source code and other drivers. Anyways, see below: On Tue, Dec 10, 2002 at 07:12:16PM -0700, yiding_wang@agilent.com wrote: > Hello Team, > > I have some questions about memory allocation in FreeBSD device driver. I couldn't find answer either from man page or docs. > > 1, For the function malloc(), what does M_DEVBUF flag represent? malloc requires a cookie that it uses for memory profiling and debugging. You can create you own cookie with MALLOC_DEFINE() > 2, What is the syntax and argument for malloc() to allocate N byte of memory with M alignment requirement? malloc cannot guarantee memory alignment. You need to create a busdma tag via bus_dma_tag_create() in order to specify things like alignment and boundary restricts. YOu then use this tag with bus_dmamem_alloc() to allocate memory with those restrictions. > 3, Can malloc be used for physical contiguous memory allocation? If so, what is the syntax and argument? malloc does not guarantee physcially contiguous allocations. contigmalloc() does. Once again, for the purpose that I think you are going for, busdma is the correct API to use. > 4, If bus_dmamem_alloc() is the one for physical contiguous memory allocation, then what is the syntax and argument? for getting alig Look at other drivers for the answer to this. For what you intend to do, this is the correct way to allocate memory. > 5, Is there any memory size limitation from both memory allocation function? Kind of. The memory allocation routines don't currently try to coalesce and merge free space, so your physical memory map can get quite fragmented over time. This isn't a big problem during boot, but can be one is your driver is loaded as a module after the system has been up for a while. Avoid allocating large slabs of physical memory. > > Any direction to source documents regarding these memory allocation function and vtop / ptov function pair are welcomes! > > Many thanks! > > Eddie > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-scsi" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-scsi" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20021211060544.GA12582>