You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Excessive RAM usage when syncing large folders #4976
When syncing we build a queue of the files to sync, then sort it according to the desired criteria (size, time, random, etc.). For millions of files this can use a lot of RAM. In some cases we don't really care too much about the exact order and it would be better to use less RAM. For this, we could have a limit on the queue size. When doing a pull and iterating over the database / need list, we stop iterating once the limit is reached. The pull proceeds as normal. When complete, we do another pass and grab more needed files, repeat until done.
Reacted by NickMa, Ian Colwell, Raphaël Jungers, TheOneValen, Starbeamrainbowlabs, Ondřej Molík, Janek, Chih-Hsuan Yen, pravorskyi, gurkov and 2 more
I think this will come with a slight disadvantage in terms of renames?
I have a almost finished (pre-polish) branch where I implement disk-spilling slices and maps to restrict RAM usage (for both scanning and pulling). I already started working on it before you posted on the forum, that you consider that overkill (from memory, maybe it was something else). Would such an option be considered, i.e. should I invest some more time to roughly finish it for review?
Yeah it would make us miss renames if there are a lot of changes and the split happens between the files. I guess that would happen if a large directory is renamed for example.
I guess disk spilling is fine too - but there's a lot of special case sorting etc going on for the pulling. I guess we can implement sort.Interface on top of them. Are they FileInfo (FileIntf?) specific or is there a lot of type assertion going on?
Shows nothing to compare. anyways, the crux of the rename problem comes from scans, and we should fix it there. Disk spilling thing will solve that hopefully, and then we can augment the puller to support that.
I updated the links (and wrote to github support, something is broken here). Anyway, the takeaway for me is that a disk-overflow type is probably good to have mid to long term, but this issue can be solved quickly without it - i.e. it's worth cleaning up for preliminary review, but no rush.
@imsodin was looking at your branch but there's no definition for Value, I think checking is missing a file or so? This is kind of central as it defines how to interact with this thing :)
I indeed forgot to git add a crucial file - symptom of hardly writing any original code at all :)
I cleaned it up and filed a (wip) PR, referencing a branch is too cumbersome: #4980
Did this fix make it into syncthing yet? Definitely would love to use this feature as I am currently experiencing excessive RAM usage and don't know how else to limit the RAM.
I may also be affected by this issue. I'm syncing a folder of 114GB, containing about 8k files. Memory usage on a NAS is maxing out at 1GB. I feel this is definitely too much for 8k files. Has this been merged into master? Is there a flag I need to set somewhere, to limit the queue size?
I also don't know if this is my issue, but I'm also having RAM issues, with very large temporary spikes. On a 4GB Raspberry pi 4 running nothing but syncthing and a tmux remote console session, it is crashing:
runtime: out of memory: cannot allocate 40370176-byte block (2855698432 in use)
fatal error: out of memory
Most of the time when I check it is using less than a GB of RAM. I have the order for all folders on this device set to "random" so I would expect it not to do any sorting, but the first post above implies that it actually does a sort when "random" is selected? Can it just skip the sort on "random", if this could be contributing to this issue?
I think I have the same issue, on my machine Syncthing used more than 4GB of RAM and made the full system unresponsive. I was syncing a folder of 200GB with mainly 4GB files (50files total). I have other shares but there was no activity on them at the time, and usage is back to 500MB now.
I'm actually still having the issue with the database tuning set to small.
It's happening every time I'm syncing a bunch of ~4GB files on my local 1Gb/s network.
AFAIK it wasn't happening before version 1.3.0 and I was already syncing the same folder.
I completely forgot about the comments in this issue. I am fairly sure it is completely unrelated to the original issue in this thread, but a problem with our pooling in the protocol package, which was not noticeable until a change in go1.13 (or our package is fine, and there is a regression in go1.13, but I'd expect it's our package).
Pretty sure I've also hit this - in trying to convert a periodic rsync between one primary and two copies to syncthing, and having to stop syncthing due to memory usage (it reached 16.3g VIRT 10.2g RES)
The single folder to sync had:
39,978 directories
17,897,687 files
1.2TB usage
It counts up to 31,999 directories, then the status remains unchanging while the memory usage keeps climbing. I've tried setting caseSensitiveFS true without apparent effect.
I have syncthing in use in a couple of other cases - but with nothing like the number of files the largest having filers including (10.5TB, 377 directories, 21,231 files) and (0.5TB, 3,816 directories, 49,906 files) and with a steady state of ~1GB SIZE and ~280MB RES. Those are under NetBSD, and the new setup is under Linux, but I don't think the OS is likely to be relevant here.
Going to try to break it down into subfolders and then try to boostrap the sync of each in turn to see if that avoids the issue
I think I've stumbled upon this issue with Syncthing on ZFS scanning a lot of tiny files in one share (~600GB in total). There's about 6GB free memory when Syncthing isn't running on average, but Syncthing gets OOM killed. Probably because ARC cache (which Syncthing starts to inflate) isn't freed quickly enough? Maybe it would be possible to have a special mode to do things slower but avoid using a lot of memory that could lead to an OOM condition?
@hohmd
That's scanning not syncing, and there are knobs to reduce/remove that memory usage. However the issue tracker isn't the place for questions/support. Please use the forum - https://forum.syncthing.net/ - for support, first by searching for any similar issues and then by posting a new one when required. The forum has a lot more eyes and friendly people on it than the issue tracker.
I faced the same problem with large folders so the service was freezing at 700MiB docker container limit and abusing storage intensively. After upgrading the syncthing image to make sure it was compiled with go 1.19 I added GOMEMLIMIT environment variable and set desired soft memory limit. After that it works just fine without any noticeable performance impact. Feels like I can freely put much lower values like 128MiB, but I haven't fully tested that yet, since I'm totally fine with 512.
I believe for older syncthing versions compiled with Go prior to 1.19 as a workaround you can experiment with values for GOGC. The lower (try 10-20) the less memory consumption will be but the more frequently garbage collector will be invoked which may hit the performance on too low values.
Activity
imsodin commentedon May 30, 2018
I think this will come with a slight disadvantage in terms of renames?
I have a almost finished (pre-polish) branch where I implement disk-spilling slices and maps to restrict RAM usage (for both scanning and pulling). I already started working on it before you posted on the forum, that you consider that overkill (from memory, maybe it was something else). Would such an option be considered, i.e. should I invest some more time to roughly finish it for review?
calmh commentedon May 30, 2018
Yeah it would make us miss renames if there are a lot of changes and the split happens between the files. I guess that would happen if a large directory is renamed for example.
I guess disk spilling is fine too - but there's a lot of special case sorting etc going on for the pulling. I guess we can implement sort.Interface on top of them. Are they FileInfo (FileIntf?) specific or is there a lot of type assertion going on?
calmh commentedon May 30, 2018
I have the implementation for this done and it's small :)
imsodin commentedon May 30, 2018
Ok, then probably don't delay for my stuff, because merging till next Tuesday is hardly realistic.
I probably shouldn't start describing it too much, that would just cause confusion. The caller needs to pass a type implementing an interface defined by the disk spilling code. I pushed the code if you want to have a quick look at it, interfaces should be final. However please do not judge that code (nor commit history), it was never meant to be public in this form x)
Value: https://github.com/imsodin/syncthing/blob/diskOverflow-nextgen/lib/diskoverflow/common.go#L19SortValue: https://github.com/imsodin/syncthing/blob/diskOverflow-nextgen/lib/diskoverflow/sorted.go#L36The following links are broken (left here for Github support ;) ):
Value: master...imsodin:diskOverflow-nextgen#diff-8d3f8add196bc2edef7d73cdf08e37daR41SortValue: master...imsodin:diskOverflow-nextgen#diff-c7f82e327453e4ad6fde542f76465758R59And there is a predifened type fulfilling the interface for file infos.
AudriusButkevicius commentedon May 30, 2018
Shows nothing to compare. anyways, the crux of the rename problem comes from scans, and we should fix it there. Disk spilling thing will solve that hopefully, and then we can augment the puller to support that.
imsodin commentedon May 31, 2018
I updated the links (and wrote to github support, something is broken here). Anyway, the takeaway for me is that a disk-overflow type is probably good to have mid to long term, but this issue can be solved quickly without it - i.e. it's worth cleaning up for preliminary review, but no rush.
calmh commentedon Jun 1, 2018
@imsodin was looking at your branch but there's no definition for
Value, I think checking is missing a file or so? This is kind of central as it defines how to interact with this thing :)lib/config, lib/model: Limit size of puller queue (fixes syncthing#4976)
imsodin commentedon Jun 1, 2018
I indeed forgot to
git adda crucial file - symptom of hardly writing any original code at all :)I cleaned it up and filed a (wip) PR, referencing a branch is too cumbersome: #4980
icolwell commentedon Mar 11, 2019
Did this fix make it into syncthing yet? Definitely would love to use this feature as I am currently experiencing excessive RAM usage and don't know how else to limit the RAM.
sifourquier commentedon May 7, 2019
Hi
I think i have a bug due to this issue
I syncronise the source of QT and syncthing use 13G ram (i have 16G ram)
wiwie commentedon Oct 18, 2019
I may also be affected by this issue. I'm syncing a folder of 114GB, containing about 8k files. Memory usage on a NAS is maxing out at 1GB. I feel this is definitely too much for 8k files. Has this been merged into master? Is there a flag I need to set somewhere, to limit the queue size?
jeffbl commentedon Oct 24, 2019
I also don't know if this is my issue, but I'm also having RAM issues, with very large temporary spikes. On a 4GB Raspberry pi 4 running nothing but syncthing and a tmux remote console session, it is crashing:
runtime: out of memory: cannot allocate 40370176-byte block (2855698432 in use)
fatal error: out of memory
Most of the time when I check it is using less than a GB of RAM. I have the order for all folders on this device set to "random" so I would expect it not to do any sorting, but the first post above implies that it actually does a sort when "random" is selected? Can it just skip the sort on "random", if this could be contributing to this issue?
Leicas commentedon Oct 24, 2019
I think I have the same issue, on my machine Syncthing used more than 4GB of RAM and made the full system unresponsive. I was syncing a folder of 200GB with mainly 4GB files (50files total). I have other shares but there was no activity on them at the time, and usage is back to 500MB now.
10 remaining items
Leicas commentedon Nov 4, 2019
I'm actually still having the issue with the database tuning set to
small.It's happening every time I'm syncing a bunch of ~4GB files on my local 1Gb/s network.
AFAIK it wasn't happening before version 1.3.0 and I was already syncing the same folder.
imsodin commentedon Nov 4, 2019
I completely forgot about the comments in this issue. I am fairly sure it is completely unrelated to the original issue in this thread, but a problem with our pooling in the protocol package, which was not noticeable until a change in go1.13 (or our package is fine, and there is a regression in go1.13, but I'd expect it's our package).
Please do not respond to this issue about the recent memory usage problem, but use the following forum thread: https://forum.syncthing.net/t/large-mem-usage-on-sync-regardless-of-db-tuning/14015
I intend to investigate further in the near future and open a ticket once the problem is located.
Fix bufferpool puts (ref syncthing#4976)
Fix bufferpool puts (ref #4976) (#6125)
Merge branch 'master' into dbastr3
Merge branch 'dbastr3' into badger
abs0 commentedon May 3, 2022
Pretty sure I've also hit this - in trying to convert a periodic rsync between one primary and two copies to syncthing, and having to stop syncthing due to memory usage (it reached 16.3g VIRT 10.2g RES)
The single folder to sync had:
It counts up to 31,999 directories, then the status remains unchanging while the memory usage keeps climbing. I've tried setting caseSensitiveFS true without apparent effect.
I have syncthing in use in a couple of other cases - but with nothing like the number of files the largest having filers including (10.5TB, 377 directories, 21,231 files) and (0.5TB, 3,816 directories, 49,906 files) and with a steady state of ~1GB SIZE and ~280MB RES. Those are under NetBSD, and the new setup is under Linux, but I don't think the OS is likely to be relevant here.
Going to try to break it down into subfolders and then try to boostrap the sync of each in turn to see if that avoids the issue
Thanks
David
AudriusButkevicius commentedon May 3, 2022
You might also want to disable progress updates (check the docs how)
calmh commentedon May 4, 2022
@abs0 If you see an issue and can reproduce it, take a heap profile (https://docs.syncthing.net/users/profiling.html) and we can look at it. This issue, as originally described at least, is really about the case where we do an initial sync of a gazillion files, which doesn't sound like what you're doing.
Avamander commentedon May 29, 2022
I think I've stumbled upon this issue with Syncthing on ZFS scanning a lot of tiny files in one share (~600GB in total). There's about 6GB free memory when Syncthing isn't running on average, but Syncthing gets OOM killed. Probably because ARC cache (which Syncthing starts to inflate) isn't freed quickly enough? Maybe it would be possible to have a special mode to do things slower but avoid using a lot of memory that could lead to an OOM condition?
calmh commentedon May 29, 2022
Again, as noted above, a memory profile would help narrow down what you're suffering from.
imsodin commentedon May 6, 2023
@hohmd
That's scanning not syncing, and there are knobs to reduce/remove that memory usage. However the issue tracker isn't the place for questions/support. Please use the forum - https://forum.syncthing.net/ - for support, first by searching for any similar issues and then by posting a new one when required. The forum has a lot more eyes and friendly people on it than the issue tracker.
Thanks!
nazar256 commentedon Jun 28, 2023
I faced the same problem with large folders so the service was freezing at 700MiB docker container limit and abusing storage intensively. After upgrading the syncthing image to make sure it was compiled with go 1.19 I added
GOMEMLIMITenvironment variable and set desired soft memory limit. After that it works just fine without any noticeable performance impact. Feels like I can freely put much lower values like 128MiB, but I haven't fully tested that yet, since I'm totally fine with 512.I believe for older syncthing versions compiled with Go prior to 1.19 as a workaround you can experiment with values for
GOGC. The lower (try 10-20) the less memory consumption will be but the more frequently garbage collector will be invoked which may hit the performance on too low values.gaby commentedon Apr 14, 2026
We are running into this issue too. We have one syncthing container per NAS, and they start using 20-30GB of RAM each.
Using latest v2 release as of today