"Unable to request 2 buffers: Cannot allocate memory" with 2 64mp cameras

RPI 5, 64-bit bookworm desktop
libcamera 0.1.0.2
2x64MP arducam autofocus cameras

pi@pi5:~ $ cat /proc/meminfo | grep Cma
CmaTotal:         655360 kB
CmaFree:          638880 kB

Hi, I get this error when i try to use two 64mp cameras from my c++ app

[3:15:25.513588021] [18902] ERROR V4L2 v4l2_videodevice.cpp:1241 /dev/video34[42:cap]: Unable to request 2 buffers: Cannot allocate memory
[3:15:25.513637410] [18902] ERROR RPI pipeline_base.cpp:683 Failed to allocate buffers

I created this simple example to demonstrate the error

if you uncomment the lines 54, 55 the error does not occur. I pinned the error to the line camera_release() in the closeCamera() method.

“Unable to request 2 buffers: Cannot allocate memory” - but i explicitly tell the cameras to use only 1 buffer in the configureStill method, why is it trying to allocate two buffers for both cameras? even if i put buffercount to 0 i still get error text “Unable to request 2 buffers”.
Also since i use YUV420 then each buffer should be 80MB so 4x80=320MB should be still ok since i have over 600MB free CMA memory. Or is this v4l_videodevice.cpp using rgb buffer? in this case 4x190MB = 760MB yes i would be running out of memory.

if i run 2xlibcamera-jpeg or libcamera-still with --encoding yuv420 in parallel in different command prompts i dont get this error.

whats going on here and how to fix this? why isnt the buffercount i give taken into account?

found these two threads that explain in detail whats going on with memory. seems that there is no fix for this though and only way to capture two images in parallel with such high res is still to use two separate RPIs each having 1 separate camera.
https://forums.raspberrypi.com/viewtopic.php?t=338949
https://forums.raspberrypi.com/viewtopic.php?t=339182
i will try the lite OS though instead of desktop

Merry Christmas Henri,
Thank you for your contribution to our forum!
Regarding your problem, though you are using Pi 5(especially you try to use two cameras), 64mp cameras will take up too much memory so that the error “Cannot allocate memory” always occus.
Changing to lite version may be the final choice…

tx, this seems to be hardware limitation. CMA memory is under DMA_ZONE which in turn can be max 1GB. I was about to look into changing DMA_ZONE memory range in raspberry pi os source code and then recompile the kernel, but then i stumbled to this sentence in documentation that was in the source code:

Zones
=====

Often hardware poses restrictions on how different physical memory
ranges can be accessed. In some cases, devices cannot perform DMA to
all the addressable memory. In other cases, the size of the physical
memory exceeds the maximal addressable size of virtual memory and
special actions are required to access portions of the memory. Linux
groups memory pages into `zones` according to their possible
usage. For example, ZONE_DMA will contain memory that can be used by
devices for DMA, ZONE_HIGHMEM will contain memory that is not
permanently mapped into kernel's address space and ZONE_NORMAL will
contain normally addressed pages.

The actual layout of the memory zones is hardware dependent as not all
architectures define all zones, and requirements for DMA are different
for different platforms.

What i have concluded is that there is a ton of wires coming from camera that go through some sort of multiplexer or controller or something like that map the memory to those wires based on CMA code so the peripheral device(camera in our case) can very fast dump its frame and theres certain fixed amount of wires going from that controller to the ram thats why we cant make DMA_ZONE greater than 1GB on raspberry pi.

My conclusion could be wrong though since i never found the place where to set DMA_ZONE memory ranges. So for those willing to go into that rabbit hole i found a post on this topic: [PATCH] arm64: make CONFIG_ZONE_DMA user settable

Just wondering, are there alternatives to raspberry pi that would work with 64mp arducam? I could potentially try those out and see if there are same hardware restrictions.

did some more digging i think its defined in this file https://github.com/raspberrypi/linux/blob/rpi-6.1.y/arch/arm64/mm/init.c
at rows 220-230

