Linux Labs

Inside the system: resources, kernel, processes / Stage 2 of 12

Memory, swap and the OOM killer

Not running Starting usually ~20 s
Leave the lesson

Step 5 of 9 · on a machine · 4 min

A unit drop-in

Raise the lab-thumbs ceiling so that the change survives a package update.

The lab-thumbs unit file lives in /usr/lib/systemd/system — that directory belongs to packages, and an update will overwrite the file along with your edit. Your own settings go into a unit drop-in: a .conf file in the /etc/systemd/system/<unit>.d/ directory. It holds only what you change, under the header of its section. systemd takes the rest from the main file.

bash
d=/etc/systemd/system/lab-thumbs.service.d
sudo mkdir -p $d
printf '[Service]\nMemoryMax=128M\n' | sudo tee $d/memory.conf
sudo systemctl daemon-reload
systemctl status lab-thumbs

systemd reads unit files at startup and on systemctl daemon-reload. Without it the new file has no effect: systemctl show -p MemoryMax prints the old ceiling. After daemon-reload the ceiling of a running service changes at once. systemctl status now has a Drop-In line, and in a few seconds the service will get through the whole queue: 128 MiB is enough for the panorama and its copy. systemctl cat lab-thumbs shows the main file and the drop-in one after the other.

Check yourself 1 question

You put a drop-in with MemoryMax=96M in place, but systemctl show -p MemoryMax prints infinity. What do you do?

  • restart does not reread unit files: systemd will remind you that the files changed and start the service without the ceiling.

  • A package update would wipe the edit in the package file, and systemd would not see it without reloading its configuration either.

systemd reads unit files at startup and on daemon-reload. After it, the ceiling applies to the running service as well.

Key points

  • Unit files in /usr/lib/systemd/system belong to packages; your settings go into a drop-in /etc/systemd/system/<unit>.d/*.conf.
  • After an edit — systemctl daemon-reload; the memory ceiling of a running service changes without a restart.
  • systemctl cat shows the main unit file and all its drop-ins.
Ubuntu 24.04
Loading…