Re: [PATCH RFC]: Bus_dma eats all available memory

From: Piotr Ziêcik <kosmo_at_semihalf.com>
Date: Fri, 26 Jun 2009 09:29:40 +0200
Thursday 25 June 2009 20:30:27 Scott Long napisa³(a):
> Piotr Ziêcik wrote:
> > Hi
> >
> > While working on new driver for FreeBSD I have found a problem in bus_dma
> > subsystem. Every time when bus_dmamap_create() is called on bus_dma tag
> > using bounce zone, at least 1 page in bounce zone is allocated. This
> > causes eating of all avaible memory by bounce zone. Problem affects i386,
> > amd64 and arm.
>
> The code block that you point at can only be entered if the maxpages
> limit has not been reached.  However, the max limit is per zone, not
> global, and there's no easy way to make it be global.  Are you creating
> an excessive number of tags/zones?

Driver creates one tag and and one map everytime when new request arrives.
Both are freed after processing. Driver can queue maximum 64 requests, so
it there will not be more than 64 tags and 64 maps. Debugging shows that the 
limit is never reached and number of tags and maps is around 30 - 40. In my 
oppinion this is not excessive number of tags.

I observe one bounce zone with huge amount of pages:
hw.busdma.total_bpages: 114428
hw.busdma.zone0.total_bpages: 114428
hw.busdma.zone0.free_bpages: 114428
hw.busdma.zone0.reserved_bpages: 0
hw.busdma.zone0.active_bpages: 0
hw.busdma.zone0.total_bounced: 0
hw.busdma.zone0.total_deferred: 0
hw.busdma.zone0.lowaddr: 0xffffffff
hw.busdma.zone0.alignment: 4096

I suppose, that problem could be around BUS_DMA_MIN_ALLOC_COMP flag:
--- code ---
if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0
                 || (bz->map_count > 0 && bz->total_bpages < maxpages)) {
--- code ---
When new tag is created, an initial bounce zone allocation will be performed 
if BUS_DMA_ALLOCNOW flag is passed to bus_dma_tag_create(). If the allocation 
was not done, the BUS_DMA_MIN_ALLOC_COMP flag is not set and we will enter to 
the problematic code block. 

The idea of my fix is to alloc 0 or more pages when when condition in the if 
statement shown above is true.  In current code 1 or more pages will be 
allocated in that case. Behaviour introduced by my patch seems to work in 
current ia64 code.

-- 
Best Regards,
Piotr Ziecik
Received on Fri Jun 26 2009 - 05:29:43 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:50 UTC