Our server held 9.36 GiB of RAM to use 3
WorkedThe club's Project Zomboid server was using nearly all the machine's RAM. We traced where it went, tried five Java settings on a copy of the server, then changed the live one without touching how the game plays.
Problem
The club's Project Zomboid server (Build 42.21, 144 mods) runs on the owner's Linux machine with 13.6 GiB of RAM and 8 CPU threads. With 5 players on, the game held 9.36 GiB, leaving the machine about 3 GiB free, and other game servers are meant to share it.
9.36 GiB
- Data the game uses
- Held by ZGC, unused
- Outside the heap, and files
See the numbers as a table
| GiB | % | |
|---|---|---|
| Data the game uses | 2.96 | 32 |
| Held by ZGC, unused | 4.62 | 49 |
| Outside the heap, and files | 1.79 | 19 |
The CPU, meanwhile, sat mostly idle: the game runs on one main thread, and the whole process used less than one core of the eight threads. So the goal: use less RAM without changing how the game plays; spending more CPU is fine.
Hypotheses
- FalseThe mods eat the RAM
The server-side Lua of all 144 mods adds up to 5.3 MiB, and every Lua table in the heap together is about 130–170 MiB out of 2.96 GiB in use.
- TrueJava’s garbage collector keeps far more memory than the game uses
ZGC held 7.58 GiB; after a collection the game was using 2.96 GiB.
- TrueA different collector can trade the idle CPU for RAM without making the game stutter
The game went down to 2.6–3.3 GiB for about 0.3–0.5 of a core more CPU; the longest GC pause was 0.9 ms, and none of the 6–8 players reported lag.
Analysis
We measured the live server while people played, without a restart: the process memory map from /proc and pmap, then Java’s jcmd for the heap and a count of the objects still in use, and a 15-minute JFR (Java Flight Recorder) recording.
- ZGC held a 7.58 GiB heap. In 15 minutes it collected 4 times: 5.8–7.6 GiB before, 3.0–3.1 GiB after, never pausing the game for more than 0.067 ms.
- The game makes garbage slowly, about 16–22 MiB a second, so collecting more often costs little.
- ZGC always uses 8-byte references (no compressed oops), so every field pointing at another object is twice what other collectors can use.
- Another 1.73 GiB lives outside the heap; 1.55 GiB of it is glibc malloc spread over more than 70 heaps, which keep freed memory instead of returning it. One jcmd System.trim_native_heap gave back 1,050 MiB on the spot, no restart.
- The biggest objects are the game's own: animation keyframes 437 MiB, world objects in the loaded area 213 MiB and map squares 137 MiB, text and buffers 286 MiB.
- Two wasteful spots in the game’s code: the vehicle network sound manager rebuilds a set every tick, 82.7% of the sampled garbage, and the on-start backup keeps its list of 140,252 files, about 53 MiB, after it finishes.
- Data in use
- Garbage waiting
- RAM held
- Collector at work (other threads)
- ZGC
- Shenandoah + compact headers
Keyframeanimation pose56 → 32 byte43% smallerLinkedHashMap.Entrya slot in a Lua table56 → 32 byte43% smallerStringtext32 → 24 byte25% smallerQuaternionrotation32 → 24 byte25% smallerVector3fno references24 → 24 byteSame
See the numbers as a table
| ZGC | Shenandoah + compact headers | |
|---|---|---|
| Keyframe (animation pose) | 56 | 32 |
| LinkedHashMap.Entry (a slot in a Lua table) | 56 | 32 |
| String (text) | 32 | 24 |
| Quaternion (rotation) | 32 | 24 |
| Vector3f (no references) | 24 | 24 |
Method
We tried it on a copy first: a Project Zomboid server on the owner’s PC with the same 144 mods and config files (a new world, no players, no Steam, closed to outsiders), started with 5 Java settings. Each was measured 90 seconds after start: the process RAM, the heap held, and the data still in use after a forced collection.
| Set | Java settings |
|---|---|
| A | ZGC as the game ships it (what the server ran) |
| B | Shenandoah in compact mode + compact headers + string dedup |
| C | ZGC + compact headers + string dedup + SoftMaxHeapSize 2 GiB |
| D | G1 + compact headers + string dedup |
| E | Shenandoah with its defaults |
The best set went onto the live server at its scheduled 19:00 restart, with the old settings file kept for a rollback and a GC log switched on to catch any stutter.
Results
- Process RAM
- Data in use
MiB
See the numbers as a table
| Data in use (MiB) | Process RAM (MiB) | |
|---|---|---|
| A · ZGC | 1,196 | 6,390 |
| E · Shenandoah | 917 | 5,156 |
| C · ZGC + SoftMax | 1,089 | 3,338 |
| D · G1 | 834 | 2,460 |
| B · Shenandoah compact | 806 | 1,274 |
| Set | Data in use | Heap held | Process RAM |
|---|---|---|---|
| A · ZGC | 1,196 MiB | 5,932 MiB | 6,390 MiB |
| B · Shenandoah compact | 806 MiB | 834 MiB | 1,274 MiB |
| C · ZGC + SoftMax | 1,089 MiB | 1,986 MiB | 3,338 MiB |
| D · G1 | 834 MiB | 2,016 MiB | 2,460 MiB |
| E · Shenandoah | 917 MiB | 966 MiB | 5,156 MiB |
Moving from ZGC to Shenandoah alone cut the data in use by 23% (A → E), because references shrink to 4 bytes; compact headers and string dedup took another 12% (E → B). Compact mode keeps the heap held close to the data at all times instead of waiting five minutes, as the default does.
See the numbers as a table
| RAM held by the game (GiB) | |
|---|---|
| 17:58 | 9.36 |
| 18:02 | 9.40 |
| 18:05 | 9.43 |
| 18:08 | 9.43 |
| 18:11 | 9.41 |
| 18:14 | 9.35 |
| 18:17 | 9.09 |
| 19:01 | 2.05 |
| 19:06 | 2.63 |
| 19:11 | 2.59 |
| 19:16 | 3.30 |
| 19:21 | 2.67 |
| 19:26 | 2.81 |
| 19:31 | 2.62 |
| 19:36 | 3.24 |
| 19:41 | 3.33 |
| 19:46 | 3.03 |
| Live server | Before (ZGC) | After (Shenandoah) |
|---|---|---|
| RAM held by the game | 9.35–9.43 GiB | 2.59–3.33 GiB |
| Machine free RAM | 2.82–2.92 GiB | 8.92–9.65 GiB |
| Heap held | 7,758 MiB | 2,008–2,796 MiB |
| Game CPU (cores) | 0.74–0.88 | 1.02–1.36 |
| Collections | 4 in 15 min | 98 in 46 min |
| Longest pause | 0.067 ms | 0.891 ms |
| Start-up | 68 s | 75 s |
| Players | 5 | 6–8 |
On the live server the game went from 9.4 to 2.6–3.3 GiB, with more players than before. The heap held stayed close to what was in use; the collector ran 98 times in 46 minutes on its own threads, its longest pause 0.9 ms (at start-up), with no degenerated, full or cancelled collection at all. The game used about 0.3–0.5 of a core more CPU, partly from the extra players, and took 75 seconds to start instead of 68.
What did not work
- ZGC with SoftMaxHeapSize (set C): the idle heap halved, but references stay at 8 bytes and ZGC’s own bookkeeping took 88 MiB, so the process still used 2.5–3.3 GiB.
- G1 (set D): the data was nearly as small as with Shenandoah, but it kept a 2 GiB heap and it stops the whole game while it collects.
- Shenandoah with its defaults (set E): references shrank, but after loading the world it still held 5 GiB, because by default it returns space only after five unused minutes.
- Hunting for a guilty mod first: scanning the 144 mods for data that grows forever found one (Zombie Dismemberment remembers the limbs of every zombie ever cut), but at a few MiB, not GiB, so it waits.
- The first run of the copy broke: Windows junctions to the mod folders made the game miss mod files and load no map, so they became hard links.
Limits
- The copy was measured with no players, on Windows; the live server with players on Linux runs higher.
- The live result covers the first 46 minutes after the restart and 20 minutes before the change, with different player counts (5 against 6–8), and the loaded world grows over each 6-hour cycle.
- Stutter was judged from the GC log and what players said; the game’s own time per tick was not measured.
Decision
The live server moved to set B at its 19:00 restart on 6 Nov 2026, plus ConcGCThreads=2 so the collector uses two idle cores, TrimNativeHeapInterval to return native memory every 60 seconds, and a GC log. The old settings file is kept for a rollback; no gameplay setting was touched.
-Xms1g
-Xmx8g
-XX:+UseShenandoahGC
-XX:ShenandoahGCHeuristics=compact
-XX:+UseCompactObjectHeaders
-XX:+UseStringDeduplication
-XX:ConcGCThreads=2
-XX:TrimNativeHeapInterval=60000
-Xlog:gc:file=/home/pzserver/ram-check/gc-%p.log:time,uptime,level:filecount=5,filesize=20mFollow-up
For 46 minutes after the change, 6–8 players played as usual, nobody reported lag and the GC log showed nothing worrying, so the settings stay. From here we watch the RAM at the end of each 6-hour cycle, and take care when the server’s agent is updated: its next version rewrites -Xms and -Xmx at every start.
Next
- Put these settings into the server’s agent so it writes them at every start (keeping -Xms low so Shenandoah can hand memory back), and a game update cannot quietly undo them.
- A small Java patch for the two wasteful spots in the game (vehicle sound, 82.7% of the garbage; the backup leftovers, 53 MiB), if the owner agrees.
- Try sharing identical animation data (the 437 MiB every Build 42 server loads).
Raw data
| Object (live server) | Count | Total |
|---|---|---|
| byte[] | 3,833,410 | 286 MiB |
| zombie.iso.IsoObject | 527,508 | 213 MiB |
| Object[] | 1,332,796 | 181 MiB |
| animation.Keyframe | 2,975,820 | 159 MiB |
| HashMap$Node[] | 924,017 | 147 MiB |
| lwjgl Vector3f | 6,049,528 | 138 MiB |
| zombie.iso.IsoGridSquare | 284,511 | 137 MiB |
| java.util.ArrayList | 3,286,411 | 100 MiB |
| lwjgl Quaternion | 3,025,118 | 92 MiB |
| LinkedHashMap$Entry | 1,547,717 | 83 MiB |
PID=$(pgrep -u pzserver -f ProjectZomboid64 | head -1)
grep -E "^(Rss|Pss_Anon|Pss_Shmem)" /proc/$PID/smaps_rollup
sudo -u pzserver jcmd $PID GC.heap_info
sudo -u pzserver jcmd $PID GC.class_histogram | head -40
sudo -u pzserver jcmd $PID JFR.start duration=15m settings=profile filename=rec.jfr
jfr view gc rec.jfr