Our server held 9.36 GiB of RAM to use 3

Worked

Entry 1 · Started 6 Nov 2026 · Last updated 6 Nov 2026 20:30

The 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
Figure 1 The game's 9.36 GiB by part, measured on the live server on 6 Nov 2026 at 18:15 with 5 players.
See the numbers as a table
GiB%
Data the game uses2.9632
Held by ZGC, unused4.6249
Outside the heap, and files1.7919

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

  1. False
    The 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.

  2. True
    Java’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.

  3. True
    A 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.
ZGC (before)Shenandoah compact (after)
  • Data in use
  • Garbage waiting
  • RAM held
  • Collector at work (other threads)
Figure 2 A diagram, not data: ZGC lets garbage pile up near its ceiling before collecting and keeps the space; Shenandoah in compact mode collects more often on other threads and hands the space back.
  • ZGC
  • Shenandoah + compact headers
  1. Keyframeanimation pose56 → 32 byte43% smaller
  2. LinkedHashMap.Entrya slot in a Lua table56 → 32 byte43% smaller
  3. Stringtext32 → 24 byte25% smaller
  4. Quaternionrotation32 → 24 byte25% smaller
  5. Vector3fno references24 → 24 byteSame
Figure 3 Size of one object of each type, measured on the server copy: ZGC against Shenandoah with compact headers.
See the numbers as a table
ZGCShenandoah + compact headers
Keyframe (animation pose)5632
LinkedHashMap.Entry (a slot in a Lua table)5632
String (text)3224
Quaternion (rotation)3224
Vector3f (no references)2424

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.

SetJava settings
AZGC as the game ships it (what the server ran)
BShenandoah in compact mode + compact headers + string dedup
CZGC + compact headers + string dedup + SoftMaxHeapSize 2 GiB
DG1 + compact headers + string dedup
EShenandoah with its defaults
Table 1

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

Figure 4 The server copy, no players, 90 seconds after start: process RAM (full bar) and data in use (solid part).
See the numbers as a table
Data in use (MiB)Process RAM (MiB)
A · ZGC1,1966,390
E · Shenandoah9175,156
C · ZGC + SoftMax1,0893,338
D · G18342,460
B · Shenandoah compact8061,274
SetData in useHeap heldProcess RAM
A · ZGC1,196 MiB5,932 MiB6,390 MiB
B · Shenandoah compact806 MiB834 MiB1,274 MiB
C · ZGC + SoftMax1,089 MiB1,986 MiB3,338 MiB
D · G1834 MiB2,016 MiB2,460 MiB
E · Shenandoah917 MiB966 MiB5,156 MiB
Table 2

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.

04812GiB17:5818:1719:0019:46RestartZGC ≈ 9.43.03Shenandoah compact ≈ 2.8
Figure 5 The live server: RAM held by the game (VmRSS) before the change, 17:58–18:17 with about 5 players, and after the 19:00 restart until 19:46 with 6–8 players, on 6 Nov 2026. The stretch between was not measured.
See the numbers as a table
RAM held by the game (GiB)
17:589.36
18:029.40
18:059.43
18:089.43
18:119.41
18:149.35
18:179.09
19:012.05
19:062.63
19:112.59
19:163.30
19:212.67
19:262.81
19:312.62
19:363.24
19:413.33
19:463.03
Live serverBefore (ZGC)After (Shenandoah)
RAM held by the game9.35–9.43 GiB2.59–3.33 GiB
Machine free RAM2.82–2.92 GiB8.92–9.65 GiB
Heap held7,758 MiB2,008–2,796 MiB
Game CPU (cores)0.74–0.881.02–1.36
Collections4 in 15 min98 in 46 min
Longest pause0.067 ms0.891 ms
Start-up68 s75 s
Players56–8
Table 3 Measured on the machine with /proc, jcmd and the GC log; CPU averaged every 5 minutes (1 = one core of 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=20m
What went into the vmArgs of ProjectZomboid64.json (-XX:+UseZGC removed)

Follow-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)CountTotal
byte[]3,833,410286 MiB
zombie.iso.IsoObject527,508213 MiB
Object[]1,332,796181 MiB
animation.Keyframe2,975,820159 MiB
HashMap$Node[]924,017147 MiB
lwjgl Vector3f6,049,528138 MiB
zombie.iso.IsoGridSquare284,511137 MiB
java.util.ArrayList3,286,411100 MiB
lwjgl Quaternion3,025,11892 MiB
LinkedHashMap$Entry1,547,71783 MiB
Table 4 The 10 largest kinds of live object (jcmd GC.class_histogram), 6 Nov 2026 18:14; 2,713 MiB in all.
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
The commands used (counting objects freezes the game for 1–3 seconds; tell the players first)