static void __init zone_sizes_init(void)
{
	unsigned long max_zone_pfns[MAX_NR_ZONES]  = {0};
	unsigned int __maybe_unused acpi_zone_dma_bits;
	unsigned int __maybe_unused dt_zone_dma_bits;
	phys_addr_t __maybe_unused dma32_phys_limit = max_zone_phys(32);

#ifdef CONFIG_ZONE_DMA
	acpi_zone_dma_bits = fls64(acpi_iort_dma_get_max_cpu_address());
	dt_zone_dma_bits = fls64(of_dma_get_max_cpu_address(NULL));
	zone_dma_bits = min3(32U, dt_zone_dma_bits, acpi_zone_dma_bits);
	arm64_dma_phys_limit = max_zone_phys(zone_dma_bits);
	max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit);
#endif
#ifdef CONFIG_ZONE_DMA32
	max_zone_pfns[ZONE_DMA32] = PFN_DOWN(dma32_phys_limit);
	if (!arm64_dma_phys_limit)
		arm64_dma_phys_limit = dma32_phys_limit;
#endif
	max_zone_pfns[ZONE_NORMAL] = max_pfn;

	free_area_init(max_zone_pfns);
}

now need to find where arm64_dma_phys_limit gets its value

lines 58-91

/*
 * If the corresponding config options are enabled, we create both ZONE_DMA
 * and ZONE_DMA32. By default ZONE_DMA covers the 32-bit addressable memory
 * unless restricted on specific platforms (e.g. 30-bit on Raspberry Pi 4).
 * In such case, ZONE_DMA32 covers the rest of the 32-bit addressable memory,
 * otherwise it is empty.
 *
 * Memory reservation for crash kernel either done early or deferred
 * depending on DMA memory zones configs (ZONE_DMA) --
 *
 * In absence of ZONE_DMA configs arm64_dma_phys_limit initialized
 * here instead of max_zone_phys().  This lets early reservation of
 * crash kernel memory which has a dependency on arm64_dma_phys_limit.
 * Reserving memory early for crash kernel allows linear creation of block
 * mappings (greater than page-granularity) for all the memory bank rangs.
 * In this scheme a comparatively quicker boot is observed.
 *
 * If ZONE_DMA configs are defined, crash kernel memory reservation
 * is delayed until DMA zone memory range size initialization performed in
 * zone_sizes_init().  The defer is necessary to steer clear of DMA zone
 * memory range to avoid overlap allocation.  So crash kernel memory boundaries
 * are not known when mapping all bank memory ranges, which otherwise means
 * not possible to exclude crash kernel range from creating block mappings
 * so page-granularity mappings are created for the entire memory range.
 * Hence a slightly slower boot is observed.
 *
 * Note: Page-granularity mappings are necessary for crash kernel memory
 * range for shrinking its size via /sys/kernel/kexec_crash_size interface.
 */
#if IS_ENABLED(CONFIG_ZONE_DMA) || IS_ENABLED(CONFIG_ZONE_DMA32)
phys_addr_t __ro_after_init arm64_dma_phys_limit;
#else
phys_addr_t __ro_after_init arm64_dma_phys_limit = PHYS_MASK + 1;
#endif

"If the corresponding config options are enabled, we create both ZONE_DMA

  • and ZONE_DMA32. By default ZONE_DMA covers the 32-bit addressable memory
  • unless restricted on specific platforms (e.g. 30-bit on Raspberry Pi 4)."

30-bits is 1GB go figure xD

i wonder could we ask the raspberry pi guys wether pi5 also is limited to 30-bits. some forum u could reccommend? or some alternative to raspberry pi that does not have such restriction? what other hardware does arducam 64mp cameras work on?

also seems like this dude managed to squeeze 848MB for CMA by playing around with device-tree adresses. its worth investigationg Maximizing CMA memory size problem - Page 2 - Raspberry Pi Forums look at his last post

