ValheimCommunityPatchGC
Garbage collector tuning for Valheim dedicated servers: a pre-grown mark stack against 'Unexpected mark stack overflow' crashes, plus optional collector settings. Companion to Valheim Community Patch.
模組介紹 作者原文
Valheim Community Patch GC
Garbage collector tuning for Valheim dedicated servers, a companion to
Valheim Community Patch.
It shipped inside the Community Patch in 0.31.0 and moved out in 0.32.0. Reaching the collector's
settings means reading and writing the Mono runtime's own memory, which malware scanners flag, and
that should not weigh on a mod every player installs. This plugin needs only BepInEx.
What it does
Dedicated servers only; clients and listen hosts ignore it. Valheim runs Unity's incremental
garbage collector, and on a busy server each collection ends in one stop-the-world pass with no
time limit. On a large world that pass measured about 55 ms per GB of heap: 330 ms at 6 GB, 460 ms
at 8.4 GB. A bigger heap also means fewer collections, so the total time paused stays about the same
whatever the heap size. The same collection pass is where a large server can abort with
Unexpected mark stack overflow.
The settings live in the Server - Garbage Collector section of
BepInEx/config/MidnightsFX.ValheimCommunityPatchGC.cfg. Only the mark stack setting is on by
default; setting any of them to 0 gives back the game's own value.
- GC Mark Stack Target Entries (Linux), default 4194304 (64 MiB) — grows the collector's mark
stack ahead of need. The collector normally grows it only after a pass that nearly overflowed it,
and a pass that does overflow it aborts the server.
- GC Free Space Divisor (Linux), default 0 (the collector's own 3) — how far the heap grows
between collections. It trades pause length against frequency: lower gives fewer, longer pauses
and uses more memory; higher gives shorter, more frequent ones.
- GC Time Slice Milliseconds, default 0 (the game's 3 ms) — the incremental collector's
per-frame budget. On a busy server it did not change the pauses; a longer slice only lengthens
the short pause that opens each collection.
The divisor and the mark stack reach the collector through symbols only the Linux server runtime
exports; on a Windows server they do nothing.
Console command
vcp_gc prints the collector's current state: whether it is incremental, the time slice as Unity,
Mono and the collector each see it, the divisor, the heap, the last rescan's dirty pages and the
mark stack. It also changes each setting live, so the effect can be watched on a profiler:
- vcp_gc slice, vcp_gc divisor, vcp_gc markstack — set and save a value;
0 restores the game's own.
- vcp_gc stats on|off (Linux) — the collector's own log: a few lines per collection with its
stop-the-world times and how much it rescanned. It goes to the server's standard error (or
GC_LOG_FILE, if that was set when the server started), not to the BepInEx log. Not saved.
An admin can run it remotely from their own console; that needs this plugin installed on their
client too, where it does nothing else. The replies are written to the server log.
Installation
Install it on the dedicated server with a mod manager, or drop ValheimCommunityPatchGC.dll into
BepInEx/plugins. It requires BepInEx
and is packaged with Valheim Community Patch 0.32.0 or later as a dependency. With Community Patch
0.31.x, which has its own copy of these settings, it logs a warning and does nothing.
Settings changed in the Community Patch 0.31.0 config are not carried over; set them again in this
plugin's config. The Community Patch's old Server - Garbage Collector section can be deleted.
Credit and sources
- bdwgc and Unity's fork of it and of Mono — the collector's
source is the reference for these settings; no code was used.
- Iron Gate Studio — Valheim itself; no game code is redistributed.
安裝與使用 安裝:BepInEx 外掛
- 本站下載的壓縮包就是模組本體,通常是 BepInEx 外掛(解壓後得到 .dll 或外掛資料夾)。
- 建議流程:用社群模組管理器(如 r2modman)選中本遊戲後匯入該模組,管理器會自動裝好 BepInEx 前置並處理依賴。
- 手動流程:先在遊戲目錄裝好 BepInEx 載入器,再把解壓出的 .dll 或外掛資料夾放進 BepInEx/plugins/。
- 啟動遊戲,BepInEx 控制台會列印載入日誌;確認這個模組出現在日誌裡即為安裝成功。
帶「前置依賴」的模組需要一併安裝,否則不會載入。功能開關通常在遊戲內或外掛自帶的設定檔裡調整。 多人連線時,主機與所有用戶端需要安裝一致的模組。
下面這些內容需要先安裝,否則該模組不會生效: