16GB RAM / 10GB Used - Swap File Being Used? How To Stop Swap File From Being Used?

Hi,

New to openSUSE…

I have 16GB RAM and under full load I use about 10GB RAM.
The swap file is being activated which I don’t want.

How to stop swap file from being used?

Let me know, thanks!

Jesse

Hi
Configure sysctl… :wink: Tweak pressure as required. Some folks have found 125 better.


cat /etc/sysctl.d/98-swap.conf

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

Hi,

I tried that but got error:

jlp@SortFastDesktop:~> cat /etc/sysctl.d/98-swap.conf
cat: /etc/sysctl.d/98-swap.conf: No such file or directory
jlp@SortFastDesktop:~>

I don’t want to turn off swap file, just want to adjust the usage.
(have swap file use started at higher RAM usage)

Let me know, thanks!

Jesse

Some documentation so you understand the consequences of disabling/inactivating/removing swap

Althouth the following is a SUSE document, it should also apply to openSUSE
https://www.suse.com/support/kb/doc/?id=7010157
Although the following SDB is very old and not updated, skimming the content suggests that everything described should also apply to current openSUSE (TW, 15.2, 15.1)
https://en.opensuse.org/SDB:Partitioning
Some interesting RHEL documentation
https://www.redhat.com/en/blog/do-we-really-need-swap-modern-systems

The following ArchWiki article describes various commands including disabling swap (without removal)
Also includes descriptions for various swap options like compressed
https://wiki.archlinux.org/index.php/Swap

HTH,
TSU

Hi
It doesn’t turn it off, it just makes sure it uses ram before going to swap… best solution more ram :wink:


 free
              total        used        free      shared  buff/cache   available
Mem:       23598564     2510152    14840200      611308     6248212    20080452
Swap:       1972384           0     1972384

Of course, unless you create such a file yourself (BTW, you need superuser permissions to write to that place).

This is the effect on a 16 GB RAM system:

LT_B:~ # cat /etc/sysctl.d/sysctl.conf
vm.swappiness=1
vm.vfs_cache_pressure=50
LT_B:~ # free
              total        used        free      shared  buff/cache   available
Mem:       16304312    10601332      **159928**      557508     5543052     4798932
Swap:       8388604          ** 0**     8388604
LT_B:~ # 


FYI - Noticed on my TW there is a utility that can disable all or some swap on the system

swapoff

TSU

Hi
Or use my systemd-zram-service


Information for package systemd-zram-service:
---------------------------------------------
Repository     : Main Repository (OSS)             
Name           : systemd-zram-service


zramswapon
Setting up swapspace version 1, size = 2.8 GiB (3020615680 bytes)
....

free
              total        used        free      shared  buff/cache   available
Mem:       23598564     2636524    14649016      596516     6313024    19968872
Swap:      25570944           0    25570944

zramswapoff

free
              total        used        free      shared  buff/cache   available
Mem:       23598564     2528376    14746068      607612     6324120    20065924
Swap:       1972384           0     1972384

Hi,

Will:

swapoff

Survive a reboot?
(need something permanent)

Let me know, thanks!

Jesse

Needs testing, but from the documentation, likely.
There is a corresponding “swapon” to reverse what swapoff does.

TSU

Hi,

I just tested: “swapoff”, it does not survive a reboot.
Is there a method to turn off swap which would survive a reboot?
Let me know, thanks!

Jesse

Try noauto as a mount option in /etc/fstab? When I use it:

# dmesg | grep -i swap
    0.141700] Spectre V1 : Mitigation: usercopy/swapgs barriers and __user pointer sanitization
    1.126877] zswap: loaded using pool lzo/zbud
    1.675831] systemd[1]: Reached target Swap.
    3.020822] systemd[1]: Reached target Swap
# free
              total        used        free      shared  buff/cache   available
Mem:       16273576      180536    15957544        1916      135496    15855824
Swap:             0           0           0

Not clear to me what the real problem is. As explained in the RedHat article already referenced by tsu2, running Linux without some swap is not a good idea (other than for testing purposes).
I see three common scenarios.

  1. The system swaps heavily under normal load and becomes unresponsive.
    >>>>Buy more RAM, there is no real alternative.

  2. The system occasionally swaps under peak load, you don’t really notice unless you look at system logs (looks like the OP case?).
    >>>>Don’t tinker with the default config unless you really, really know what you are doing. (Most users, me included, lack the detailed knowledge to tune a system better than the sensible default config).

  3. The system never swaps under normal load; if swaps happen, there is an application that needs to be killed and/or debugged.
    >>>>Create a sysctl config like suggested in posts #2 or #7, what most of us SSD users do. Please be aware that with this config the system becomes very unresponsive as soon as it starts using swap, so that should never happen in normal use.
    There may be alternative solutions as hinted by malcolmlewis, but the end result is not much different.

Super confused…

Used Kubuntu Linux for many years on 16GB RAM desktop and swap file was never used.
On openSUSE Tumbleweed KDE 64Bit, the swap file is used and there is nothing I can do about it.

I tried in Konsole:
su
nano /etc/sysctl.conf
ADD TO BOTTOM:
vm.swappiness=1
vm.vfs_cache_pressure=1

Saved an rebooted, but under full load the swap file is still being used?
Frustrated…

Jesse

Maybe with TW there is just a peak in RAM usage, some “old” content or buffer is swapped (and maybe never reclaimed) so it sits in swap until the next reboot doing no harm…
The real question is: do you really notice adverse effects (e.g. persistent slowness) or is it just a nuisance to not see “swap in use =0” in system monitor?

I tried in Konsole:
su
nano /etc/sysctl.conf
ADD TO BOTTOM:
vm.swappiness=1
vm.vfs_cache_pressure=1

Two things:

  1. /etc/sysctl.conf will be replaced with the next update, copy to /etc/sysctl.d/sysctl.conf for a persistent setting.
  2. A sensible value for vm.vfs_cache_pressure is 50, not 1; even with 50 the system becomes extremely unresponsive if swap is being effectively used, so you should notice.
    As a general rule, don’t tinker with those values unless you really know what you are doing; occasional use of swap space is normal and not something to be worried about.

BTW, what is your RAM usage “under full load”?

Hi,

Full load is:
Memory Used: 9.3GB
Swap Used: 25MB

I have the following running:

  • Konsole
  • ExpressVPN running through OpenVPN
  • Pidgin IM
  • Skype
  • Thunderbird Email
  • Firefox Browser
  • Chrome Browser
  • FileZilla FTP Client
  • LibreOffice Calc
  • Steam Game Client
  • AppGameKit Studio IDE
  • VirtualBox
  • Win 10 Pro 64Bit Virtual Machine(4GB RAM)

Jesse

This is swap=0 to any practical standard. My guess is that an application asked for some buffer space and the system pushed to swap some boot code that it never needed thereafter, to leave as much ram as needed available to buffers, possibly for one of the running network clients or VBox during some peak operation.
That sounds normal to me and I doubt that you ever noticed; if you don’t want to see that 25 MB to swap I think the only option is to switch off swap entirely, but then one of your running applications might be killed sooner than you expect due to poorer memory management when a swap is not available.
In a situation like that I would not even tweak the default parameters (swappiness=60 vfs_cache_pressure=100) unless I had another valid reason to do so.

I’m not sure if it matters in this case. But that file is probably copied into the “initrd”. You could try running “mkinitrd” to recreate that.

I have been working for 5 years without swap files, however open the terminal

su -

enter your password

kate /etc/sysctl.conf 

if you have Gnome use gedit, at the bottom of the file add

vm.swappiness = 10

reboot