Turn off CMA in kernel

Hi - the application i’m using is very RAM hungry (hence my earlier question on hugepages which are now working) and so i would like to turn off CMA so that i can get at the ~330mb that is has allocated to use for more hugepages. I cant just turn this off in the kernel config and rebuild the kernel as the build fails. Is there anyway to turn it off at runtime / make it smaller / get the kernel to build without CMA

In fact any way to get more memory available would be appreciated. I run this headless and just ssh into it for a computing / memory intensive workload so dont need graphics or anything

thanks in advance!

@Gouwa - this is the thread i started on getting CMA turned off - any ideas if its possible? When i turn off CMA in the kernel config file and build then it starts throwing errors - can get past the first one by ifdef’ing the variable in question:

static int bypass_4K;

but then we are into huge numbers of errors after that - looks fairly integral to the amlogic driver code. Currently waiting on a usb to serial device so i can change the boot options to set cma to zero to see if that works. Is there anyway to change the kernel boot options without the serial device to tap into u-boot?

thanks in advance!

@numbqq please follow up when you available.

1 Like

What version of kernel did you use? How did you turn off CMA? What errors did you encounter?

For image V171028 you can use boot.ini file to set u-boot environment variables.
You need a SD card with fat32 filesystem, put boot.ini file in it and insert it to VIM, when system bootup will read and parse environment variables in boot.ini file.

boot.ini file format example:


setenv test-boot-ini 1


Hi @numbqq

I built the kernel from https://github.com/khadas/linux so assume latest version. I turned off CMA using both menuconfig and by editing the kvim_defconfig file, by commenting out CONFIG_CMA=y and CONFIG_DMA_CMA=y, tried the combinations of these one by one and both together and get the same error.

first error is bypass_4K being an unused variable and generates an error because of strict rules. When i modified the source to the extract below to remove that error then there are a huge number of errors generated after that, bits of structs missing etc.

static int bypass_4K;

Think the need for CMA is pretty well embedded. Having said that im happy to turn off lots of features as running this headless without a need for GPU so if you know of any way to get past it then im willing to strip lots of the kernel out!

Have tried a boot.ini file on an otherwise blank FAT32 formatted SD card, but couldnt get it to change the boot. My USB to serial device doesnt seem to be working as i just get gibberish out, so getting another one. The boot.ini file was:


setenv cma 0

any help appreciated!

You can try to disable CMA in DTS and don’t modify configurations.You can refer to this about disable some reserved memory.

You can use u-boot-tools to set u-boot environment variables in ubuntu.

$ sudo apt-get install u-boot-tools

Download fw_env.config and copy it to /etc/fw_env.config.

$ sudo cp fw_env.config /etc/fw_env.config

Print u-boot environment variables.

$ sudo fw_printenv

Set u-boot environment variables.

$ sudo fw_setenv hello-test 1
$ sudo fw_setenv save
$ sudo fw_printenv hello-test


well adding cma=100 to the command line appears to have fully stopped it working lol - cant even get it to boot into upgrade mode now! Thru the buttons or Mregister and still cant get serial working (unless anyone can translate this \�-�V�79�;�����3�=��su}W�}wsy���y���_ay���[yM���]YY^���W�-��^+k��%V����UY{��� lol)! Will continue to play

Hi birty,

What’s the purpose of adding cma=100?



Im trying to make the CMA smaller - though i think i went the wrong way with the numbers, but didnt want to get to 0 straight away given the issue compiling the kernel. But now sadly i have a deveice that wont boot, so im kind of stuck! How do you guys do the initial programme of the devices? Is there somethign i could try?


I disable CMA in DTS ever. I’m not sure how did you modify the kernel and DTS.

And Mregister mode can’t work?

ive got it back to being recognised on my computer and flashing an image now works ok - but still not booting afterwards. Have ordered a new board as well. Will update if i get it working again or when the new one arrives.

Should have copied your DTS fix the first time instead of messing with u-boot stuff!

What’s the status of your VIM2?

Can flash ROM, but still not boot?

Yes - thats where I am now. Image burns ok, but nothing on reset - no hdmi output, no network connection. Have tried erase all flash - but nothing

Still cant get serial working - is there a recomended serial to usb adaptor, ive tried two and they both output garbage. Have got correct settings and followed the guide in docs on how to set it up

Show photos of how you connect the adapters. Have you tried to swap Rx Tx contacts ? Very often the designation for the adapters is not correct.

@numbqq - Ive got my new VIM2 now - trying to get to a point where i have hugepages on and CMA off.

I have used the Fenix scripts to build now - makes the process easier.

Ive got hugepages on my adding the followign lines to project/fenix/linux/arch/arm64/configs/kvim_defconfig (also added it to defconfig and kvim_defconfig_buildroot for good measure so i didnt have to build mulitple times)

Using the Fenix scripts then the file (arch/arm64/boot/dts/amlogic/ep-box.dts) you linked to above to change isnt there, but there is a kvim2_linux.dts so i put the changes into that instead. Then i did a make clean and then built again according to fenix scripts instructions - but when i burn the image it doesnt boot (at least doesnt get as far as getting an IP address) as i cant see it on the network.

Any advice apprecitaed

yeah - have tried two and have tried swapping contacts over. Ive used one of them on a microcontroller project before and it worked fine there. Connections are as per http://docs.khadas.com/develop/SetupSerialTool/ using three wires for 0v, tx and rx.

Will find another serial device to connect to make sure its all still working

@birty If you need only console, you can try to remove the whole reserved-memory section, maybe except for secmon and secos:

You will also need to remove every other section that uses reserved memory chunks you deleted, e.g. https://github.com/khadas/linux/blob/Nougat/arch/arm64/boot/dts/kvim2.dts#L213-L218

ok, thanks will give that a go - kind of deleting stuff in the dark to be honest! Wouldnt mind if it didnt take so long to build and for me to find out it didnt work lol

I don’t know your build setup but modifying device tree should be pretty easy: simply run make kvim.dtb in you kernel dir after you modify the tree and you’ll get a dtb almost in an instant.

1 Like

It’s been a while since I’ve worked this low level but CMA should clear out pages (eg inode cache) that others request. On ARM however we use this space for a LOT for things other platforms may have in hardware. I would start by stripping down every driver from the kernel you don’t need (eg audio, video, …) and use serial to get a TTY. Basically get to the level of busybox and then run your application with minimal software.