sysctl.conf still being ignored on boot

I recently encountered an issue on my newly installed Arch Linux system. I attempted to modify the swappiness value to adjust the system’s behavior, and I followed online guides that recommended adding the value to the ‘/etc/sysctl.conf’ file. However, even after a reboot, it appeared that the swappiness value had not been successfully changed

(vm.swappiness is a Linux kernel parameter that controls the tendency of the operating system to swap out (move from RAM to swap space on the hard disk) the pages of processes. Swapping is a process that occurs when the system’s physical memory (RAM) is running low, and the kernel needs to free up space by moving less frequently used data from RAM to the swap space on the hard disk.)

After some online research, I discovered that the system was utilizing the configurations specified in the ‘/usr/lib/sysctl.d/’ directory. It turns out that in certain Linux distributions that employ systemd, the loading of these settings is managed by the systemd-sysctl command, which is executed by the systemd-sysctl service. Importantly, the systemd-sysctl service doesn’t read the ‘/etc/sysctl.conf’ file; instead, it reads a variety of ‘*.conf’ files from the ‘/etc/sysctl.d’ directory.

The fix was simple, I created a symbolic link in the ‘/usr/lib/sysctl.d/’ directory that pointed to my configuration in ‘/etc/sysctl.conf’ (Just me being lazy to create one more file sysctl.d directory) and applied it using ‘sysctl -p’ command.

$ cat /etc/sysctl.conf
vm.swappiness=10
$ ln -s /etc/sysctl.conf /usr/lib/sysctl.d/99-sysctl.conf
$ ll /usr/lib/sysctl.d/99-sysctl.conf
lrwxrwxrwx 17 root 15 Oct 20:33  /usr/lib/sysctl.d/99-sysctl.conf -> /etc/sysctl.conf
$ sudo sysctl -p
vm.swappiness = 10 

Reference

systemd manual pages

<