Arduino, Raspberry Pi, NVIDIA Jetson, Rockchip, NXP, and more - from arducam website. would need to contact these companies and ask wether they have 30-bit DMA_ZONE limit

i also made post to raspberry pi forums on the topic of does pi5 have ZONE_DMA limited to 30 bits Question: Is Pi5 ZONE_DMA also limited to 30-bit addressable memory? - Raspberry Pi Forums
and to nvidia forums about jetson Is ZONE_DMA limit 30 or 32-bits on Jetson? - Jetson Nano - NVIDIA Developer Forums

https://www.marcusfolkesson.se/blog/contiguous-memory-allocator/
also i reccommend this post - this guy says he got Pi4 CMA to 900MiB!!!

pi@pi4:~ $ sudo cat /proc/iomem
00000000-3b2fffff : System RAM (960 MiB)
00000000-00000fff : reserved (0.00391 MiB)

~2MiB hole here

00210000-0122ffff : Kernel code (16.1875 MiB)
01230000-0165ffff : reserved (4.34375 MiB)
01660000-0199ffff : Kernel data (2.625 MiB)

~10MiB hole

02400000-2e3fffff : reserved (705.5 MiB) <— CMA

hole 2E400000 - 2E559FFF 0.07 MiB

2e55a000-2e567fff : reserved (0.00488 MiB)
2e568000-2effffff : reserved (10 MiB)

big hole ~137 MB 2f000000 - 372fffff

37300000-3b2fffff : reserved (64.25 MiB)

pi@pi4:/ $ sudo cat /proc/meminfo
CmaTotal: 720896 kB
CmaFree: 705376 kB

if im able to find whats allocated at
2e55a000-2e567fff : reserved (0.00488 MiB)
and
2e568000-2effffff : reserved (10 MiB)

i might be able to allocate somewhere else and then i can have cma up to 848MiB. The small one 0.00488 MiB i think is the device_tree they mention in the raspberry pi forum
and can be moved with setting
device_tree_address=0x2000000
device_tree_end=0x20FFFFF
in the /boot/config.txt just use adresses suitable for your case
but the big one 10MB they dont even mention in their thread. they dont have it in their iomem https://forums.raspberrypi.com/viewtopic.php?t=355799&start=25

I looked at whats in that address

pi@pi4:~ $ dmesg | grep -i 2e568000
[ 0.000000] reserved[0x5] [0x000000002e568000-0x000000002effffff], 0x0000000000a98000 bytes flags: 0x0
[ 0.765971] memblock_phys_free: [0x000000002e568000-0x000000002effffff] free_initrd_mem+0x34/0x5c

what is it?

i did add memblock=debug to /boot/cmdline.txt but i dont see any more information

Hey, I think I managed to get around 3GB+ recognized on the CMAd by adding cma=3072M at the end of the /boot/cmdlinet.txt Somewhere between 3GB-4GB seems to be the maximum. I messed up the boot, flashed it again with the lite 64-bit OS, plugged it into pi5 right away, and now, after editing the cmdline.txt and rebooting, it shows that there’s indeed that much CMAd available.

CmaTotal:        3145728 kB
CmaFree:         3135392 kB

I probably couldn’t get it before because after flashing it, I used that stick on a pi4 earlier. Somehow, after the first boot configuration there, it ended up recognizing only 1GB. Have a great end to the old year!

Unfortunately after setting CMA that large i cant use keyboard nor do i see cameras being attached with libcamera-still --list-cameras

I managed to increase CMA to 3072MB. Instructions here

https://forums.raspberrypi.com/viewtopic.php?p=2173568#p2173568

running these two commands in separate terminals works fine
libcamera-still --camera 0 --width 9152 --height 6944 -o test0.jpg -n -t 1 --encoding yuv420
libcamera-still --camera 1 --width 9152 --height 6944 -o test1.jpg -n -t 1 --encoding yuv420

