raspberrypi / rpicam-apps

BSD 2-Clause "Simplified" License
410 stars 224 forks source link

[QUESTION] - unable to request buffers #555

Closed EricClaeys closed 1 year ago

EricClaeys commented 1 year ago

One of our Allsky users has an RPi HQ camera that occasionally produces the error below. Sometimes it produces 4 in a row, at which point our software stops. Any ideas on how to debug this?

Before calling libcamera-still our software kills any currently running libcamera-still processes (or at least it's supposed to).

Thanks - Eric

[111:06:04.333128904] [2815] ERROR V4L2 v4l2_videodevice.cpp:1241 /dev/video14[16:cap]: Unable to request 1 buffers: Cannot allocate memory
[111:06:04.333312828] [2815] ERROR RPI raspberrypi.cpp:1133 Failed to allocate buffers
ERROR: *** failed to start camera ***
naushir commented 1 year ago

Typically this would be if the CMA (contiguous memory allocator) heap is full and we are unable to allocate frame buffers for the camera data. The first thing I would check is if the user has any custom settings in the /boot/config.txt file that reduces the size of the CMA heap. Also, what sensor are they running with?

pmccudden commented 1 year ago

Here's my Pi: image and I'm using a Pi HQ camera. Could it be that my Pi board only has 1GB of RAM?

naushir commented 1 year ago

Easiest way is to do cat /proc/meminfo and check what memtotal lists. Have there been any other changes to the default /boot/config.txt or /boot/cmdline.txt files?

pmccudden commented 1 year ago

Here you go: image and I didn't make any changes to either of those files that I know of. Do you want to see copies of them? Thanks again.

naushir commented 1 year ago

That shows a 1GB memory size. Depending on what else might be running on the system, this might be a bit tight on memory and fail to allocate capture buffers. Our most recent updates to the libcamera libraries have made some improvements in camera buffer allocations, this may help with your intermittent failures. To update, you need to run

sudo apt update
sudo apt upgrade -y
naushir commented 1 year ago

Any further updates on this issue?

pmccudden commented 1 year ago

The problem was still there. I got my hands on an 8GB Pi, however, and the problem seems to be gone with it - apparently it was a memory issue?

EricClaeys commented 1 year ago

Many other people are using the HQ camera on Pi's with 1/2 GB or 1 GB systems, so I doubt it's the physical memory. During installation of Allsky did you let it create swap space?

pmccudden commented 1 year ago

I'm almost certain I did - I certainly did not actively chose NOT to. I may try a complete reinstallation on the 1 GB Pi and see what happens. I followed this video: https://www.youtube.com/watch?v=7TGpGz5SeVI

naushir commented 1 year ago

1GB ought to work (just about). It might possibly/probably be some background process or task that would be eating away some memory.

Conrad414 commented 1 year ago

My Allsky system is running on a Raspberry Pi 3B+ now with the latest version of Raspbian Bullseye OS with a 128Mb GPU memory, 4Gb swap file, no overlay file system, GL driver enabled and the latest version of Allsky.

The following issue has arisen. When I start Allsky from the Web GUI, it takes four pictures and then hangs with the message "ERROR: maximum number of consecutive errors of 4 reached; capture program stopped. (September 14, 07:21:25 AM)". However, if I close the Web GUI and browser immediately after starting Allsky, (or launch from the CLI) the program functions normally, eventually producing all the outputs - timelapse, startrails etc. Running a "libcamera-still --timelapse" also works with no problems so the camera cable is fine.

I have attached the log and RPi debug files pertaining to the above error message, hopefully in the right manner.

[65:22:36.000215746] [17183] [1;31mERROR [1;37mV4L2 [1;34mv4l2_videodevice.cpp:1241 [0;32m/dev/video14[16:cap]: [0mUnable to request 1 buffers: Cannot allocate memory ERROR: failed to allocate capture buffers

capture_RPi_debug.txt allsky.log

EricClaeys commented 1 year ago

@naushir, please note @Conrad414's issue is identical to @pmccudden's.

naushir commented 1 year ago

with a 128Mb GPU memory

How have you set this up? Unless there is a very specific need, you should leave CMA/GPU allocations set to the defaults provided in our standard OS images. This could possibly cause the memory issues you are encountering.

Conrad414 commented 1 year ago

I am using a RPi HiQ camera. I should note that I have now found that the Allsky Web GUI continues to run and save pictures provided I don't open the preview screen. As soon as I do, it fails with the above error message. I believe I have tried with memory defaults but will confirm this.

Conrad414 commented 1 year ago

I have changed the GPU memory back to 76Mb which I believe is the default and behavior is unchanged. cat /proc/me info reports 262144kB Cma total, 164788 free

naushir commented 1 year ago

Sorry for the delay in replying to this. Can you send me the output of libcamera-hello --version to see what version of libcamera you are running?

Conrad414 commented 1 year ago

Hi Naushir, I sent this output of libcamera-hello yesterday, not sure if it got through.

libcamer-hello.txt

naushir commented 1 year ago

Thanks for that. To be honest, there is very little I can recommend to do right now. One thing to do would be to try and increase the CMA memory space. To do this, edit /boot/config.txt and replace the following line:

dtoverlay=vc4-kms-v3d

with

dtoverlay=vc4-kms-v3d,cma-512

and see if that helps.

On the side, we are working with the libcamera team to improve memory usage, but that requires some changes to the libcamera stack. This is an ongoing development, so I can't give an exact timeframe when it would be ready.

Conrad414 commented 1 year ago

Thanks, will give it a try. Can at least live with the problem as long as I keep the Allsky preview window closed.

On Thu, 28 Sept 2023, 09:51 naushir, @.***> wrote:

Thanks for that. To be honest, there is very little I can recommend to do right now. One thing to do would be to try and increase the CMA memory space. To do this, edit /boot/config.txt and replace the following line:

dtoverlay=vc4-kms-v3d

with

dtoverlay=vc4-kms-v3d,cma-512

and see if that helps.

On the side, we are working with the libcamera team to improve memory usage, but that requires some changes to the libcamera stack. This is an ongoing development, so I can't give an exact timeframe when it would be ready.

— Reply to this email directly, view it on GitHub https://github.com/raspberrypi/libcamera-apps/issues/555#issuecomment-1738652521, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALLOEGYSK3IX5NWIPY7UYJ3X4UT5RANCNFSM6AAAAAA3TCJ76Y . You are receiving this because you were mentioned.Message ID: @.***>

pmccudden commented 1 year ago

My problem disappeared when I got a Raspberry Pi with more memory, so I'm assuming that was the issue

EricClaeys commented 1 year ago

@Conrad414, FYI, @naushir asked for the output of libcamera-hello --version, not libcamera-hello.

Conrad414 commented 1 year ago

Oh dear! Sorry about that. Here is the output of libcamera-hello --version

libcamera-hello --version libcamera-apps build: 7e4d3d71867f 17-07-2023 (07:34:42) libcamera build: v0.0.5+83-bde9b04f

naushir commented 1 year ago

Thanks, that verifies that you are using a very recent version of the libraries.

naushir commented 1 year ago

Unfortunately I cannot really think of anything more I can do here about this memory issue. However, we are working with the libcamera team on optimisations that improve the memory footprint, so things should hopefully improve in the future...

Conrad414 commented 1 year ago

Naushir,

Thanks for your input, I can manage by closing the preview window. Perhaps it's just too much for a Pi3?

Look forward to hearing if libcamera solves the problem.

Best regards

Conrad

On Thu, 05 Oct 2023, 09:34 naushir, @.***> wrote:

Unfortunately I cannot really think of anything more I can do here about this memory issue. However, we are working with the libcamera team on optimisations that improve the memory footprint, so things should hopefully improve in the future...

— Reply to this email directly, view it on GitHub https://github.com/raspberrypi/libcamera-apps/issues/555#issuecomment-1748259915, or unsubscribe https://github.com/notifications/unsubscribe-auth/ALLOEG7F5MZNPVDL5UC66N3X5ZPAFAVCNFSM6AAAAAA3TCJ762VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBYGI2TSOJRGU . You are receiving this because you were mentioned.Message ID: @.***>

orzaez commented 7 months ago

I have the same issue, I´m working with a Pi Zero 2W have 512 MB. Thats my config.txt dtparam=audio=on camera_auto_detect=1 display_auto_detect=1 dtoverlay=vc4-kms-v3d max_framebuffers=6 disable_overscan=1 otg_mode=1 dtoverlay=arducam-64mp [pi4] arm_boost=1 [all] camara auto detect=0

And the msg error is : ERROR V4L2 v4l2_videodevice.cpp:1241 /dev/video0[13:cap]: Unable to request 1 buffers: Cannot allocate memory ERROR: *** failed to allocate capture buffers *** Pls help!!!1

6by9 commented 7 months ago

max_framebuffers=6 is a nonsense. The max the firmware supports is 2.

Use of arducam-64mp means you're using Arducam's fork of libcamera, as they've never upstreamed support for that sensor. https://github.com/arducam/libcamera, and support through https://forum.arducam.com/c/cameras-for-raspberry-pi/7

https://forum.arducam.com/t/how-to-use-arducam-64mp-arducam-64mp-faq/2848/2 is recommending you assign 512MB to the CMA heap. That would be all the RAM on your Pi02W (it won't work), and the CMA heap is also used by the display pipeline. Each 64MPix image is 76MB. You literally can't fit many of those into 512MB.