From owner-freebsd-scsi Tue Dec 10 22: 9: 7 2002 Delivered-To: freebsd-scsi@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 417D737B401 for ; Tue, 10 Dec 2002 22:09:06 -0800 (PST) Received: from magic.adaptec.com (magic.adaptec.com [208.236.45.80]) by mx1.FreeBSD.org (Postfix) with ESMTP id 97E7B43EA9 for ; Tue, 10 Dec 2002 22:09:05 -0800 (PST) (envelope-from scottl@btc.adaptec.com) Received: from redfish.adaptec.com (redfish.adaptec.com [162.62.50.11]) by magic.adaptec.com (8.11.6+Sun/8.11.6) with ESMTP id gBB694j05680; Tue, 10 Dec 2002 22:09:04 -0800 (PST) Received: from btc.btc.adaptec.com (btc.btc.adaptec.com [10.100.0.52]) by redfish.adaptec.com (8.8.8+Sun/8.8.8) with ESMTP id WAA18810; Tue, 10 Dec 2002 22:08:53 -0800 (PST) Received: from hollin.btc.adaptec.com (hollin [10.100.253.56]) by btc.btc.adaptec.com (8.8.8+Sun/8.8.8) with ESMTP id XAA22808; Tue, 10 Dec 2002 23:08:49 -0700 (MST) Received: from hollin.btc.adaptec.com (localhost [127.0.0.1]) by hollin.btc.adaptec.com (8.12.6/8.12.5) with ESMTP id gBB65jkY013268; Tue, 10 Dec 2002 23:05:45 -0700 (MST) (envelope-from scottl@hollin.btc.adaptec.com) Received: (from scottl@localhost) by hollin.btc.adaptec.com (8.12.6/8.12.5/Submit) id gBB65jUQ013267; Tue, 10 Dec 2002 23:05:45 -0700 (MST) Date: Tue, 10 Dec 2002 23:05:45 -0700 From: Scott Long To: yiding_wang@agilent.com Cc: freebsd-scsi@freebsd.org Subject: Re: Question on memory allocation Message-ID: <20021211060544.GA12582@hollin.btc.adaptec.com> References: <334DD5C2ADAB9245B60F213F49C5EBCD05D54F20@axcs03.cos.agilent.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <334DD5C2ADAB9245B60F213F49C5EBCD05D54F20@axcs03.cos.agilent.com> User-Agent: Mutt/1.4i Sender: owner-freebsd-scsi@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org 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