but the with bgr still get error in second terminal when running
libcamera-still --camera 0 --width 9152 --height 6944 -o test0.jpg -n -t 1 --encoding rgb
libcamera-still --camera 1 --width 9152 --height 6944 -o test1.jpg -n -t 1 --encoding rgb

pi@pi:~ $ libcamera-still --camera 1 --width 9152 --height 6944 -o test1.jpg -n                                                                                                                                    -t 1 --encoding rgb
[0:05:20.147690394] [1079]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+                                                                                                                                   146-cff216fa-dirty (2023-12-05T09:54:10+00:00)
[0:05:20.174573716] [1091]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a25                                                                                                                                   8644a 22-11-2023 (22:03:31)
[0:05:20.179246561] [1091]  WARN CameraSensorProperties camera_sensor_properties                                                                                                                                   .cpp:265 No static properties available for 'arducam_64mp'
[0:05:20.179264321] [1091]  WARN CameraSensorProperties camera_sensor_properties                                                                                                                                   .cpp:267 Please consider updating the camera sensor properties database
[0:05:20.208772133] [1091]  INFO RPI pisp.cpp:1113 Registered camera /base/axi/p                                                                                                                                   cie@120000/rp1/i2c@88000/arducam_64mp@1a to CFE device /dev/media0 and ISP devic                                                                                                                                   e /dev/media2 using PiSP variant BCM2712_C0
[0:05:20.208854803] [1091]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a25                                                                                                                                   8644a 22-11-2023 (22:03:31)
[0:05:20.209826710] [1091]  WARN CameraSensorProperties camera_sensor_properties                                                                                                                                   .cpp:265 No static properties available for 'arducam_64mp'
[0:05:20.209843859] [1091]  WARN CameraSensorProperties camera_sensor_properties                                                                                                                                   .cpp:267 Please consider updating the camera sensor properties database
[0:05:20.227270061] [1091]  INFO RPI pisp.cpp:1113 Registered camera /base/axi/p                                                                                                                                   cie@120000/rp1/i2c@80000/arducam_64mp@1a to CFE device /dev/media1 and ISP devic                                                                                                                                   e /dev/media3 using PiSP variant BCM2712_C0
[0:05:20.228874734] [1079]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format Y16
[0:05:20.228911846] [1079]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format RGB6
[0:05:20.228921495] [1079]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format BGR6
[0:05:20.228931402] [1079]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format PC1M
Mode selection for 4576:3472:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 13268.4
    SRGGB10_CSI2P,1920x1080/0 - Score: 11268.4
    SRGGB10_CSI2P,2312x1736/0 - Score: 9005.18
    SRGGB10_CSI2P,3840x2160/0 - Score: 5268.43
    SRGGB10_CSI2P,4624x3472/0 - Score: 1017.18
    SRGGB10_CSI2P,8000x6000/0 - Score: 2493.76
    SRGGB10_CSI2P,9152x6944/0 - Score: 3012
Stream configuration adjusted
[0:05:20.229361826] [1079]  INFO Camera camera.cpp:1183 configuring streams: (0)                                                                                                                                    4576x3472-YUV420 (1) 4624x3472-RGGB16_PISP_COMP1
[0:05:20.229479960] [1091]  INFO RPI pisp.cpp:1397 Sensor: /base/axi/pcie@120000                                                                                                                                   /rp1/i2c@80000/arducam_64mp@1a - Selected sensor format: 4624x3472-SRGGB10_1X10                                                                                                                                    - Selected CFE format: 4624x3472-PC1R
[0:05:21.516236624] [1079]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format Y16
[0:05:21.516286348] [1079]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format RGB6
[0:05:21.516295830] [1079]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format BGR6
[0:05:21.516306294] [1079]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format PC1M
Mode selection for 9152:6944:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 29364.4
    SRGGB10_CSI2P,1920x1080/0 - Score: 27364.4
    SRGGB10_CSI2P,2312x1736/0 - Score: 25101.2
    SRGGB10_CSI2P,3840x2160/0 - Score: 21364.4
    SRGGB10_CSI2P,4624x3472/0 - Score: 17005.2
    SRGGB10_CSI2P,8000x6000/0 - Score: 5197.76
    SRGGB10_CSI2P,9152x6944/0 - Score: 1000
