Can restic avoid OOM

As the title show, when restic backup volumes, can it avoid OOM when my machine’s memory is not enough? Which may just slow down the backup, but eventually the backup is successful.

You can set the environment variable GOGC=10 or even a lower value to let go garbage-collect memory more aggressively. If you’re not already using restic 0.11.0, upgrade the restic version! There have been a few improvements in memory usage since 0.9.6. The slowest option is probably to increase the amount of swap for that machine.

However, I have to add a warning: Expect that restore and other commands require more memory than the backup command. Make sure to test that you are actually able to restore your backup.


Are you asking generically about running out of memory, or about the Linux OOM killer? 'cause there are also configuration knobs on that which might help the restic process survive.

Yes, i just want my restic process survive when i backup or restore but the memory is not enough.If the config of memory is effective may help for me.

Linux provides a way to adjust how likely the OOM killer is to take any given process. How to use it depends on how you’re starting the backup process. The tunable is oom_score_adj, and there is a command line utility (choom) to change it. systemd unit files have a directive to set it, OOMScoreAdjust.

(Edited to add:)
You should, however, be careful, especially if you’re running into memory problems with restic as the only serious load on a system.

Or “disable” the OOM killer by adding the following to /etc/sysctl.conf and rebooting:

vm.overcommit_memory = 2
vm.overcommit_kbytes = 0

Instead of rebooting you can run the following commands which should apply the same settings on the running system:

sysctl vm.overcommit_memory=2
sysctl vm.overcommit_kbytes=0

I use restic as a kubernete pod, and limit the pod’s memory a specific value. Thus, when the pod’s memory is not enough, i hope the restic process should still alive.
In fact, can we add a config, may called –limit-memory, like –limit-download and –limit-upload to limit the memory when we use restic backup or restore.

Implementing a --limit-memory option would require a fundamental redesign of the index data structures (and the on-disk cache format) so that won’t happen anytime soon.

I set GOGC=20 on my system and load / memory issues have disappeared and backup tasks take exactly the same amount of time as before.

1 Like

So, i should control memory resource myself.
Thx, it’s very helpful for me.