Page 1 of 1

CMA in 7.4

Posted: 2019/09/23 17:37:06
by zvivered

According to .config:
CONFIG_DMA_CMA : Does not exist

How can I enable CMA in this version ?

I have to allocate a 256MB physically contiguous memory buffer with: dma_alloc_coherent
or __get_free_pages

I managed to allocate only 4MB.

Thank you,

Re: CMA in 7.4

Posted: 2019/09/23 22:49:16
by TrevorH
Please don't use 7.4, it's over 2 years old and riddled with security vulnerabilities. The current version is 7.7. Run yum update

Are you passing cma=xx[MG] as per/usr/share/doc/kernel-doc-3.10.0/Documentation/kernel-parameters.txt (part of the kernel-doc package)?

Code: Select all

         cma=nn[MG]      [ARM,KNL]
                        Sets the size of kernel global memory area for contiguous
                        memory allocations. For more information, see

Re: CMA in 7.4

Posted: 2019/09/29 04:22:46
by zvivered

Thank you for your reply.
I upgraded to centos 8.0.1905

I changed kernel configuration to:
In kernel boot parameters: cma=32M

When I tried to allocate up to 4MB I got the following output in dmesg:

[ 1462.787121] cma: cma_alloc(cma 000000001c0c6b6b, count 1024, align 8)
[ 1462.790433] cma: cma_alloc(): returned 00000000087f40b7
[ 1462.790434] cma: cma_release(page 00000000087f40b7)[/i]

The allocation succeeded.

Then I tried to allocate 8MB and got:
[ 1588.692877] cma: cma_alloc(cma 000000001c0c6b6b, count 2048, align 8)
[ 1588.695398] cma: cma_alloc(): returned 00000000087f40b7
[ 1588.695399] cma: cma_release(page 00000000087f40b7)

The allocation failed.
dma_alloc_coherent(NULL, 0x800000, &dma_handle, GFP_KERNEL);
returned NULL.

What am I doing wrong ?

Thank you in advance,

Re: CMA in 7.4

Posted: 2019/09/29 22:20:08
by zvivered

The hardware I'm using is PCIe.
The FPGA will write data by DMA to a physical address.

Is it possible that the reason for the failure is that currently I'm working without this FPGA ?

static void * virtual_adr_ptr;
static int hello_init(void)
printk ("-->hello_init\n");

virtual_adr_ptr=dma_alloc_coherent(NULL, BUF_SIZE, &dma_handle, GFP_KERNEL);
if (virtual_adr_ptr == 0)
return -1;

return 0;

Thank you,

Re: CMA in 7.4

Posted: 2019/09/30 19:04:23
by aks
No where near a C kind of guy, but I can tell you that the CMA values are published under /proc/meminfo (specfically CmaTotal & CmaFree) - might prove whether it is *actually* enabled or not (and allocation success and failure).

Re: CMA in 7.4

Posted: 2019/09/30 19:26:34
by TrevorH
And you don't need to recompile it to change it, it's a kernel parameter passed via the kernel command line.