Stream configuration adjusted
[0:05:21.516770662] [1079]  INFO Camera camera.cpp:1183 configuring streams: (0)                                                                                                                                    9152x6944-BGR888 (1) 9152x6944-RGGB16_PISP_COMP1
[0:05:21.553124322] [1091]  INFO RPI pisp.cpp:1397 Sensor: /base/axi/pcie@120000                                                                                                                                   /rp1/i2c@80000/arducam_64mp@1a - Selected sensor format: 9152x6944-SRGGB10_1X10                                                                                                                                    - Selected CFE format: 9152x6944-PC1R
Still capture image received

pi@pi:~ $ libcamera-still --camera 0 --width 9152 --height 6944 -o test0.jpg -n                                                                                                                                    -t 1 --encoding rgb
[0:05:20.147690412] [1080]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+                                                                                                                                   146-cff216fa-dirty (2023-12-05T09:54:10+00:00)
[0:05:20.174573475] [1090]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a25                                                                                                                                   8644a 22-11-2023 (22:03:31)
[0:05:20.179246932] [1090]  WARN CameraSensorProperties camera_sensor_properties                                                                                                                                   .cpp:265 No static properties available for 'arducam_64mp'
[0:05:20.179264210] [1090]  WARN CameraSensorProperties camera_sensor_properties                                                                                                                                   .cpp:267 Please consider updating the camera sensor properties database
[0:05:20.208869396] [1090]  INFO RPI pisp.cpp:1113 Registered camera /base/axi/p                                                                                                                                   cie@120000/rp1/i2c@88000/arducam_64mp@1a to CFE device /dev/media0 and ISP devic                                                                                                                                   e /dev/media2 using PiSP variant BCM2712_C0
[0:05:20.209002438] [1090]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a25                                                                                                                                   8644a 22-11-2023 (22:03:31)
[0:05:20.209916973] [1090]  WARN CameraSensorProperties camera_sensor_properties                                                                                                                                   .cpp:265 No static properties available for 'arducam_64mp'
[0:05:20.209941474] [1090]  WARN CameraSensorProperties camera_sensor_properties                                                                                                                                   .cpp:267 Please consider updating the camera sensor properties database
[0:05:20.227270098] [1090]  INFO RPI pisp.cpp:1113 Registered camera /base/axi/p                                                                                                                                   cie@120000/rp1/i2c@80000/arducam_64mp@1a to CFE device /dev/media1 and ISP devic                                                                                                                                   e /dev/media3 using PiSP variant BCM2712_C0
[0:05:20.228876123] [1080]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format Y16
[0:05:20.228921069] [1080]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format RGB6
[0:05:20.228935143] [1080]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format BGR6
[0:05:20.228957366] [1080]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format PC1M
Mode selection for 4576:3472:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 13268.4
    SRGGB10_CSI2P,1920x1080/0 - Score: 11268.4
    SRGGB10_CSI2P,2312x1736/0 - Score: 9005.18
    SRGGB10_CSI2P,3840x2160/0 - Score: 5268.43
    SRGGB10_CSI2P,4624x3472/0 - Score: 1017.18
    SRGGB10_CSI2P,8000x6000/0 - Score: 2493.76
    SRGGB10_CSI2P,9152x6944/0 - Score: 3012
