Operating Systems Bug Report

journald filled the disk: 30 GB in /var/log/journal, a copied SystemMaxUse and a noisy unit

An API host ran out of disk and its database writes failed. /var/log/journal held 30 GB because a drop-in copied from our log server raised SystemMaxUse, and one unit logged a stack trace per retry. We vacuumed, found the override with systemd-analyze and rate-limited the unit.

Leila Farahani Leila Farahani @leilafarahani · November 21, 2026 · 7 min read · 156 Views
601-journald-filled-disk-systemmaxuse-vacuum

At 06:40 one API host started returning errors on every write. The application log, the little of it that still got written, showed:

Error: ENOSPC: no space left on device, write

and the local PostgreSQL instance used for job state refused new transactions:

PANIC:  could not write to file "pg_wal/xlogtemp.4127": No space left on device

df -h / showed the 60 GB root filesystem at 100%. du pointed at one directory:

sudo du -xh --max-depth=2 /var | sort -h | tail -4
1.2G    /var/lib/postgresql
2.9G    /var/lib
30G     /var/log/journal
34G     /var
journalctl --disk-usage
Archived and active journals take up 30.0G in the file system.

Reproducing it

The growth was steady rather than sudden: our disk dashboard showed root usage climbing about 1 GB a day for a month. Nothing changed at 06:40 except that the disk finally ran out.

What we ruled out

  • Deleted-but-open files. sudo lsof +L1 listed nothing large; the space was real files.

  • rsyslog duplicates. /var/log/syslog and its rotations totalled 1.1 GB, kept in check by logrotate.

  • A journald bug ignoring limits. journald was behaving exactly as configured, as the next step showed.

Root cause

Two things combined. First, the journal size limit was not the default. By default journald caps persistent storage at 10% of the filesystem (and never more than 4 GB), about 4 GB here. A configuration management role shared with our central log server had installed a drop-in, /etc/systemd/journald.conf.d/90-retention.conf, with SystemMaxUse=40G and SystemKeepFree=1G, values chosen for a 500 GB log volume. On a 60 GB root filesystem that allowed the journal to grow until only 1 GB remained free, and the rest of the system filled that.

Second, one unit was producing most of the volume. A sync worker failing to reach a partner API retried every second and logged a full stack trace each time, about 300 lines per attempt.

What is happening under the hood

journald writes structured binary journal files to /var/log/journal/<machine-id>/ when persistent storage is enabled (the directory exists, or Storage=persistent). It rotates the active file when it reaches SystemMaxFileSize or after MaxFileSec, and deletes the oldest archived files to stay within the limits:

Setting

Default

Meaning

SystemMaxUse=

10% of filesystem, max 4G

Total space the journal may use

SystemKeepFree=

15% of filesystem, max 4G

Space journald leaves free for others

SystemMaxFileSize=

one-eighth of SystemMaxUse

Size at which a file is rotated

MaxRetentionSec=

none

Delete entries older than this

RateLimitIntervalSec= / RateLimitBurst=

30s / 10000

Per-service message rate limit, before dropping

journald honours whichever of SystemMaxUse and SystemKeepFree is stricter. Values in drop-ins under /etc/systemd/journald.conf.d/ override the main journald.conf, and files are read in lexical order with later ones winning. Limits are applied at rotation and startup, so a lowered limit takes effect when journald restarts or rotates.

The default rate limit allows 10,000 messages per 30 seconds per service before dropping. Our worker emitted roughly 9,000 lines per 30 seconds, just under the threshold, so nothing was dropped and everything was stored.

Environment

Component

Version / value

OS

Ubuntu 22.04 LTS

systemd

249

Root filesystem

60 GB ext4, /var on root

Journal

Persistent, /var/log/journal

Override

/etc/systemd/journald.conf.d/90-retention.conf from shared Ansible role

Noisy unit

partner-sync.service, Node.js worker

Minimal reproduction

# /etc/systemd/journald.conf.d/90-retention.conf (the problem)
[Journal]
SystemMaxUse=40G
SystemKeepFree=1G
# A unit that logs a lot, just under the rate limit
systemd-run --unit=noisy bash -c 'while true; do for i in $(seq 290); do echo "trace line $i"; done; sleep 1; done'
watch -n 60 journalctl --disk-usage

The fix

Step 1: free space now, safely. Vacuuming deletes archived journal files only. Rotate first so the active files become archived and can be trimmed too:

sudo journalctl --rotate
sudo journalctl --vacuum-size=2G
Vacuuming done, freed 28.0G of archived journals from /var/log/journal/3f1c9a2b7e8d4c1f9a6b2d0e5c7f8a91.

