Here is my environment: # R32 (release), REVISION: 7.2, GCID: 30192233, BOARD: t210ref, EABI: aarch64, DATE: Wed Apr 20 21:34:48 UTC 2022
Issue description.
3 pipelines using nvivafilter eat memory. The memory leak is significant about 1MB per minute.
Here is a sample source code to reproduce the issue. test_leak.txt (4.8 KB)
As soon as I reduce pipeline number from 3 to 2 (by commenting out start(2);) or remove nvivafilter from pipelines the issue goes away.
Here is source code sample with nvivafilter removed from the pipeline. test_no_leak.txt (4.5 KB)
To compile the samples: g++ -Wall -std=c++11 test_leak.cpp -o test $(pkg-config --cflags --libs gstreamer-app-1.0) -ldl
Can reproduce this issue on TX2 as well.
Observe no issues with stream and encoder until all the available memory is consumed and things start to crash randomly due to absence of available system memory.
Hi @DaneLLL,
I wasnāt able to reproduce it in r32.7.4.
The only difference is that Iāve had to use videotestsrc(it was eating memory on our r32.7.2 as well) instead of nvv4l2camerasrc since we have custom drivers and I would like to avoid re-compiling kernel for r32.7.4 and making new image as much as I can.
Iāll try bare r32.7.2 as well and will let you know the results.
One more observation as soon as I unplug HDMI cable from the r32.7.4 unit with test application running. Memory consumption starts to creep the same way as it does on 32.7.2 unit.
We are not using HDMI port by default, we have a DSI screen connected.
Could it be the contributing factor?
Update: Confirmed on 32.7.2 as long as I run the test app on HDMI screen standalone - there is no memory leak.
As soon as I disconnect HDMI screen with application running, memory leak shows up right away.
Can I make sure how did you run the APP?
Like is any librariy other than GStreamer required?
We are testing on TX2 with 32.7.4 and an e3333 camera, but we got GST_STATE_CHANGE_FAILURE error in the end.
Also want to know how did you record the memory usage to get the diagram.
Like is any librariy other than GStreamer required? - No, nothing else as you can see this only requires gstreamer g++ -Wall -std=c++11 test_leak.cpp -o test $(pkg-config --cflags --libs gstreamer-app-1.0) -ldl
Update: I was wrong about nvivafilter being the reason for memory leak.
Here is why.
Somehow removing of nvivafilter blocks (no errors it just gets āstuckā) 1 out of 3 pipelines randomly and that prevents memory leak from happening. Didnāt spot it before because it displays last frame and I had to put something active in front of camera to spot it. As Iāve mentioned above 2 pipelines do run without memory leaks.
Also want to know how did you record the memory usage to get the diagram. - Sure.
Script for plotting using gnuplot (you will have to install gnuplot) plot_memory.txt (206 Bytes)
Somehow it is related to DSI output? Probably - yes. DSI has 60 Hz refresh rate and HDMI monitor has 144Hz. When Iām running 3 pipelines simultaneously I do see frame drops on all nv3dsinks. Instead of 30 FPS I get only 20 which is 60 / 3 similar to this post:
And it also explains why everything works well with up to 2 pipelines, it is because we are requesting 30 fps and 60/2 = 30 so it can keep up with performance.
Is it all tied to the screen refresh rate?
If I fork pipelines like this:
Update:
Due to pipelines working correctly in separate processes and having memory leak only within single process.
Iāve searched the forum and found these 2 topics.
I did set nv3dsink sync=false and it fixed the memory leak issue. But it is not acceptable since recording is lagging behind up to couple of seconds in this case.
Splitting the pipelines into different processes is not an option as well because it will require huge amount of work and change of current architecture.
So it looks like all pipelines are sharing some kind of resource which degrades and lags behind as well as losing frames. In case of 3 pipelines within within the same process. And this lag happens only if DSI screen is enabled (60Hz), it doesnāt happen on the HDMI (144Hz) screen standalone.
Can you please make a summary of the current situation?
I think this paragraph is kind of contradicting with each other.
You said nvivafilter was not the reason for memory leak, but you also said moving it out from 1 of the 3 pipelines prevented memory leak?
How about the lag between DSI monitor/HDMI monitor?
I donāt quite get it. Is it about performance issue or also memory leak?
You said nvivafilter was not the reason for memory leak, but you also said moving it out from 1 of the 3 pipelines prevented memory leak?
You are partially correct. Moving nvivafilter out from all 3 pipelines solves memory leak, but introduces new issue - 1 out of 3 pipelines will be blocked. It is visible on nv3dsink output, it will display the last available frame and wonāt update. So it just āfixesā memory leak by introducing another issue.
How about the lag between DSI monitor/HDMI monitor?
Memory leak happens on 60Hz DSI monitor as well as degraded 20 fps performance on 3 pipelines.
Memory leak doesnāt happen on 144Hz HDMI monitor and all 3 pipelines are running at 30 fps.
I donāt quite get it. Is it about performance issue or also memory leak?
Memory leak is consequence of degraded performance.
Here is the summary:
3 pipelines running including nvivafilter on a 60 Hz DSI screen - each pipeline gets only 20 fps. Memory leak is present.
3 pipelines running without nvivafilter on a 60 Hz DSI screen. In this case one of the pipelines blocks randomly (I havenāt spotted this when Iāve opened the topic). The rest 2 pipelines run correctly at 30 fps each. No memory leak.
My assumption is:
Something in the pipeline is limited by 20 Hz refresh rate (probably nv3dsink) when running 3 pipelines at the same time within the same process on a 60Hz screen refresh rate. Throughput is throttled which leads to memory leak.
This issue is complex.
Sorry if something is not clear.
Please let me know if more clarification is needed.
I think it would be appropriate to change the title after we get to the root cause of the issue.
Sorry for coming back later. Thanks for the clarification.
However, sorry that we currently donāt have a DSI monitor for testing, so itās kind of hard to proceed on further debugging if it only happens on DSI monitors.
We are also loaded with other tasks, so please keep the HDMI monitor if it works fine, and weāll get back to you when we are available and when we get a DSI monitor for testing.
Unfortunately I canāt use HDMI monitor as a solution.
DSI is the primary monitor.
You donāt need a DSI monitor to reproduce the issue.
All you need is an HDMI monitor which supports 60Hz. I was able to reproduce the issue by switching HDMI monitor refresh rate to 1920x1080@60Hz instead of 1920x1080@144Hz.
A temporary workaround is to dynamically unlink then re-link nv3dsink branch when needed during runtime.
Our design allows such approach.
Looks like the root cause is that 3 instances of nv3dsink running simultaneously within the same app on a 60Hz refresh rate screen (doesnāt matter DSI or HDMI) canāt run faster than 20Hz, thus slowing down the whole pipeline. And side effect is a memory leak with the pipeline Iāve provided as a sample.
I think that title should be renamed, because nvivafilter is not the real memory leak cause.
I ran your code again on TX2+r32.7.4+e3333 camera, but I did not get anything from the camera on the screen.
I just had 3 windows showing the wallpaper; is that expected?
@DaneLLL
Iāve tested nveglglessink as requested. nvegltransform ! nveglglessink - exhibits the same behavior as nv3dsink. Missed frames and āchoppyā output.
Hi,
Please run sudo jetson_clocks and set sync=0 to nveglglessink and try. The steps run system in maximum performance mode and disable synchronization mechanism in gstreamer. May bring further improvement.
@DaneLLLsudo jetson_clocks and set sync=0 to nveglglessink. Fixes memory leak issue and āchoppinessā.
But it introduces new issue - almost 1 second lag, unfortunately it wonāt work in our case.