Can't reduce swappiness in /etc/sysctl.conf

I’m running on an SSD and I wanted to reduce swappiness in order to try to decrease the number of writes to the SSD. I may just reinstall without a swap partition but from all my googling (and experience on other distros) it looks like I should be able to set swappiness lower by adding

vm.swappiness=1

to /etc/sysctl.conf. I’ve done so but the system doesn’t seem to be respecting it as running

cat /proc/sys/vm/swappiness

still returns 60. Is this the proper way to reduce swappiness on TW?

Hi and welcome to the forum :slight_smile:
There are two items to set…


# Disable swap
vm.swappiness = 1
vm.vfs_cache_pressure = 50

Also ensure no CR LF after the last line…

Working fine here on Tumbleweed and other systems;


cat /proc/sys/vm/swappiness
1
cat /proc/sys/vm/vfs_cache_pressure
50

Have you restarted the system since the change?

Thanks! So I went back and added the vfs_cache_pressure line and rebooted, but still no joy.

cat /etc/sysctl.conf 
####
#
# /etc/sysctl.conf is meant for local sysctl settings
#
# sysctl reads settings from the following locations:
#   /boot/sysctl.conf-<kernelversion>
#   /lib/sysctl.d/*.conf
#   /usr/lib/sysctl.d/*.conf
#   /usr/local/lib/sysctl.d/*.conf
#   /etc/sysctl.d/*.conf
#   /run/sysctl.d/*.conf
#   /etc/sysctl.conf
#
# To disable or override a distribution provided file just place a
# file with the same name in /etc/sysctl.d/
#
# See sysctl.conf(5), sysctl.d(5) and sysctl(8) for more information
#
####
vm.swappiness = 1
vm.vfs_cache_pressure = 50
cat /proc/sys/vm/swappiness
60
cat /proc/sys/vm/vfs_cache_pressure 
100

Is there a typo I’m missing or something?

Hi
Strange indeed… anything in the logs when it boots up?

Not 100% sure, but IIRC sysctl.conf files are put into initrd, so maybe
rebuilding the initrd might be necessary.

AK


Never attribute to malice that which can be adequately explained by stupidity.
(R.J. Hanlon)

Alright, so the only interesting thing in the boot log is:

 %G%G%G%G[FAILED] Failed to start Create Volatile Files and Directories.
 See 'systemctl status systemd-tmpfiles-setup.service' for details.


And that just shows me:

● systemd-tmpfiles-setup.service - Create Volatile Files and Directories
   Loaded: loaded (/usr/lib/systemd/system/systemd-tmpfiles-setup.service; static; vendor preset: disabled)
   Active: failed (Result: exit-code) since Sun 2017-05-21 21:51:39 EDT; 7min ago
     Docs: man:tmpfiles.d(5)
           man:systemd-tmpfiles(8)
  Process: 597 ExecStart=/usr/bin/systemd-tmpfiles --create --remove --boot --exclude-prefix=/dev (code=exited, st
 Main PID: 597 (code=exited, status=1/FAILURE)

May 21 21:51:39 linux-vbzl systemd[1]: Starting Create Volatile Files and Directories...
May 21 21:51:39 linux-vbzl systemd-tmpfiles[597]: [/usr/lib/tmpfiles.d/cups.conf:3] Unknown group 'sys'.
May 21 21:51:39 linux-vbzl systemd-tmpfiles[597]: Cannot set file attribute for '/var/log/journal', value=0x008000
May 21 21:51:39 linux-vbzl systemd-tmpfiles[597]: Cannot set file attribute for '/var/log/journal/faffae7d6378453b
May 21 21:51:39 linux-vbzl systemd[1]: systemd-tmpfiles-setup.service: Main process exited, code=exited, status=1/
May 21 21:51:39 linux-vbzl systemd[1]: Failed to start Create Volatile Files and Directories.
May 21 21:51:39 linux-vbzl systemd[1]: systemd-tmpfiles-setup.service: Unit entered failed state.
May 21 21:51:39 linux-vbzl systemd[1]: systemd-tmpfiles-setup.service: Failed with result 'exit-code'.

Probably not related, but something I’d still like to figure out.

I think I figured out the sysctl issue through a bit more digging. I noticed that systemd-sysctl.service is disabled by default on install. I assume this needs to be enabled for /etc/sysctl.conf to be read? Should I enable it, or is there a better way to deal with swappiness? I could just remove the partition from my fstab…

Got it! It wasn’t the service. Apparently, systemd-sysctl does not read /etc/sysctl.conf directly but expects a link in /etc/sysctl.d/99-sysctl.conf > /etc/sysctl.conf. I created that link and it reads /etc/sysctl.conf as expected.

I’m not sure why did this happen to you as i’ve never done that linking and all is fine with me, but i’ve added your comment in my bookmarks just in case lol