Trying to alloc many continous pages

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I'm writing a driver using DMA to transfer data to a performance critical device. I allocate a temporary DMA buffer which will be freed immediately after the DMA is completed. If there is enough continous memory available for all data I would like to transfer, I use it. Otherwise I split up the transfer in multiple transfers.

What's the right way to allocate the continous buffer? I didn't find how to "try allocating memory" without having an effect, if the memory in not available.

If I use the following code and there is not enough free memory, my linux hangs for several minutes after the DMA has finished.


unsigned int order = get_order(data_size);
while (1) {
     	kbuf = (void *) __get_free_pages(__GFP_NORETRY | __GFP_NOWARN, order);
	if (kbuf)
		break;		// success: we got a buffer
	if (order == 0)
		return -ENOMEM;
	order--;			// retry with a smaller order
}
buffer_size = PAGE_SIZE << order;



I think the memory management tries to reduce fragmentation in memory, but I would like to avoid this behaviour. It's not really a problem if I can't get a huge buffer, because in this case I will use a smaller one. But if there is a huge chunk of free memory I would like to use it, because it yields performance benefits.

I just want to look if I can alloc a number of continous pages, and if there aren't enough I want to handle it myself... How can I do that?


Best regards 
Philipp Werner 
___________________________________



Blaupunkt GmbH 
Robert-Bosch-Straße 200
31139 Hildesheim
www.blaupunkt.com


Sitz: Hildesheim, Registergericht: Amtsgericht Hildesheim HRB 120
Aufsichtsratsvorsitzender: Volkmar Denner; Geschäftsführung: Uwe Thomas,
Egbert Hellwig, Dirk Hoheisel, Michael Klemm
Blaupunkt GmbH - Ein Unternehmen der Bosch Gruppe 

--
To unsubscribe from this list: send the line "unsubscribe linux-newbie" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.linux-learn.org/faqs

[Index of Archives]     [Audio]     [Hams]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Fedora Users]

  Powered by Linux