"sudo sysctl vm.swappiness=1"/"sudo sysctl vm.vfs_cache_pressure=1" Not Working?

Hi,

Running Manjaro Xfce 64Bit.
Have 16GB RAM but swap activates too early.

I tried the following in terminal:

sudo sysctl vm.swappiness=1
sudo sysctl vm.vfs_cache_pressure=1

but it does not survive a reboot?

How can I fix the above?
Let me know, thanks!

Jesse

Hi. You just need to put your desired parameters inside a *.conf file @ /etc/sysctl.d/

https://wiki.archlinux.org/index.php/sysctl#Configuration

That low of a value for cache_pressure doesn’t makes much sense if you ask me BTW, but I’m no expert myself :man_shrugging:

1 Like

In the meantime you can also take a look to such discussion:

Important: I don’t encourage you to do the same, to apply same settings.

Hi,

I tried post #2, but it’s not working after a reboot?:

Jesse

Ok, removing the “sysctl” made it work, thanks!

I know this will work for changing value for swappiness
But I have not combined it with setting for ‘vm.vfs_cache_pressure’ before

echo -e 'vm.swappiness=1\nvm.vfs_cache_pressure=1' | sudo tee -a /etc/sysctl.d/99-sysctl-swappiness.conf

As @Signalrunner already mentioned, using 1 for these values will not help you.

cc @nikgnomic as I see you’re making the same mistake.

TL;DR

Swapping is normal: the kernel knows better than you when to swap stuff out. Don’t focus on not having any swap at all!

:man_shrugging:

The Long version:

You will always see some swapping going on, because the kernel knows better than you and will swap unused services out; so you’re better off debugging what’s not needed by looking at what gets swapped out exactly and deleting / disabling that instead of trying to having no swapping happen at all!
E.G. If you’ve installed samba but only wanted the client and not the server, well, guess what? The server will be swapped out because it’s not being used.

So, please use these (pretty self-explanatory) values to swap late, but once swapped out, don’t swap in again aggressively as that slows down things as well:

cat /etc/sysctl.d/30-swap_usage.conf
# Fabrizio: 2014-03-02: change "swappiness" from default 60 to 10:
#  Theoretically, only swap when RAM usage reaches around 80 or 90 percent
# Fabrizio: 2014-03-29: lower to 5 as swapping is still occurring with low mem usage
# Fabrizio: 2014-11-21: Bring back up to 10 as vm.vfs_cache_pressure was introduced
vm.swappiness = 10

# Fabrizio: 2014-11-29: Lower vm.vfs_cache_pressure to 75%
# (once swapped, probably not immediately needed any more)
#
# This value used to be a percentage value that controls the tendency of the kernel to reclaim
# the memory which is used for caching of directory and inode objects.
#
# At the default value of vfs_cache_pressure=100 the kernel will attempt to
# reclaim dentries and inodes at a "fair" rate with respect to pagecache and
# swapcache reclaim.  Decreasing vfs_cache_pressure causes the kernel to prefer
# to retain dentry and inode caches.
# Nowadays the value can be >100!
vm.vfs_cache_pressure = 75

Also know that hibernation works by swapping all programs out to disk and then shutting down, so when you come out of hibernation, any swapped-out applications not taking any CPU cycles will stay swapped until you use them! This is by design!
(I.E. Don’t debug swapping when coming out of hibernation: the figures always look awful!)

How to debug what is getting swapped, you ask?

  1. sudo nano --backup /usr/local/bin/swapusage

  2. copy-paste this:

    #!/bin/sh
    for szFile in /proc/*/status ; do
    awk '/VmSwap|Name/{printf $2 "\t" $3}END{ print "" }' $szFile
    done | sort --key 2 --numeric --reverse | more
    
  3. Execute:

    chmod a+x /usr/local/bin/swapusage
    
  4. Execute:

    swapusage
    
  5. Start debugging what gets swapped out and disable it.

E.G. On my system; right now; coming out of hibernate yesterday:

  1. Result of free --human:

    total          used        free      shared  buff/cache   available
    Mem:           15Gi       5.8Gi       678Mi       431Mi       9.1Gi       9.1Gi
    Swap:          19Gi       283Mi        19Gi
    
  2. Result of swapusage:

    Application size unit
    qbittorrent 81968 kB
    telegram-deskto 32704 kB
    plasmashell 17132 kB
    dolphin 9736 kB
    konsole 7792 kB
    geany 6280 kB
    vlc 6196 kB
    mono 5944 kB
    Xorg 5928 kB
    baloorunner 5260 kB
    xdg-desktop-por 5000 kB
    bash 3928 kB
    kglobalaccel5 3600 kB
    xdg-desktop-por 2440 kB
    kactivitymanage 1684 kB
    bash 1264 kB
    skypeforlinux 1216 kB
    kdeconnectd 1172 kB
    gsettings-helpe 1084 kB
    kdeinit5 948 kB
    pulseaudio 932 kB
    file.so 884 kB
    file.so 884 kB
    file.so 880 kB
    systemd 704 kB

But:

  1. I have a lot of finished torrents that I should convert to a lower resolution and then delete but they’re not taking up any RAM now.
  2. There are a lot of conversations inside Telegram that are not active right now, so I’ll see a slight delay when opening those
  3. I dunno why plasmashell is taking up that amount of swap
  4. Dolphin has not been used for a while on my 4th desktop
  5. bash: I have 3 consoles open but only one was being used recently
    etc, etc

:+1:

3 Likes

I was only answering the question of setting the values permanently using the values OP wanted
I don’t expect OP will be happy with the values requested, but it will help towards finding the optimal setting one way or another

I have posted before about swappiness value but users still try things that may not be good, I did the same myself when I was trying to find the right balance on settings

I have 8GB RAM and found vm.swappiness = 10 to be optimal for my use
I tried lower values 10 but found it delayed swap too much and system could stall hard for a moment. I found swapping too late to be just as annoying as swapping too early

1 Like

2 posts were split to a new topic: Issues with vfs_cache_pressure

Folks, I’m just marking this as solved. it looks like the underlying issue on this thread was solved long time ago. Probably the OP forgot to mark this thread as solved.

I don’t think there is a need to revive this discussion.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.