Repository navigation
Description
What happened?
What happened?
Syncthing crashed twice on a node with plenty of free RAM with fatal error: runtime: out of memory.
The root cause is not memory exhaustion but the per-process mapping limit (vm.max_map_count, default 65530):
the process accumulates tens of thousands of small anonymous mappings outside the Go heap, and when the Go
runtime later tries to grow the heap, mmap fails with ENOMEM.
Crash 1 (2026-09-30 00:50):
runtime: out of memory: cannot allocate 54525952-byte block (1037729792 in use)
fatal error: out of memory
→ a 52 MiB allocation fails with only ~1 GiB heap in use.
Crash 2 (2026-10-05 22:04, ~10.7 h uptime):
fatal error: runtime: out of memory
runtime.throw(...)
runtime.sysMapOS(0x3858b1000000, 0xc00000, ...) runtime/mem_linux.go:175
runtime.(*mheap).grow(...) runtime/mheap.go:1625
...
runtime.growslice(...)
github.com/syncthing/syncthing/lib/scanner.(*walker).walk.func1() lib/scanner/walk.go:160
→ a 12 MiB heap growth fails during a folder scan.
Both panic logs attached (also auto-submitted via crash reporting).
Evidence
Host: 12 GiB RAM, ~9 GiB available, vm.overcommit_memory=0, no cgroup/rlimit limits
(MemoryMax/LimitAS/LimitDATA=infinity), GOMEMLIMIT=4GiB.
Mapping count of the main syncthing process (~39 h uptime after crash 2):
$ wc -l /proc/$PID/maps
19682
Breakdown – Go-owned regions are labelled (Go ≥1.25 VMA names), only ~140 of them:
19532 [anon] <- unlabelled
140 [anon: Go: ...] (heap, gc bits, page alloc, immortal metadata, ...)
Size histogram of the unlabelled anonymous mappings:
18299 65536
1048 131072
69 196608
37 8192
35 8392704
23 262144
5 327680
3 524288
The binary is static (ldd: not a dynamic executable), so SQLite is modernc.org/sqlite. Its allocator
modernc.org/memory acquires memory "in 64 KiB units or, for larger allocations, in units rounded up to a
power of two" and retains empty regions – which matches the histogram exactly (~18.3k × 64 KiB ≈ 1.1 GiB).
Mapping count scales with database size / activity across our fleet (same version, same config):
node maps index-v2 size
fs01 19682 8.8 GB
app-c01 11764
fs02 10334 3.5 GB
dam01 6749
other nodes 2300-3900
idle/test 80-170
Expected behaviour
The SQLite allocator should not fragment the address space into tens of thousands of separate mappings
(or should cap/trim them), so that Syncthing does not hit the default vm.max_map_count and crash.
Workaround
sysctl vm.max_map_count=262144 – crashes have not recurred since, but we are monitoring whether the
mapping count keeps growing with uptime.
Version / platform
- Syncthing v2.1.5 "Hafnium Hornet" (go1.27.1 linux-amd64), official Debian package (apt, stable-v2)
- Ubuntu, kernel 6.8, VMware VM, ext4
- 1 folder, ~605k directories, 2 devices (LAN, TCP), fsWatcher enabled, rescanIntervalS=3600
- Transparent huge pages:
madvise
Possibly related (scan performance): #10869
Syncthing version
v.2.1.5
Platform & operating system
Linux Ubuntu 22.04
Browser version
No response
Activity
moerkey commentedon Oct 7, 2026
Follow-up after a service restart (14:19), same node:
So the mapping count is driven by scans (highest right after startup / initial scan), not by uptime.
27776 × 64 KiB ≈ 1.7 GiB, which matches the process memory not accounted for by the Go runtime
(RSS+swap − go_sys ≈ 1.7 GiB). This memory is outside GOMEMLIMIT and largely idle – the kernel
swaps ~800 MiB of it out during scan-induced page cache churn.
With the default vm.max_map_count=65530 a single startup already uses ~42 % of the limit.
calmh commentedon Oct 7, 2026
See if the build here helps, when it's done: https://github.com/syncthing/syncthing/actions/runs/37651073689
This would cause leaked SQLite memory; not specifically during scanning, but during index sending.
fix(sqlite): do not generate unbounded prepared statements (ref #10913)…
moerkey commentedon Oct 8, 2026
Baseline on v2.1.6 (released build, 6 h uptime): 26208 maps (25000 × 64 KiB ≈ 1.5 GiB),
go_sys 886 MiB, RSS+swap ≈ 2.6 GiB – same as 2.1.5. Now switching this node to the #10915 build.
moerkey commentedon Oct 9, 2026
Tested
v2.1.7-dev.3.gdf8d0d92(artifact from the linked run) on fs01 for 24 h, with fs02 on v2.1.6 as control(same folder, same data, syncing with each other). No measurable improvement on the test build.
Note: fs01 always has a higher count than fs02 (index 8.8 GB vs 3.5 GB). Comparing fs01 with itself:
The only API clients on these nodes are our monitoring scripts, which use fixed parameters
(
/rest/system/status,/rest/stats/folder,/metrics,/rest/folder/errors?folder=<id>without paging),so the unbounded-prepared-statement path is probably not what we're hitting. The growth is still almost
entirely 64 KiB mappings. Happy to run more diagnostics – what would be most useful
(STTRACE facility, support bundle, a specific debug endpoint)?
nosduco commentedon Oct 9, 2026
hey! seeing the exact same thing here, figured id add another data point.
running the official ghcr image as an always on hub in k8s (single node, talos), 2 folders, one desktop that syncs constantly and a laptop thats mostly offline. folder dbs are ~180MB and ~27MB. only thing hitting the API is the kubelet health check (
/rest/noauth/health) and me opening the gui every once in a while, so nothing with paging params either.on 2.1.5 it was getting OOMKilled at a 1Gi limit (4 times in like 12 days). bumped it to 2Gi and it just kept climbing, ~200MB -> ~1.1GB over 3.5 days. heap profile early on only showed ~20MB in the go heap while RSS was ~178MB, rest was all those anonymous mappings.
moved to 2.1.7-rc.1 yesterday (double checked the tag is the #10915 merge commit) and honestly no difference. working set since restart, roughly every 4h: 125 -> 304 -> 418 -> 494 -> 587 -> 658 MiB
at ~21h its 3075 mappings, 666MB RSS, basically all anonymous. ~3000 of the mappings are small regions that are all multiples of 64KB (64/128/192/256K etc, i think adjacent ones are just getting merged) and those hold ~611MB of it. go side is only ~38MB.
so same signature as @moerkey and same as them i dont think we're hitting the paging path. im not super caught up on the sqlite side of things but happy to run whatever would help (STTRACE, support bundle, a test build, etc) and report back!
moerkey commentedon Oct 13, 2026
Long-run data point from fs01, still on the #10915 build (
v2.1.7-dev.3.gdf8d0d92), now 5.2 days uptime:So roughly +0.5 GiB/day outside the Go heap, while the Go side is completely flat over 8 days
(only the hourly scan sawtooth, no upward trend – graph attached).
Size histogram of the unlabelled anonymous mappings now:
Compared to day 1 (18299 × 64 KiB, 1048 × 128 KiB) the distribution shifts towards larger multiples
of 64 KiB, which fits @'s observation that adjacent 64 KiB regions get merged – the
mapping count therefore grows slower than the memory.
Same signature as the k8s report above, on a very different setup (bare VM, 8.8 GB index, single
folder, ~605k dirs), and the only API clients are our monitoring scripts with fixed parameters.
I have heap profile, /proc//maps, smaps_rollup and a support bundle from this state and can
attach or send them if useful.
Merge branch 'main' into protovalidate
chore(deps): update syncthing/syncthing docker tag to v2.1.7 (#13)
docs: PATCHES.md/ISSUES.md currency pass
docs: PATCHES.md/ISSUES.md currency pass
FNJervis commentedon Nov 2, 2026
Edited 2026-11-08 — correction. My original comment blamed
modernc.org/sqlite. That was wrong, as pointed out below: the official binary is CGO +mattn/go-sqlite3. The root cause appears to be the C allocator that Zig links into the release builds.What the official v2.1.7 binary is:
go version -mshowsCGO_ENABLED=1,github.com/mattn/go-sqlite3 v1.14.52, statically linked.readelf -p .commentshowsclang version 22.1.8, which is the clang in Zig 0.17.0. The Linux release builds usezig cc -target <arch>-linux-muslwith an unpinnedsetup-zig, so they get the latest Zig.Why that matters: since Zig 0.16,
zig ccfor musl targets no longer uses musl's mallocng. It links Zig's ownlib/c/malloc.zig, a thin wrapper overstd.heap.SmpAllocator. Zig 0.15.2 still ships mallocng. MinGW targets are excluded, so Windows is not affected. InSmpAllocator:freepushes a block onto the free list of the slot held by the freeing thread, not the one that allocated it;alloctries one other slot (max_alloc_search = 1) before mapping a fresh 64 KiB slab;Under cgo, SQLite memory is routinely freed on a different OS thread than the one that allocated it, so freed blocks pile up on slots that rarely allocate that size, while other slots keep mapping new 64 KiB slabs. That matches the 64 KiB mapping histograms in this thread. Zig already tracks it: https://codeberg.org/ziglang/zig/issues/36969 (proposed fix https://codeberg.org/ziglang/zig/pulls/36294, still open;
SmpAllocator.zigis unchanged in 0.17.1 and on master).Evidence from our hub (official
syncthing/syncthing:2.1.7image, worker process, 8.5 days uptime): 29,375 mappings, 23,606 of them 64 KiB; 1.29 GiB anonymous resident + 2.07 GiB swapped; about 40 open SQLite connections in total, so not a connection leak. Reading those regions shows SQLite 4 KiB b-tree pages preceded by Zig malloc headers: qword0x44604decodes to alignment 16, size 4376 (SQLite's 4368-byte page slot plus its 8-byte size prefix).Minimal repro, no Syncthing: C program, one thread
malloc(4376), another threadfrees, at most 1,000 blocks in flight, statically linked:zig cc0.17.0,x86_64-linux-muslzig cc0.15.2,x86_64-linux-muslMy earlier comparison with the Arch package (154 mappings) is not meaningful by itself, since that build uses glibc, whose heap layout is entirely different. The relevant difference is the allocator.
Analysis done with AI assistance; every number above was measured on our own systems.
bt90 commentedon Nov 2, 2026
Our official docker binaries are built with CGO. We only ship binaries with modernc if the target platform isn't supported.
docs: PATCHES.md/ISSUES.md currency pass
docs: PATCHES.md/ISSUES.md currency pass