Project

General

Profile

How to reduce RAM usage

Added by M. Reimer 2 months ago

Hello,

I've set up tvheadend on an Raspberry Pi 4 with 2GB of RAM.

This setup runs for a few weeks and then dies because of RAM shortage. Seems like this causes EPG data corruption if it happens.

How can I reduce tvheadend's RAM usage?

The setup accesses two satellite positions including UK channels (but without EPG beyond "now" and "next" as I never managed to set this up properly for UK channels)

Thanks for any help


Replies (8)

RE: How to reduce RAM usage - Added by Dave Pickles 2 months ago

TVheadend should not be using anything like 2Gb of memory. My Pi2 has DVB-T and DVB-S tuners and is currently using 19Mb.

If you look on the GUI at Configuration ->Debugging -> Memory Information Entries there may be a clue where the memory is going.

The only memory problem I have seen was due to a faulty USB-SATA interface which meant that the disk couldn't keep up with the incoming data stream. The "Packet Buffers" count increased until the Pi ran out of memory.

To get the EPG for UK Freesat you just need to tune to mux 11428H with the "UK Freesat" and "UK Freesat (EIT) grabbers enabled.

RE: How to reduce RAM usage - Added by M. Reimer 2 months ago

Seems like RAM is filling again after pretty short time. Maybe someone can help me with finding out what is happening here.

After rebooting we had about 1,5GB of RAM free. Now after about 3 days we are down to 32MB again.

I've attached two screenshots. One taken directly after booting and the second taken 3 days after reboot.

What can I check next?

As far as I know there is no recording running but one client is connected for live streaming of TV.

For the case it makes any difference: All tuners are connected via minisatip.

after_3_days.jpg (153 KB) after_3_days.jpg Screenshot after 3 days of runtime
after_boot.jpg (98.5 KB) after_boot.jpg Screenshot directly after booting

RE: How to reduce RAM usage - Added by M. Reimer 2 months ago

And here a "top" screenshot sorted by memory usage. You can see that there are only 49MB free but most of the used memory seems to be "virtual" for some reason...

top.jpg (277 KB) top.jpg

RE: How to reduce RAM usage - Added by Hiro Protagonist 2 months ago

That all looks normal enough to me. Linux will use all available RAM for buffer & cache. Your TVHeadend RAM usage is less than 10%.

If you're using ffmpeg for transcoding, that can eat a chunk of RAM, but only while ffmpeg is running.

You should configure some swap - on spinning rust rather than SD, that will allow processes that aren't in use to swap out their memory, maximising available RAM.

RE: How to reduce RAM usage - Added by paul griffiths 2 months ago

I am seeing something similar on my 2 tvHeadends running T230 DVB-T2. I started monitoring swap with nodered, see the attached graph.

The series are:
blue: a pi4 running tvheadend (in docker)
red: a pi3 running tvheadend as a SAT>IP server to blue (in docker)
green: a pi3 running motioneye (in docker)

The EPG is being downloaded at 2:00 and 14:00 and you can see an increase in swap usage while its being processed at around 2:30. A similar reduction is seen while playing recorded programs with kodi on the pi4 at around 22:00 to 22:30.
Although not significant at this time swap usage accumulates over time and reboot needed about once a week.

The situation was significantly worse when running 2 tuners on one pi4.

swap.JPG (31.5 KB) swap.JPG swap usage

RE: How to reduce RAM usage - Added by saen acro 2 months ago

Pseudo virtualisation need extra memory with you dont have.
Run tvh nativly

Why not schedule

sync && echo 3 > /proc/sys/vm/drop_caches

5 min before epg start?

RE: How to reduce RAM usage - Added by M. Reimer 2 months ago

Interesting to see that there is at least one other user with the same problem.

I could place swap on the HDD of course. This could "buffer" high memory requirement spikes but doesn't help if swap usage just keeps rising.

Currently the situation is still stable but I'll post screenshots again this sunday.

Maybe I'll just try setting up the server with VDR. I guess VDR may be more resource friendly.

RE: How to reduce RAM usage - Added by Dave H 2 months ago

M. Reimer wrote:

And here a "top" screenshot sorted by memory usage. You can see that there are only 49MB free but most of the used memory seems to be "virtual" for some reason...

You don't seem to understand how linux works. There's nothing to worry about there. What is the actual problem you are experiencing?

    (1-8/8)