Linux Labs

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

ulimit and sysctl: system ceilings

Not running Starting usually ~20 s
Leave the lesson

Step 6 of 10 · theory · 4 min

A change for boot time

To make a value survive a reboot, you write it to a file, and the system sets it at every start.

At boot the systemd-sysctl service reads the *.conf files from /etc/sysctl.d, /run/sysctl.d and /usr/lib/sysctl.d and sets the values written there. A file holds lines of the form name = value:

bash
# /etc/sysctl.d/60-inotify.conf
fs.inotify.max_user_watches = 65536

The files are applied in name order across all the directories together. If a parameter appears in two files, the value from the last one stays, which is why file names start with a number. A file with another extension, such as .txt or .bak, is skipped.

To apply the files without a reboot, run sudo sysctl --system. It reads the same directories in the same order and prints every file and every value: the output tells you whether your line reached the kernel.

Check yourself 1 question

/etc/sysctl.d/10-watches.conf has fs.inotify.max_user_watches = 65536, and /etc/sysctl.d/90-desktop.conf has fs.inotify.max_user_watches = 16384. What value will the parameter have after a boot?

  • The size of the value does not matter: the files are applied in name order, and 90-desktop.conf comes after 10-watches.conf.

  • There is no dispute: each file simply sets the value, and the last one stays. sudo sysctl --system shows both lines in order.

The files are applied in name order, and the last value written stays. 90-desktop.conf comes after 10-watches.conf, so after a boot the value is 16384. The file order is visible in the output of sudo sysctl --system.

Key points

  • sysctl -w changes a parameter until a reboot; at start the kernel begins with its own values.
  • A lasting value is a name = value line in a *.conf file in /etc/sysctl.d; at boot systemd-sysctl sets it.
  • sudo sysctl --system applies the files right away; of two files with the same parameter, the value from the last by name stays.
Ubuntu 24.04
Loading…