Stream configuration adjusted
[0:05:20.229547352] [1080]  INFO Camera camera.cpp:1183 configuring streams: (0)                                                                                                                                    4576x3472-YUV420 (1) 4624x3472-RGGB16_PISP_COMP1
[0:05:20.229807343] [1090]  INFO RPI pisp.cpp:1397 Sensor: /base/axi/pcie@120000                                                                                                                                   /rp1/i2c@88000/arducam_64mp@1a - Selected sensor format: 4624x3472-SRGGB10_1X10                                                                                                                                    - Selected CFE format: 4624x3472-PC1R
[0:05:21.501825562] [1080]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format Y16
[0:05:21.501889379] [1080]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format RGB6
[0:05:21.501898787] [1080]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format BGR6
[0:05:21.501913158] [1080]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2                                                                                                                                    pixel format PC1M
Mode selection for 9152:6944:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 29364.4
    SRGGB10_CSI2P,1920x1080/0 - Score: 27364.4
    SRGGB10_CSI2P,2312x1736/0 - Score: 25101.2
    SRGGB10_CSI2P,3840x2160/0 - Score: 21364.4
    SRGGB10_CSI2P,4624x3472/0 - Score: 17005.2
    SRGGB10_CSI2P,8000x6000/0 - Score: 5197.76
    SRGGB10_CSI2P,9152x6944/0 - Score: 1000
Stream configuration adjusted
[0:05:21.502521606] [1080]  INFO Camera camera.cpp:1183 configuring streams: (0)                                                                                                                                    9152x6944-BGR888 (1) 9152x6944-RGGB16_PISP_COMP1
[0:05:21.517791033] [1090]  INFO RPI pisp.cpp:1397 Sensor: /base/axi/pcie@120000                                                                                                                                   /rp1/i2c@88000/arducam_64mp@1a - Selected sensor format: 9152x6944-SRGGB10_1X10                                                                                                                                    - Selected CFE format: 9152x6944-PC1R
[0:05:22.949701675] [1090] ERROR V4L2 v4l2_videodevice.cpp:1697 /dev/video21[25:                                                                                                                                   out]: Failed to queue buffer 0: Invalid argument
[0:05:22.949775196] [1090] ERROR RPISTREAM rpi_stream.cpp:276 Failed to queue bu                                                                                                                                   ffer for ISP TDN Input
[0:05:22.949815364] [1090] ERROR V4L2 v4l2_videodevice.cpp:1697 /dev/video26[26:                                                                                                                                   cap]: Failed to queue buffer 0: Invalid argument
[0:05:22.949826531] [1090] ERROR RPISTREAM rpi_stream.cpp:276 Failed to queue bu                                                                                                                                   ffer for ISP TDN Output
[0:05:22.949861143] [1090] ERROR V4L2 v4l2_videodevice.cpp:1697 /dev/video22[27:                                                                                                                                   out]: Failed to queue buffer 0: Invalid argument
[0:05:22.949872551] [1090] ERROR RPISTREAM rpi_stream.cpp:276 Failed to queue bu                                                                                                                                   ffer for ISP Stitch Input
[0:05:22.949905089] [1090] ERROR V4L2 v4l2_videodevice.cpp:1697 /dev/video27[28:                                                                                                                                   cap]: Failed to queue buffer 0: Invalid argument
[0:05:22.949914923] [1090] ERROR RPISTREAM rpi_stream.cpp:276 Failed to queue bu                                                                                                                                   ffer for ISP Stitch Output
                                                                                                                                   

looking at log of last camera there is
[0:05:20.229547352] [1080] INFO Camera camera.cpp:1183 configuring streams: (0) 4576x3472-YUV420 (1) 4624x3472-RGGB16_PISP_COMP1

[0:05:21.502521606] [1080] INFO Camera camera.cpp:1183 configuring streams: (0) 9152x6944-BGR888 (1) 9152x6944-RGGB16_PISP_COMP1

Like why is it creating 4576x3472-YUV420, 4624x3472-RGGB16_PISP_COMP1, 9152x6944-RGGB16_PISP_COMP1 streams if im telling it to use res 9152x6944 and encoding rgb? Is it creating buffers for these also?

I think the CMA still isnt enough to create all these buffers since last address system reserves for cma is still withgin 1024M because the ZONE_DMA is limited to 30-bit on raspberry pi. The logs above i got when cma=960M48M


