Skip to contentSkip to conversation

Why does ion_cma_allocate need GFP_HIGHUSER | __GFP_ZERO flags?

DISCUSSION Gioh Kim 2 participants 3 messages Nov 13, 2014 – Nov 14, 2014

lore
Share & tools
lore

Gioh Kim

author
#0 lore raw

Hi,

I'm wondering why dma_alloc_coherent needs GFP_HIGHUSER | __GFP_ZERO flags in ion_cma_allocate().

I think dma_alloc_coherent can go to __dma_alloc if the system has CMA area. If __GFP_WAIT flag is set, it allocates memory from atomic pool. So I think calling dma_alloc_coherent with __GFP_WAIT is enough.

And can I get zero-filled-memory from CMA if I set __GFP_ZERO?

Signature · 2 lines
Thanks,
Gioh Kim
#1 lore raw
Quoted 11 lines · Gioh Kim

Hi,

I'm wondering why dma_alloc_coherent needs GFP_HIGHUSER | __GFP_ZERO flags in ion_cma_allocate().

I think dma_alloc_coherent can go to __dma_alloc if the system has CMA area. If __GFP_WAIT flag is set, it allocates memory from atomic pool. So I think calling dma_alloc_coherent with __GFP_WAIT is enough.

And can I get zero-filled-memory from CMA if I set __GFP_ZERO?

If we are actually using CMA, the GFP flags don't make much of a difference. If we didn't have CMA, using GFP_HIGHUSER would still be appropriate. The memory is going to userspace so the user part is necessary and there should be no need for a lowmem mapping so highmem can be used. __GFP_ZERO might be redundant since the dma layer zeros memory anyway but it's probably safe.

I think the flags should be fine as is.

Thanks,
Laura

Signature · 3 lines
Qualcomm Innovation Center, Inc. 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author
#2 lore raw

2014-11-14 오전 10:24에 Laura Abbott 이(가) 쓴 글:

Quoted 13 lines · Gioh Kim
Quoted 11 lines

Hi,

I'm wondering why dma_alloc_coherent needs GFP_HIGHUSER | __GFP_ZERO flags in ion_cma_allocate().

I think dma_alloc_coherent can go to __dma_alloc if the system has CMA area. If __GFP_WAIT flag is set, it allocates memory from atomic pool. So I think calling dma_alloc_coherent with __GFP_WAIT is enough.

And can I get zero-filled-memory from CMA if I set __GFP_ZERO?

Quoted 5 lines

If we are actually using CMA, the GFP flags don't make much of a difference. If we didn't have CMA, using GFP_HIGHUSER would still be appropriate. The memory is going to userspace so the user part is necessary and there should be no need for a lowmem mapping so highmem can be used. __GFP_ZERO might be redundant since the dma layer zeros memory anyway but it's probably safe.

If cma-heap can be created even-if the system doesn't have CMA area, you're right.

But I think cma-heap should be created only if the system has CMA area.
I think, in no CMA system, cma-heap creation and/or allocation from cma-heap should be failed, not allocate memory from lowmem or highmem as you say.

Thanks for your reply.

Quoted 6 lines

I think the flags should be fine as is.

Thanks,
Laura