contigmalloc() and mmap()

Apache Xie apachexm at hotmail.com
Mon Jun 13 15:03:11 GMT 2005



>From: Mark Tinguely <tinguely at casselton.net>
>To: apachexm at hotmail.com, freebsd-hackers at 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/



More information about the freebsd-hackers mailing list