What i think might be happening lets say libcamera is creating 2 x (9152x6944 rgb888) buffer for each camera thats already 4 buffers and in my code i also make 1 buffer for each camera and that means 6 rgb buffers each requiring 192MB. 6x192MB=1152MB that is more then CMA can be give in 30-bit address space. whe i set CMA to exceed this address space cma=3072MB@48M then i get different error in second camera.

pi@pi:~ $ libcamera-still --camera 0 --width 8000 --height 6000 -o test0.jpg -n -t 1 --encoding rgb
[0:07:42.936795892] [1283]  INFO Camera camera_manager.cpp:284 libcamera v0.1.0+146-cff216fa-dirty (2023-12-05T09:54:10+00:00)
[0:07:42.961703713] [1293]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (22:03:31)
[0:07:42.962912846] [1293]  WARN CameraSensorProperties camera_sensor_properties.cpp:265 No static properties available for 'arducam_64mp'
[0:07:42.962928661] [1293]  WARN CameraSensorProperties camera_sensor_properties.cpp:267 Please consider updating the camera sensor properties database
[0:07:42.983811724] [1293]  INFO RPI pisp.cpp:1113 Registered camera /base/axi/pcie@120000/rp1/i2c@88000/arducam_64mp@1a to CFE device /dev/media0 and ISP device /dev/media3 using PiSP variant BCM2712_C0
[0:07:42.983888615] [1293]  INFO RPI pisp.cpp:653 libpisp version v1.0.2 fa44a258644a 22-11-2023 (22:03:31)
[0:07:43.241684169] [1293] ERROR V4L2 v4l2_device.cpp:353 'arducam_64mp 4-001a': Unable to set controls: Device or resource busy
[0:07:43.241992804] [1293]  WARN CameraSensorProperties camera_sensor_properties.cpp:265 No static properties available for 'arducam_64mp'
[0:07:43.242005378] [1293]  WARN CameraSensorProperties camera_sensor_properties.cpp:267 Please consider updating the camera sensor properties database
[0:07:43.255837203] [1293]  INFO RPI pisp.cpp:1113 Registered camera /base/axi/pcie@120000/rp1/i2c@80000/arducam_64mp@1a to CFE device /dev/media1 and ISP device /dev/media4 using PiSP variant BCM2712_C0
[0:07:43.256455417] [1283]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format Y16
[0:07:43.256500696] [1283]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format RGB6
[0:07:43.256516678] [1283]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format BGR6
[0:07:43.256532326] [1283]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format PC1M
Mode selection for 4624:3468:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 13350.7
    SRGGB10_CSI2P,1920x1080/0 - Score: 11350.7
    SRGGB10_CSI2P,2312x1736/0 - Score: 9092.61
    SRGGB10_CSI2P,3840x2160/0 - Score: 5350.67
    SRGGB10_CSI2P,4624x3472/0 - Score: 1005.61
    SRGGB10_CSI2P,8000x6000/0 - Score: 2477
    SRGGB10_CSI2P,9152x6944/0 - Score: 3047.08
Stream configuration adjusted
[0:07:43.257506844] [1283]  INFO Camera camera.cpp:1183 configuring streams: (0) 4624x3468-YUV420 (1) 4624x3472-RGGB16_PISP_COMP1
[0:07:43.257649661] [1293]  INFO RPI pisp.cpp:1397 Sensor: /base/axi/pcie@120000/rp1/i2c@88000/arducam_64mp@1a - Selected sensor format: 4624x3472-SRGGB10_1X10 - Selected CFE format: 4624x3472-PC1R
[0:07:44.517548256] [1283]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format Y16
[0:07:44.517597424] [1283]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format RGB6
[0:07:44.517607516] [1283]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format BGR6
[0:07:44.517618239] [1283]  WARN V4L2 v4l2_pixelformat.cpp:338 Unsupported V4L2 pixel format PC1M
Mode selection for 8000:6000:12:P
    SRGGB10_CSI2P,1280x720/0 - Score: 25166.7
    SRGGB10_CSI2P,1920x1080/0 - Score: 23166.7
    SRGGB10_CSI2P,2312x1736/0 - Score: 20908.6
    SRGGB10_CSI2P,3840x2160/0 - Score: 17166.7
    SRGGB10_CSI2P,4624x3472/0 - Score: 12812.6
    SRGGB10_CSI2P,8000x6000/0 - Score: 1000
    SRGGB10_CSI2P,9152x6944/0 - Score: 1570.08
