elementary / appcenter

Pay-what-you-can app store for elementary OS
https://elementary.io
GNU General Public License v3.0
543 stars 101 forks source link

Valgrind/massif suggests libostree is allocating (and probably leaking) significant memory #1507

Open ids1024 opened 3 years ago

ids1024 commented 3 years ago

I've been looking into memory consumption for Pop!_OS's fork of Appcenter (https://github.com/pop-os/shop/issues/257). I haven't done any profiling on Elementary, but I'd be interested to know if the results are similar.

The output from Valgrid's massif tool seems interesting:

Screenshot from 2021-03-31 08-14-06

Screenshot from 2021-03-31 08-33-32

I'd need to do more testing and get more familar with massif to understand if this 879.8 MiB is (largely) leaked, but it seems considerable for even peak memory consumption from that library.

This seems to indicate that most of the excessive memory consumption we've been seeing with Pop Shop (and presumably Appcenter) is allocated by libostree, a dependency of libflatpak. It may not be well tested for long running applications.

This Gnome Software issue looks like they may have a similar problem.

Steps to Reproduce

  1. Build Appcenter.
  2. Run valgrind --tool=massif --depth=5 --alloc-fn=g_malloc --alloc-fn=g_realloc --alloc-fn=g_try_malloc --alloc-fn=g_malloc0 --alloc-fn=g_mem_chunk_alloc build/src/io.elementary.appcenter (as suggested in Gnome Optimization Guide).
  3. Run for a while allowing memory consumption to grow. Doing a few things (with painfully slow response due to valgrind). Exit.
  4. Use massif-visualizer to display results.

Platform Information

Compiled from 42320e94c534531a16803805999f98603eae38d9 on Pop!_OS 20.10, with libostree 2020.6-1 and libflatpak 1.8.5-1pop1~1612228017~20.10~7ba959a.

tintou commented 3 years ago

Have you used G_SLICE=always-malloc when using valgrind ? also there is a suppression file for GLib at /usr/share/glib-2.0/valgrind/glib.supp