Skip to content

v2.1.5: "fatal error: runtime: out of memory" caused by hitting vm.max_map_count – ~19k 64 KiB anonymous mappings from the SQLite allocator #10913

Open

Description

@moerkey

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

Relevant log output

Activity

  1. added
    bug
    on Oct 7, 2026
  2. added theissue type on Oct 7, 2026
  3. added
    needs-triage
    on Oct 7, 2026
  4. moerkey commented on Oct 7, 2026

    @moerkey
    Author

    Follow-up after a service restart (14:19), same node:

    uptime 6764s (~1.9 h), folder still in initial/periodic scan
    maps        27776   (vs. 19682 after 39 h uptime before the restart)
    go_sys      853 MiB
    RSS + swap  1835 + 796 MiB ≈ 2.6 GiB
    

    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.

  5. calmh commented on Oct 7, 2026

    @calmh
    Member

    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.

  6. moerkey commented on Oct 8, 2026

    @moerkey
    Author

    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.

  7. moerkey commented on Oct 9, 2026

    @moerkey
    Author

    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.

    after ~24 h          fs01 (#10915 build)    fs02 (v2.1.6)
    maps                 29457                  18529
    go_sys               618 MiB                629 MiB
    RSS + swap           2486 + 897 MiB         868 + 930 MiB
    outside Go heap      ~2.7 GiB               ~1.2 GiB
    

    Note: fs01 always has a higher count than fs02 (index 8.8 GB vs 3.5 GB). Comparing fs01 with itself:

    fs01 version         uptime    maps
    v2.1.5               1.9 h     27776
    v2.1.6               6 h       26208
    #10915 build         24 h      29457
    

    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)?

  8. nosduco commented on Oct 9, 2026

    @nosduco

    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!

  9. moerkey commented on Oct 13, 2026

    @moerkey
    Author

    Long-run data point from fs01, still on the #10915 build (v2.1.7-dev.3.gdf8d0d92), now 5.2 days uptime:

                             ~24 h        ~5.2 d (450001 s)
    maps                     29457        37255
    unlabelled anon total    ~1.7 GiB     3794 MiB
    RSS + swap               3.3 GiB      3242 + 902 MiB ≈ 4.1 GiB
    go_sys                   618 MiB      630 MiB
    go_alloc                 400 MiB      374 MiB
    

    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:

    25042 × 64 KiB
     7736 × 128 KiB
     2670 × 192 KiB
     1028 × 256 KiB
      313 × 320 KiB
    

    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.

  10. added a commit that references this issue on Oct 18, 2026
  11. FNJervis commented on Nov 2, 2026

    @FNJervis

    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 -m shows CGO_ENABLED=1, github.com/mattn/go-sqlite3 v1.14.52, statically linked. readelf -p .comment shows clang version 22.1.8, which is the clang in Zig 0.17.0. The Linux release builds use zig cc -target <arch>-linux-musl with an unpinned setup-zig, so they get the latest Zig.

    Why that matters: since Zig 0.16, zig cc for musl targets no longer uses musl's mallocng. It links Zig's own lib/c/malloc.zig, a thin wrapper over std.heap.SmpAllocator. Zig 0.15.2 still ships mallocng. MinGW targets are excluded, so Windows is not affected. In SmpAllocator:

    • free pushes a block onto the free list of the slot held by the freeing thread, not the one that allocated it;
    • alloc tries one other slot (max_alloc_search = 1) before mapping a fresh 64 KiB slab;
    • small slabs are never unmapped.

    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.zig is unchanged in 0.17.1 and on master).

    Evidence from our hub (official syncthing/syncthing:2.1.7 image, 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: qword 0x44604 decodes 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 thread frees, at most 1,000 blocks in flight, statically linked:

    libc 200k rounds 2M rounds
    zig cc 0.17.0, x86_64-linux-musl 26,748 kB RssAnon 64,576 kB, still growing
    zig cc 0.15.2, x86_64-linux-musl 36 kB 44 kB
    glibc (dynamic) 252 kB 252 kB

    My 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.

  12. bt90 commented on Nov 2, 2026

    @bt90
    Contributor

    Our official docker binaries are built with CGO. We only ship binaries with modernc if the target platform isn't supported.

  13. added a commit that references this issue on Nov 4, 2026
  14. added a commit that references this issue on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds-triage

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions