Syncthing uses too much RAM (killed by oom_reaper)

One of my systems (let’s call it “Q”) has 3GB RAM. It ran Syncthing just fine for months. A few days ago I’ve added a new device “N” to a big folder (500k files, 1.5k folders, 45GiB) that was previously only shared between “Q” & “L”. “Q” is configured as my introducer. “L” has 32GB RAM, “N” has 16GB - So I don’t see any issues on those.

Is there a way to constraint the memory usage of Syncthing in a way that prevents the system to become unresponsive for many minutes before the oom-killer kicks in and forces Syncthing to restart?

You can use some of the tuning options to reduce memory usage, and you can set GOMEMLIMIT to set a limit for how much the runtime should allocate: Configuration Tuning — Syncthing documentation

This looks like a good guide for my situation:

I did find “Max Concurrent Incoming Request Ki B” under Advanced → Options which I guess is the same as the mentioned maxConcurrentIncomingRequestKiB and set it to 32768.

I guess for the other’s I’ll have to find where the Debian packager has put the config file in the filesystem..

UPDATE: Is this the right file? /home/syncthing/.config/syncthing/config.xml

UPDATE2: I believe it is, since it contains this which is not the default value: <maxConcurrentIncomingRequestKiB>32768</maxConcurrentIncomingRequestKiB>

All the things are editable in the advanced dialog, except GOMEMLIMIT etc which are environment variables.

Okey, so to set one of those

  • STNORESTART=1
  • GOGC=25
  • GOMEMLIMIT=??

I need to make systemd pass those as environment variables?

If systemd is how you start Syncthing, yes, that sounds about right.

what unit is GOMEMLIMIT use? bytes? KiB? MiB? MB?

UPDATE: It seems it want’s a String that includes the unit. So I’ve added those lines:

Environment="STNORESTART=1"
Environment="GOMEMLIMIT=1GiB"

to /lib/systemd/system/syncthing@.service.

Let’s see how that behaves.

Changing all those settings helped! No more out-of-memory problems. I’ve actually lightened them up again by increasing maxFolderConcurrency from the suggested value 1 up to 2 because it annoyed me that it stopped handling all other folders when one large change requires long transfer times.

Just a side-note: You can also use a drop-in configuration for this, e.g. using systemctl edit syncthing@.service.