Contiguous memory

I’m running 3.0.1 on a 4x2 board. I issue the linux command

!cat /proc/meminfo | grep -I cms

from the jupyter notebook and it comes back with

CmaTotal:   131072 kB
CmaFree:     69596 kB

I read a previous post on this in this forum (Pynq & maximum allocatable memory (CMA)) which has to do with how to rebuild linux for more contiguous space. But I couldn’t resist asking claude.ai what it thinks, and here’s what it returned (see below). Seems quite a bit easier than rebuilding linux! Has anyone tried this, could it work? I can easily try it but thought I would ask if there’s any experience out there first. Thanks in advance!

Method 1: Edit the boot arguments directly

  1. Mount the boot partition (if not already mounted):

bash

   sudo mount /dev/mmcblk0p1 /mnt
  1. Edit the boot.py or uEnv.txt file (depending on your PYNQ setup):

bash

   sudo nano /mnt/uEnv.txt

Or look for boot configuration files in /boot/

  1. Add or modify the CMA parameter in the kernel command line:
   cma=256M

You can set this to whatever size you need (e.g., 256M, 512M, etc.). Common values are powers of 2.

Method 2: Modify extlinux.conf (more common on PYNQ)

  1. Edit the extlinux configuration:

bash

   sudo nano /boot/extlinux/extlinux.conf
  1. Add cma=XXXm to the APPEND line:
   APPEND root=/dev/mmcblk0p2 rw rootwait cma=256M

Method 3: Device Tree modification

For PYNQ systems, you might need to modify the device tree:

  1. Check your current device tree:

bash

   ls /boot/devicetree/
  1. You can either modify the bootargs in the device tree source or use the methods above.

Important Considerations:

  • Total RAM: Make sure you don’t allocate too much to CMA, as this reduces available system memory
  • Backup: Always backup your boot configuration before modifying
  • Reboot required: Changes take effect after rebooting
  • Verification: After reboot, check with cat /proc/meminfo | grep Cma to verify the change

The exact location and method depends on your specific PYNQ image, but the cma= kernel parameter is the standard way to control CMA size across all these approaches.

Hi @drewphysics

I remember trying this a while back, but couldn’t get it to work by changing the boot arguments in u-boot.

I didn’t try any other methods mentioned in your post though, so if you do find one that works, then please report back.

The Trixie release boots via a U-boot script for the implementation of Ubuntu Linux. You can know this by looking at the directory /boot/ via

ls -la /boot

you should see:

drwxr-xr-x  3 root root    16384 Jan  1  1970 .
drwxr-xr-x 19 root root     4096 Nov 21 17:57 ../
-rwxr-xr-x  1 root root  1683736 Oct 23  2022 BOOT.BIN*
-rwxr-xr-x  1 root root     1726 Oct 23  2022 boot.py*
-rwxr-xr-x  1 root root     2779 Oct 23  2022 boot.scr*
-rwxr-xr-x  1 root root 23123516 May 25  2024 image.ub*
-rwxr-xr-x  1 root root       89 Oct 23  2022 REVISION*
drwxr-xr-x  2 root root     4096 May 26  2024 "System Volume Information"

That you see BOOT.BIN and boot.scr is telling you that the system uses the U-Boot facility.

All you need to do to increase contiguous memory is to create a file in /boot that gets read at boot time, and put the modifications there. So it’s quite easy:

cd /boot
sudo nano uEnv.txt

and add this single line:

bootargs=root=/dev/mmcblk0p2 rw earlyprintk rootfstype=ext4 rootwait devtmpfs.mount=1 uio_pdrv_genirq.of_id="generic-uio" clk_ignore_unused cma=512M

save and exit (control x) and reboot. This increases the contiguous memory to 512M, but you can go higher (e.g. change 512M to 2G)

When you reboot check with

cat /proc/meminfo | grep -i cma

And it should return the right number. At least, it did for me!