From owner-freebsd-hackers@FreeBSD.ORG Mon Jun 13 15:03:10 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id D9DCA16A41C for ; Mon, 13 Jun 2005 15:03:10 +0000 (GMT) (envelope-from apachexm@hotmail.com) Received: from hotmail.com (bay19-f5.bay19.hotmail.com [64.4.53.55]) by mx1.FreeBSD.org (Postfix) with ESMTP id B11EE43D53 for ; Mon, 13 Jun 2005 15:03:10 +0000 (GMT) (envelope-from apachexm@hotmail.com) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Mon, 13 Jun 2005 08:03:10 -0700 Message-ID: Received: from 220.169.39.197 by by19fd.bay19.hotmail.msn.com with HTTP; Mon, 13 Jun 2005 15:03:10 GMT X-Originating-IP: [220.169.39.197] X-Originating-Email: [apachexm@hotmail.com] X-Sender: apachexm@hotmail.com In-Reply-To: <200506131241.j5DCfXL5026935@casselton.net> From: "Apache Xie" To: tinguely@casselton.net Date: Mon, 13 Jun 2005 15:03:10 +0000 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 13 Jun 2005 15:03:10.0444 (UTC) FILETIME=[037D4AC0:01C57029] Cc: freebsd-hackers@freebsd.org Subject: Re: contigmalloc() and mmap() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 13 Jun 2005 15:03:11 -0000 >From: Mark Tinguely >To: apachexm@hotmail.com, freebsd-hackers@freebsd.org >Subject: Re: contigmalloc() and mmap() >Date: Mon, 13 Jun 2005 07:41:33 -0500 (CDT) > > > I browsed kernel tree, I found those drivers which use contigmalloc() >and > > contigfree() always call these two kernel interfaces in _attach() and > > _detach(), but in my driver, I call contigmalloc() in ioctl(), and call > > contigfree() in a callout function which is set by callout_reset(). > > What I want to know is if contigmalloc() and contigfree() can only be >used > > under some conditions? > >Allocating early prevents unfullfilled requests due to fragmentation of >the physical memory. I believe starting in FreeBSD 5.x, contigmalloc() >started to fill physical memory requests from the higher memory locations >to help with fragmentation. FreeBSD 5/6 has a Unified Meory Allocator >that helps allocate/free cycles. > > > And recently, I modified my driver, I allocated a big chunk of >contiguous > > physical memory using contigmalloc() in the driver's _attach() >function, > > and I use a simple first-fit algorithm to manage this memory myself, >which > > mean in ioctl() I use my allocate/deallocate functions instead of > > contigmalloc(), > > in _detach() function contigfree() is called to free the big chunk of > > memory, > > no panic again, but sometimes, process cannot get the correct data from > > the mmaped memory. I don't know why. > >Are you sure that you are allocating page length request on page >boundaries? >Are you checking the success/failure of the allocation? Your page faults >before implementing your own allocation sounds like you did not check >the return status from contigmalloc() and were dereferencing a pointer >on page 0. > >--Mark Tinguely. I checked the return values of those functions in my code, the problem I meet now seems caused by some cache coherency, I am still not sure, maybe I should do some more tests. And I used /dev/mem and bktr driver as the template when I was porting my driver, the platform I use is IA-64, in sys/ia64/ia64/mem.c, I find this line: *paddr = IA64_PHYS_TO_RR7(offset); why return the region 7 address? _________________________________________________________________ Express yourself instantly with MSN Messenger! Download today it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/