Stream configuration adjusted
[0:07:44.518218639] [1283]  INFO Camera camera.cpp:1183 configuring streams: (0) 8000x6000-BGR888 (1) 8000x6000-RGGB16_PISP_COMP1
[0:07:44.532071021] [1293]  INFO RPI pisp.cpp:1397 Sensor: /base/axi/pcie@120000/rp1/i2c@88000/arducam_64mp@1a - Selected sensor format: 8000x6000-SRGGB10_1X10 - Selected CFE format: 8000x6000-PC1R
[0:07:44.950899674] [1293] ERROR V4L2 v4l2_videodevice.cpp:1697 /dev/video25[23:cap]: Failed to queue buffer 0: Invalid argument
[0:07:44.950932138] [1293] ERROR RPISTREAM rpi_stream.cpp:276 Failed to queue buffer for ISP Output1
ERROR: Device timeout detected, attempting a restart!!!
[0:07:44.953530037] [1293] FATAL default v4l2_videodevice.cpp:1960 /dev/video25[23:cap]: assertion "cache_->isEmpty()" failed in streamOff()
Backtrace:
??? [0xfffffffff782ca44] (/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 [0xfffffffff782ca44])
??? [0xfffffffff7851bc0] (/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 [0xfffffffff7851bc0])
??? [0xfffffffff78015b4] (/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 [0xfffffffff78015b4])
??? [0xfffffffff734cdc0] (/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 [0xfffffffff734cdc0])
??? [0xfffffffff734f564] (/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 [0xfffffffff734f564])
??? [0xfffffffff73457f0] (/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 [0xfffffffff73457f0])
??? [0xfffffffff734eee4] (/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 [0xfffffffff734eee4])
??? [0xfffffffff77d2600] (/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 [0xfffffffff77d2600])
??? [0xfffffffff75be068] (/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 [0xfffffffff75be068])
??? [0xfffffffff73d18e0] (/usr/lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 [0xfffffffff73d18e0])

Through trial and error i figured out that maximum res i can give is 7445x6000 with BGR888 for parallel capture of two cameras

libcamera-still --camera 0 --width 7445 --height 6000 -o test0.jpg -n -t 1 --encoding rgb
libcamera-still --camera 1 --width 7445 --height 6000 -o test1.jpg -n -t 1 --encoding rgb

increasing the width to 7446 on both commands will create the same error in second camera log.

Is it possible for you to fix arducam-libcamera so that it wouldnt eat so much CMA and i could capture bgr888 at 9152x6944?

An idea popped in my head.
Lets say 1 buffer that driver or libcamera makes somewhere for each camera in and another 2 buffers the that are made in the user application. so 4 buffers in total
4xrgb7445x6000 is ~511.20MB … dual capture works
4xrgb7446x6000 is ~511.28MB … dual capture does not work anymore

as in the docs it is specified that when configuring CMA from /boot/config.txt the largest option is
dtoverlay=vc4-kms-v3d,cma-512

and 511.28MB is strangely close to 512

@Dion eventhough im able to increase CMA up to 972MB on rpi os lite with cma=972M@48M in the /boot/cmdline.txt, is it possible that arducam-libcamera or driver can still only use up to 512MB CMA? how to confirm or deny that? and what could be the cause of this?

libcamera-still --camera 0 --width 9152 --height 6944 -o test0.jpg -n -t 1 --encoding rgb
wait ~1.1…2 seconds
libcamera-still --camera 1 --width 9152 --height 6944 -o test1.jpg -n -t 1 --encoding rgb

it works!