Date: Mon, 13 Jun 2005 07:41:33 -0500 (CDT) From: Mark Tinguely <tinguely@casselton.net> To: apachexm@hotmail.com, freebsd-hackers@freebsd.org Subject: Re: contigmalloc() and mmap() Message-ID: <200506131241.j5DCfXL5026935@casselton.net> In-Reply-To: <BAY19-F33CED9E68F54579EE49ACCC4F00@phx.gbl>
next in thread | previous in thread | raw e-mail | index | archive | help
> 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.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200506131241.j5DCfXL5026935>