[iMX8M Plus] CMA alloc failed during gst-launch

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[iMX8M Plus] CMA alloc failed during gst-launch

Jump to solution
2,350 Views
khang_letruong
Senior Contributor III

Hi NXP Community,

256MB of CMA memory has been successfully allocated in our iMX8M Plus based system with 1GB of DDR4:

 

root@viperimx8mp:~# dmesg | grep -i cma
[    0.000000] Reserved memory: created CMA memory pool at 0x0000000070000000, size 256 MiB
[    0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
[    0.000000] Memory: 703092K/1015808K available (17920K kernel code, 1506K rwdata, 6920K rodata, 2880K init, 553K bss, 50572K reserved, 262144K cma-reserved)

 

 

However, I am struggling with following errors while streaming the camera with gstreamer :

 

root@viperimx8mp:~# gst-launch-1.0 v4l2src device=/dev/video2 ! video/x-raw, width=1920, height=1080, framerate=15/1 ! autovideos

 

gst-launch.jpg

 


On the debug console side :

 

root@viperimx8mp:~# [  425.307460] enter isp_mi_stop                                                
[  425.942933] enter isp_mi_stop                                                                    
[  426.134422] cma: cma_alloc: alloc failed, req-size: 1013 pages, ret: -12                         
[  426.143351] cma: cma_alloc: alloc failed, req-size: 1013 pages, ret: -12                         
[  426.152091] cma: cma_alloc: alloc failed, req-size: 1013 pages, ret: -12                         
[  426.160775] cma: cma_alloc: alloc failed, req-size: 1013 pages, ret: -12                         
[  426.171442] cma: cma_alloc: alloc failed, req-size: 64 pages, ret: -12                           
[  426.178547] cma: cma_alloc: alloc failed, req-size: 1013 pages, ret: -12                         
[  426.189008] cma: cma_alloc: alloc failed, req-size: 1013 pages, ret: -12                         
[  426.199560] cma: cma_alloc: alloc failed, req-size: 1013 pages, ret: -12                         
[  426.209896] cma: cma_alloc: alloc failed, req-size: 1013 pages, ret: -12                         
[  426.251559] enter isp_mi_stop                                                                    
[  426.381644] jxf355_set_fps : current frame length: 2252, current line length: 1280               
[  426.399852] enter isp_s_comp                                                                     
[  426.402763] enter isp_s_comp                                                                     
[  426.405644] enter isp_s_comp                                                                     
[  426.427504] enter wdr3_hw_init                                                                   
[  426.430580] wdr3 res: 1920 1080                                                                  
[  426.434753] enter isp_mi_start                                                                   

 

 

Could you help if 256MB is sufficient for streaming single 1080p camera or the problem is somewhere else ?

Best Regards,

Khang

0 Kudos
1 Solution
2,331 Views
Holger75
Contributor II

Hi Khang,

I was facing same topic with my SoM. I found this link usefull

https://developer.toradex.com/software/linux-resources/linux-features/contiguous-memory-allocator-cm...

I assume it is controlled in the DTS in your case and you have to slightly increase your memsize.

resmem: reserved-memory {
/* global autoconfigured region for contiguous allocations */
linux,cma {
compatible = "shared-dma-pool";
reusable;
size = <0 0x38000000>;
alloc-ranges = <0 0x40000000 0 0x80000000>;
linux,cma-default;
};

Best regards

Holger

View solution in original post

8 Replies
1,596 Views
malik_cisse
Senior Contributor I

Hi Khang,

Can you please explain how you increased CMA size to 512MiB?

I have currently 640MiB allocated and I want to increase it as can be seen here:
~# dmesg | grep -i cma
[ 0.000000] Reserved memory: created CMA memory pool at 0x000000006a000000, size 640 MiB
[ 0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
[ 0.000000] Memory: 1034564K/2064384K available (18560K kernel code, 1644K rwdata, 7292K rodata, 3072K init, 552K bss, 374460K reserved, 655360K cma-reserved)

However the CMA size in the device tree does not correspond to 640MiB:
linux-imx/arch/arm64/boot/dts/freescale/imx8mp.dtsi

/* global autoconfigured region for contiguous allocations */

linux,cma {

compatible = "shared-dma-pool";

reusable;

size = <0 0x3c000000>;

alloc-ranges = <0 0x40000000 0 0xC0000000>;

linux,cma-default;

};


What is the correct way to increase this?
Thx

0 Kudos
1,589 Views
khang_letruong
Senior Contributor III

Hi @malik_cisse ,

Below is how I define 512MiB of CMA over 1024MiB (1 GiB) of DDR memory :

 

+               /* global autoconfigured region for contiguous allocations */
+               linux,cma {
+                       compatible = "shared-dma-pool";
+                       reusable;
+                       size = <0 0x20000000>;
+                       alloc-ranges = <0 0x40000000 0 0x40000000>;
+                       linux,cma-default;
+               };
+       };

 

Small conversion : 0x20000000 = 536870912 B = 536870912/1024/1024=512 MiB.

In your initial case, it seemed that the size ranged from 0 to 960MiB = 1006632960/1024/1024 = 1006632960 B =  0x3c000000. But it resulted in 640MiB (less than expected 960MiB) because the alloc-range was not enough or not contiguous (the first allocable region has 1024MiB in size).

Regards,

K.

 

0 Kudos
1,583 Views
malik_cisse
Senior Contributor I

Hi @khang_letruong ,
Thank you for your insight. This clarifies things to a certain extend.

My SOM has 2GB of DDR memory and it should be possible to alloc 960MiB to CMA (that would be less than 50% of available DDR memory).

Would it make sense to set the alloc-range to the full 2GB DDR size (similarly to what you set in your DT) like this:

alloc-ranges = <0 0x80000000 0 0x80000000>; ??

PS:
I have the feeling the initial alloc-range in my device tree does not even reflect my actual DDR size
alloc-ranges = <0 0x40000000 0 0xC0000000>;
to me means that two DDR regions can be used for CMA
region1: 0 to 0x40000000 : 0x40000000 = 1073741824 Dec = 1073741824/1024/1024=1024MiB.
region2:  0 to 0xC0000000 :0xC0000000 = 3221225472 Dec = 3221225472/1024/1024=3072MiB.
1024MiB + 3072MiB = 4096MiB
Thus total DDR memory is 4GB and not expected 2GB. This can be an error from my SOM provider.

0 Kudos
1,570 Views
khang_letruong
Senior Contributor III

Hi @malik_cisse ,

I also have 2GB of DDR :

+               /* global autoconfigured region for contiguous allocations */
+               linux,cma {
+                       compatible = "shared-dma-pool";
+                       reusable;
+                       size = <0 0x3c000000>;
+                       alloc-ranges = <0 0x40000000 0 0x80000000>;
+                       linux,cma-default;
+               };

and CMA is successfully allocated :

[    0.000000] Reserved memory: created CMA memory pool at 0x000000005c000000, size 960 MiB
[    0.000000] OF: reserved mem: initialized node linux,cma, compatible id shared-dma-pool
[    0.000000] Memory: 714344K/2064384K available (19584K kernel code, 1608K rwdata, 6708K rodata, 3328K init, 644K bss, 367000K reserved, 983040K cma-reserved)

 Brgs,

Khang

0 Kudos
1,503 Views
malik_cisse
Senior Contributor I

Hi @khang_letruong 
This is just to confirm that CMA size is overwritten with other DTS. I can now change CMA also.
On the other side I found the root cause of my CMA memory leak:
Not freeing properly gstreamer appsink upon new pipeline stop/start cycle.
Thank you for sharing your thoughts.

0 Kudos
1,567 Views
malik_cisse
Senior Contributor I

You must be right. I just found a mistake on my side.
I just found a dtsi file that overrules and includes settings in imx8mp.dtsi and that sets the 640MiB.

&{/reserved-memory/linux,cma} {
size = <0 0x28000000>;
alloc-ranges = <0 0x40000000 0 0x60000000>;
};

I will now update the CMA setting here and give it a try.
Thank you again for the precious feedback.

0 Kudos
2,332 Views
Holger75
Contributor II

Hi Khang,

I was facing same topic with my SoM. I found this link usefull

https://developer.toradex.com/software/linux-resources/linux-features/contiguous-memory-allocator-cm...

I assume it is controlled in the DTS in your case and you have to slightly increase your memsize.

resmem: reserved-memory {
/* global autoconfigured region for contiguous allocations */
linux,cma {
compatible = "shared-dma-pool";
reusable;
size = <0 0x38000000>;
alloc-ranges = <0 0x40000000 0 0x80000000>;
linux,cma-default;
};

Best regards

Holger

2,305 Views
khang_letruong
Senior Contributor III

Hi @Holger75 ,

Thanks for sharing your experience. I temporarily solved the issue by setting the CMA size to 512MiB, which is a half of the available DDR memory in the system. I am not sure if the remain 512MiB would be sufficient for other running stuffs.

Best Regards,
Khang

0 Kudos