Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GFP_KERNEL vs GFP_DMA and kmalloc() vs dma_alloc_coherent()

I always use dma_alloc_coherent() to allocate DMA buffer with flag GFP_KERNEL and haven't observed problem so far, my understanding is both flags allow the caller to sleep as well..

So I am just curious if GFP_DMA option is really useful in this case? Also the flag is available for kmalloc(), however are we not supposed to use kmalloc() to allocate DMA buffer but only dma apis?

like image 643
luke Avatar asked Dec 20 '25 03:12

luke


1 Answers

dma_alloc_coherent() returns address range for which proper memory attributes are already set so cache effect is handled naturally. We need not to do any cache operation for these addresses.

If we use address allocated by kmalloc() for DMA operation then we need to do extra cache operation like cache clean and cache invalidate based on direction of transfer.

GFP_DMA flag just allocates memory from DMA Zone on 32-bit machine.

like image 145
Dhiraj Avatar answered Dec 23 '25 07:12

Dhiraj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!