From owner-freebsd-hackers@FreeBSD.ORG Mon Jun 13 12:41:35 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 EBBEB16A41C for ; Mon, 13 Jun 2005 12:41:35 +0000 (GMT) (envelope-from tinguely@casselton.net) Received: from casselton.net (casselton.net [63.165.140.2]) by mx1.FreeBSD.org (Postfix) with ESMTP id 98C4643D1F for ; Mon, 13 Jun 2005 12:41:35 +0000 (GMT) (envelope-from tinguely@casselton.net) Received: from casselton.net (localhost [127.0.0.1]) by casselton.net (8.12.11/8.12.11) with ESMTP id j5DCfXAn026936; Mon, 13 Jun 2005 07:41:33 -0500 (CDT) (envelope-from tinguely@casselton.net) Received: (from tinguely@localhost) by casselton.net (8.12.11/8.12.11/Submit) id j5DCfXL5026935; Mon, 13 Jun 2005 07:41:33 -0500 (CDT) (envelope-from tinguely) Date: Mon, 13 Jun 2005 07:41:33 -0500 (CDT) From: Mark Tinguely Message-Id: <200506131241.j5DCfXL5026935@casselton.net> To: apachexm@hotmail.com, freebsd-hackers@freebsd.org In-Reply-To: X-Spam-Status: No, score=1.4 required=5.0 tests=REPLY_TO_EMPTY autolearn=no version=3.0.3 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on ccn.casselton.net X-Mailman-Approved-At: Tue, 14 Jun 2005 12:36:45 +0000 Cc: 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 12:41:36 -0000 > 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.