Minimizing ram and disk used by systemd-journald

3 réponses [Dernière contribution]
andyprough
Hors ligne
A rejoint: 02/12/2015

Sorry this is going to be terribly boring reading, but I'm running an experiment and just going to write notes here on what I'm finding.

systemd-journald has been regularly taking up over 60mb of ram on my system and nearly 1GB of disk space, which is just absolutely ridiculous. I proved in an earlier thread that just by replacing systemd-journald with the older rsyslog that memory usage could fall to as little as 1.8mb of ram. Here I'll show that systemd-journald itself can be tamed with the right settings to get it down to a reasonable amount of ram usage and disk usage. With this systemd-journald minimization in place, I'm now able to regularly start a normal installation of Trisquel 11 with the DWM window manager with less than 200mb of ram.

[WARNING - I don't know if any of this is a good idea or if it will have disastrous effects - so don't just happily follow along with andyprough in this little experiment thinking that your system's health is somehow guaranteed. This is just about me continuing in my experimenting with ways of chopping down systemd's excessive bloatiness.]

There appear to be five settings that need to be adjusted in /etc/systemd/journald.conf to reduce systemd-journald ram and disk usage on Trisquel:
Storage=
SystemMaxUse=
SystemMaxFileSize=
RuntimeMaxUse=
RuntimeMaxFileSize=

The Storage= config setting is an important gatekeeper for systemd-journald. You have the options of using the following settings: auto, volatile, persistent, none. The default setting is Storage=auto, which tends to act just like Storage=persistent, both of them preferring to store the log data on disk. If you set this config option to Storage=none, you will completely shut off systemd-journald (no more logging at all, no ram usage). If you set it to Storage=volatile, the journald.conf man page says that journal log data will be stored only in memory, i.e. below the /run/log/journal hierarchy (which is created if needed). Apparently, the command
journalctl --flush will move volatile data to persistent storage on your hard disk. I'm not certain yet that this really --flush command really works to save the data persistently, but I'll update this thread with more info as I figure it out.

The journald.conf man page claims that the SystemMaxUse= and RuntimeMaxUse= config options control how much disk space the journal may use up at most. However, I haven't found that systemd-journald is really willing to live within the small disk limits I've set. However, it does seem to work to greatly reduce the amount of disk space taken up, and seeing as how my system was earlier eating up nearly 1GB of disk space for logging, any reduction is desirable. Also, the RuntimeMaxUse= config option seems to have a big impact on reducing the amount of ram used by systemd-journald if a small number is used in combination with the Storage=volatile config option.

The journald.conf man page claims that the SystemMaxFileSize= and RuntimeMaxFileSize= control how large individual journal files may grow at most. Once again, when I set these to tiny sizes, I don't see systemd-journald respecting them completely in terms of disk usage. However, disk usage does seem to be greatly reduced, and, as with RuntimeMaxUse=, giving a tiny size to the RuntimeMaxFileSize= config option in combination with the Storage=volatile config option does seem to greatly reduce the amount of ram being used.

Anyway, here's my /etc/systemd/journald.conf file if anyone is interested in following along. I went with Storage=volatile, SystemMaxUse=8M, SystemMaxFileSize=100K, RuntimeMaxUse=3M, RuntimeMaxFileSize=100K - much tinier files than systemd wants by default, but they seem plenty big enough for log files to me. With these options in place, I've reduced systemd-journald disk usage from about 900mb to 56mb, and I've reduced ram usage from 60mb at startup to 1.7mb at startup and about 2.4mb after using the system for an hour (see attached screenshot):

# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 2.1 of the License, or (at your option)
# any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the journald.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-analyze cat-config systemd/journald.conf' to display the full config.
#
# See journald.conf(5) for details.

[Journal]
#Storage=auto
#Storage=none
Storage=volatile
#Storage=persistent
#Compress=yes
#Seal=yes
#SplitMode=uid
#SyncIntervalSec=5m
#RateLimitIntervalSec=30s
#RateLimitBurst=10000
SystemMaxUse=8M
#SystemKeepFree=
SystemMaxFileSize=100K
#SystemMaxFiles=100
RuntimeMaxUse=3M
#RuntimeKeepFree=
RuntimeMaxFileSize=100K
#RuntimeMaxFiles=100
#MaxRetentionSec=
#MaxFileSec=1month
#ForwardToSyslog=yes
#ForwardToKMsg=no
#ForwardToConsole=no
#ForwardToWall=yes
#TTYPath=/dev/console
#MaxLevelStore=debug
#MaxLevelSyslog=debug
#MaxLevelKMsg=notice
#MaxLevelConsole=info
#MaxLevelWall=emerg
#LineMax=48K
#ReadKMsg=yes
#Audit=no

Pièce jointeTaille
systemd-journald.jpg27.04 Ko
andyprough
Hors ligne
A rejoint: 02/12/2015

And now I'm at 185mb ram in use at startup - making progress. I could still cut some more fat - mate-screensaver probably doesn't need to be running. I switched to using the st terminal from the suckless project as it's using less than 5mb of ram. I'm thinking I could possibly get rid of pulseaudio and just run the system audio purely through pipewire, could save another 10mb that way. Might try to get down below 150mb at startup one of these days.

systemd-journald2.jpg
andyprough
Hors ligne
A rejoint: 02/12/2015

Down to 179mb without mate-screensaver now.

systemd-journald3.jpg
andyprough
Hors ligne
A rejoint: 02/12/2015

It appears that all the logs are being saved for a sufficient time period for my uses. Most logs seem to be collecting several days worth of information. Disk usage as measured by jounralctl is still just 59.5MB, and ram today for systemd-journald is hovering between 1.8 to 2.7 MB of ram. Still pretty good. And the system is stable. Seems like a successful little experiment so far.