--vacuum-time=14d and --vacuum-files=20 are the time- and count-based alternatives. Never rm files from /var/log/journal while journald is running; vacuuming does it correctly. Once space was free, PostgreSQL recovered on restart and the API returned to normal.

Step 2: find out which configuration was actually in force.

systemd-analyze cat-config systemd/journald.conf

This prints the main file followed by every drop-in in the order they apply, each with its path. It showed 90-retention.conf with the 40G value. We removed the file from the shared role and gave app hosts their own explicit limits:

# /etc/systemd/journald.conf.d/50-app-host.conf
[Journal]
SystemMaxUse=4G
SystemKeepFree=8G
MaxRetentionSec=30day
sudo systemctl restart systemd-journald
journalctl --disk-usage

Logs that must be kept longer are forwarded to the central log server anyway; the local journal is a short buffer, not the archive.

Step 3: find and calm the noisy unit.

journalctl --since "-1h" -o json --output-fields=_SYSTEMD_UNIT \
  | jq -r '._SYSTEMD_UNIT // "kernel/other"' | sort | uniq -c | sort -rn | head
 532811 partner-sync.service
   3120 nginx.service
    844 api.service

We fixed the worker to log one line per failed attempt with the error code, and to back off exponentially instead of retrying every second. We also added a per-unit rate limit and level cap as a safety net:

# systemctl edit partner-sync.service
[Service]
LogRateLimitIntervalSec=30s
LogRateLimitBurst=1000
LogLevelMax=info

LogLevelMax=info drops debug-level messages from that unit before they are stored. When the rate limit triggers, journald writes a single "Suppressed N messages" line instead of every message, so you still know it happened.

Alternatives and trade-offs

  • Volatile journal (Storage=volatile). Keeps logs in RAM under /run/log/journal, so they never fill the disk, but they vanish at reboot. Acceptable only if every log is shipped elsewhere in real time.

  • Separate /var/log filesystem. Contains the blast radius: the journal can fill its own volume without breaking the database. Worth doing on long-lived VMs; less relevant for immutable instances.

  • Lower the global rate limit. Protects against every noisy unit at once, but can drop important bursts during real incidents. We preferred per-unit limits on known offenders.

How to test the fix

systemd-analyze cat-config systemd/journald.conf | grep -E 'SystemMaxUse|SystemKeepFree'
sudo systemctl restart partner-sync
journalctl -u partner-sync --since "-5 min" | wc -l

We pointed the worker at an unreachable test endpoint and confirmed it logged one line per backoff interval and that disk usage stayed flat over an hour.

Confirming in production

Over the following week journalctl --disk-usage stayed between 1.8 and 2.6 GB, and the root filesystem's usage graph went flat. We also checked that rotation and limits applied on every app host:

ansible app_hosts -b -m command -a 'journalctl --disk-usage'

Regression guard

We added a disk-usage alert per mount point with prediction, so slow growth pages long before it is critical:

- alert: DiskWillFillIn4Days
  expr: predict_linear(node_filesystem_avail_bytes{fstype!~"tmpfs|overlay"}[6h], 4*24*3600) < 0
  for: 1h

The Ansible role for journald now has a test that renders the drop-in per host group and fails if SystemMaxUse exceeds 10% of the target host's root filesystem size.

Security implications

Log loss is a security concern: an attacker who can make a service log heavily could, with permissive limits, fill the disk (a denial of service), or with tight limits, push evidence out of retention. Forwarding logs off host in real time addresses both, which is why our local limits are small. Also check what the noisy unit was logging: our stack traces included request headers from the partner API, which we now redact, since anyone in the adm or systemd-journal group can read the journal.

Prevention checklist

  • Inspect effective journald settings with systemd-analyze cat-config, not by reading one file.

  • Keep app hosts' journals small (a few GB) and forward logs centrally.

  • Rate-limit and level-cap chatty units with LogRateLimit* and LogLevelMax.

  • Alert on predicted disk fill, not only on percent used.

  • Do not share log retention roles between log servers and app hosts.

References

Add a label

#linux #logging #systemd #journalctl #journald
Written by
Leila Farahani @leilafarahani

I lead a small team responsible for observability and quality tooling, and I spend a fair share of my time on application security reviews. That mix means I see many incidents twice: once when they happen and again when we ask why nothing warned us. The posts here come from that second look. An alert that never fired because the metric disappeared, sampling that dropped exactly the traces we needed, a catch-all that reported success for weeks, a secret recoverable from an image layer, tests that passed against mocks while production failed. Each one covers how the gap was found, what we changed in code or configuration, and how we verified the fix with a test or a drill. Security topics stay defensive and practical: controls you can add to your own code and a way to test each one.

Advertisement

Comments

0

No comments yet. Be the first to comment!

Sign In to post a comment.