Thursday, December 11, 2014

When to use GFP_ATOMIC over GFP_KERNEL

Using the GFP_ATOMIC option with kmalloc instructs the memory allocator to never block waiting for a page. So the execution of the instruction will happen instantaneously - either with the allocation of the desired memory or not. Because the kernel does not have a chance to wait and free
up memory or reclaim memory for new allocations, GFP_ATOMIC has a higher chance of failing than GFP_KERNEL.

In order to make sure that the memory can be DMA’d, bitwise or either GFP_KERNEL or GFP_ATOMIC with the GFP_DMA flag as shown below:
1 . . .
2 buf = kmalloc (BUF_LEN, GFP_DMA | GFP_KERNEL) ;
3 i f ( ! buf )
4 e r r o r handling
5 . . .

0 comments:

Post a Comment