Jump to content

Memory leak/issue


Recommended Posts

quickmic
Posted (edited)

I was chasing a memory leak on Kodi for almost 3 days and wanna share my results:

As I started Kodi tests with my Raspberry Pi 5 (8GB) ram I was wondering why this device uses all the memory.

I tracked it down to skin/widget refreshes means, by trigger a library update. More and more ram was consumed and never released.

Also each playback start/stop triggers a skin refresh and memory usage was increasing even more till a point Kodi crashed.

First thought was a bug in Kodi/images, so I tried libreelec and Xbian which are the only available images for RPI 5, but no difference.

I uninstalled every plugin, every dependency, even build in addons and stripped down Kodi to bare minimum, still no difference.

As I never experienced this issue on my other boxes (vero 5 and osmc), I started thinking what could be the difference.

First clue was, osmc is an 32bit OS, so I tired libreelec in 32bit, but turns out this 32bit images still seems to uses the 64 bit kernel, but 32bit Kodi application.

Digging deeper and deeper, I started reviewing the glibc parameters. Turns out, the MALLOC_ARENA_MAX seems the key to success (at least for now).

https://www.gnu.org/software/libc/manual/html_node/Memory-Allocation-Tunables.html

On 32bit OS the MALLOC_ARENA_MAX is by default 2 times the cores = 8 on a 4 core system.

On 64bit OS it's 8 times cores = 32

As I started lower MALLOC_ARENA_MAX=1 via env parameters (as a test) I immediately realized the difference. Ram usage was down to a bare minimum and never grows again.

However, MALLOC_ARENA_MAX=1 is not optimal for performance, currently I'm testing MALLOC_ARENA_MAX=16 on my RPI 5 with libreelec and seems to work quite good. Highest mem usage is currently 4.7GB.

Anyway, if you experience same memory leaks, give it a try:

In libreelec you can adjust the parameter here:

/storage/.config/kodi.conf

and add this line

MALLOC_ARENA_MAX=16 also crashed

MALLOC_ARENA_MAX=8

same as on 32bit os seems to work

Edited by quickmic
  • Like 1
quickmic
Posted

Xbian:

/etc/init/xbmc.conf

replace "env MALLOC_MMAP_THRESHOLD_=65536"

with "env MALLOC_MMAP_THRESHOLD_=8192"

and add

"env MALLOC_ARENA_MAX=8"

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...