System "micro-freezing" with automated swap management

Some time ago (maybe months) I set automated swap management as per here:

https://wiki.manjaro.org/index.php?title=Swap#Automated_Swap_Management_with_systemd-swap

However for some time (weeks?), every so often, the the system will freeze frequently for a split second, or a program will become unusable. I have 5 virtual desktops and often keep many tabs open. Just before writing this post the issue was occuring, but after closing many tabs it is not “micro-freezing”. But I have 64 GB of RAM so I am not expecting it to freeze. Sometimes it has also frozen for several seconds, and one time Firefox just hung and I had to restart. I recall that when I ran htop the CPU and memory were not close to being maxed out—checking just now, most cores are less than 10% most of the time, and memory is around 27G out of 63G. There is no swap.

Some info:

[jr@fm ~]$ inxi -Fxxx
System:    Host: fm Kernel: 5.4.89-1-MANJARO x86_64 bits: 64 compiler: gcc v: 10.2.1 Desktop: KDE Plasma 5.20.5 tk: Qt 5.15.2 
           wm: kwin_x11 dm: SDDM Distro: Manjaro Linux 
Machine:   Type: Desktop Mobo: ASUSTeK model: TUF B450M-PLUS GAMING v: Rev X.0x serial: <superuser required> 
           UEFI: American Megatrends v: 1002 date: 03/07/2019 
CPU:       Info: 8-Core model: AMD Ryzen 7 2700X bits: 64 type: MT MCP arch: Zen+ rev: 2 L2 cache: 4 MiB 
           flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm bogomips: 118202 
           Speed: 1897 MHz min/max: 2200/3700 MHz boost: enabled Core speeds (MHz): 1: 1897 2: 1887 3: 2125 4: 4248 5: 3186 
           6: 2142 7: 2177 8: 2136 9: 2127 10: 4264 11: 2308 12: 2182 13: 2161 14: 2151 15: 1970 16: 1927 
Graphics:  Device-1: NVIDIA TU104 [GeForce RTX 2080] vendor: ASUSTeK driver: nvidia v: 460.32.03 bus ID: 07:00.0 
           chip ID: 10de:1e82 
           Display: x11 server: X.Org 1.20.10 compositor: kwin_x11 driver: loaded: nvidia resolution: 1: 1920x1080~60Hz 
           2: 1920x1080~60Hz s-dpi: 93 
           OpenGL: renderer: GeForce RTX 2080/PCIe/SSE2 v: 4.6.0 NVIDIA 460.32.03 direct render: Yes 
Audio:     Device-1: NVIDIA TU104 HD Audio vendor: ASUSTeK driver: snd_hda_intel v: kernel bus ID: 07:00.1 chip ID: 10de:10f8 
           Device-2: Advanced Micro Devices [AMD] Family 17h HD Audio vendor: ASUSTeK driver: snd_hda_intel v: kernel 
           bus ID: 09:00.3 chip ID: 1022:1457 
           Device-3: Logitech Webcam C270 type: USB driver: snd-usb-audio,uvcvideo bus ID: 1-4:3 chip ID: 046d:0825 
           serial: 8D1EA6E0 
           Sound Server: ALSA v: k5.4.89-1-MANJARO 
Network:   Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet vendor: ASUSTeK driver: r8169 v: kernel port: f000 
           bus ID: 05:00.0 chip ID: 10ec:8168 
           IF: enp5s0 state: up speed: 1000 Mbps duplex: full mac: 40:b0:76:5c:8c:4c 
Drives:    Local Storage: total: 465.76 GiB used: 39.64 GiB (8.5%) 
           ID-1: /dev/nvme0n1 vendor: Samsung model: SSD 970 EVO Plus 500GB size: 465.76 GiB speed: 31.6 Gb/s lanes: 4 
           serial: S4EVNG0M116780W rev: 1B2QEXM7 
Partition: ID-1: / size: 109.37 GiB used: 39.62 GiB (36.2%) fs: ext4 dev: /dev/nvme0n1p3 
           ID-2: /boot/efi size: 299.4 MiB used: 25.5 MiB (8.5%) fs: vfat dev: /dev/nvme0n1p1 
Swap:      Alert: No Swap data was found. 
Sensors:   System Temperatures: cpu: 50.5 C mobo: N/A gpu: nvidia temp: 40 C 
           Fan Speeds (RPM): N/A gpu: nvidia fan: 22% 
Info:      Processes: 348 Uptime: 2d 3h 48m wakeups: 120 Memory: 62.81 GiB used: 27.54 GiB (43.8%) Init: systemd v: 247 
           Compilers: gcc: 10.2.0 clang: 11.0.1 Packages: pacman: 1419 Shell: Bash v: 5.1.0 running in: konsole inxi: 3.2.02 
[jr@fm ~]$ 

As you can see there is an alert for no swap.

[jr@fm ~]$ yay systemd-swap
2 aur/systemd-swap-git 4.4.0.r4.g74d882f-1 (+1 0.01) 
    Script for creating hybrid swap space from zram swaps, swap files and swap partitions
1 community/systemd-swap 4.4.0-2 (15.3 KiB 39.9 KiB) (Installed)
    Script for creating hybrid swap space from zram swaps, swap files and swap partitions.
==> Packages to install (eg: 1 2 3, 1-3 or ^4)
==> ^C
[jr@fm ~]$ sudo systemctl enable systemd-swap.service
[sudo] password for jr: 
[jr@fm ~]$ cat /etc/systemd/swap.conf.d/myswap.conf
zswap_enabled=0
zram_enabled=0
swapfc_enabled=1
[jr@fm ~]$ cat /etc/fstab
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a device; this may
# be used with UUID= as a more robust way to name devices that works even if
# disks are added and removed. See fstab(5).
#
# <file system>             <mount point>  <type>  <options>  <dump>  <pass>
UUID=7B0E-8148                            /boot/efi      vfat    umask=0077 0 2
UUID=1e8aecd0-e0c4-4dd2-8320-8a8dd8df66c6 /              ext4    defaults,noatime 0 1
[jr@fm ~]$ swapon
[jr@fm ~]$ 

What should I do, any suggestions? Of course, I could minimize the amount of tabs that I keep open. Or revert to using manual swap management.

some thoughts:
As it is now, does your system have some swap space?
free
will tell you
as will
swapon --show

htop
will also, in the top left

Next: the Arch wiki, as well as the project page of the author which is linked to from there, do show a different configuration than the Manjaro wiki you followed.

The difference that I see is in the location of the configuration file.
It is supposed to be in
/etc/systemd/swap.conf
… in /etc/systemd
where all the other configuration files (with the .conf suffix) are

but yours is in a subdirectory swap.conf.d
/etc/systemd/swap.conf.d/myswap.conf

That seems wrong.
It could be as simple as that - wrong location of the config file.

1 Like

Coming back here because the issue happened just now with Firefox, it just hung. I could open other programs, switch to a different virtual desktop, but now when I switch to a tab it doesn’t load, and then switching to another tab, it also doesn’t load, although it did just a moment ago.

some thoughts:
As it is now, does your system have some swap space?

Nada

[jr@fm ~]$ swapon --show
[jr@fm ~]$ free
              total        used        free      shared  buff/cache   available
Mem:          64320       32541       24666        1056        7112       30089
Swap:             0           0           0
[jr@fm ~]$ 

It could be as simple as that - wrong location of the config file.

When I tried to close the terminal while htop was running, it didn’t close straight away, and then a few seconds later I got a warning prompting “there is a process running, are you sure that you want to close it?” So that all suggests an issue with the swap rather than Firefox.

[jr@fm ~]$ cat /etc/systemd/swap.conf.d/myswap.conf
zswap_enabled=0
zram_enabled=0
swapfc_enabled=1

These lines were commented out in this file as shown below, so I uncommented them in and flipped their values accordingly.

[jr@fm ~]$ cat /etc/systemd/swap.conf
#  This file is part of systemd-swap.
#
# Entries in this file show the systemd-swap defaults as
# specified in /usr/share/systemd-swap/swap-default.conf
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See swap.conf(5) and /usr/share/systemd-swap/swap-default.conf for details.

#zswap_enabled=1
#zswap_compressor=zstd
#zswap_max_pool_percent=25
#zswap_zpool=z3fold
#zram_enabled=0
#zram_size=$(( RAM_SIZE / 4 ))
#zram_count=${NCPU}
#zram_streams=${NCPU}
#zram_alg=zstd
#zram_prio=32767
#swapfc_enabled=0
#swapfc_force_use_loop=0
#swapfc_frequency=1
#swapfc_chunk_size=256M
#swapfc_max_count=32
#swapfc_min_count=0
#swapfc_free_ram_perc=35
#swapfc_free_swap_perc=15
#swapfc_remove_free_swap_perc=55
#swapfc_priority=50
#swapfc_path=/var/lib/systemd-swap/swapfc/
#swapfc_nocow=1
#swapfc_directio=1
#swapfc_force_preallocated=0
#swapd_auto_swapon=1
#swapd_prio=1024

And then I sudo rm /etc/systemd/swap.conf.d/myswap.conf

I will restart for the changes to take effect.

It took a few minutes to restart (which happened before as well)—noticeably longer than usual with some errors while loading.

But I still have:

[jr@fm ~]$ free
              total        used        free      shared  buff/cache   available
Mem:          64320        5914       56342         507        2064       57265
Swap:             0           0           0
[jr@fm ~]$ swapon --show
[jr@fm ~]$ cat /etc/systemd/swap.conf
#  This file is part of systemd-swap.
#
# Entries in this file show the systemd-swap defaults as
# specified in /usr/share/systemd-swap/swap-default.conf
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See swap.conf(5) and /usr/share/systemd-swap/swap-default.conf for details.

zswap_enabled=0
#zswap_compressor=zstd
#zswap_max_pool_percent=25
#zswap_zpool=z3fold
zram_enabled=0
#zram_size=$(( RAM_SIZE / 4 ))
#zram_count=${NCPU}
#zram_streams=${NCPU}
#zram_alg=zstd
#zram_prio=32767
swapfc_enabled=1
#swapfc_force_use_loop=0
#swapfc_frequency=1
#swapfc_chunk_size=256M
#swapfc_max_count=32
#swapfc_min_count=0
#swapfc_free_ram_perc=35
#swapfc_free_swap_perc=15
#swapfc_remove_free_swap_perc=55
#swapfc_priority=50
#swapfc_path=/var/lib/systemd-swap/swapfc/
#swapfc_nocow=1
#swapfc_directio=1
#swapfc_force_preallocated=0
#swapd_auto_swapon=1
#swapd_prio=1024
[jr@fm ~]$ 

If the service is active and running

systemctl status systemd-swap.service

then I don’t know how to debug this automatic mechanism.
Sorry!

The only thing I can think of is:
the swap will perhaps only then be created when it is actually needed.
That would make sense to me.
So you only get to have swap when you actually need it - and when that is is decided by systemd-swap …
But that is my speculation as of now.

If I where you I’d just use a regular swap file
as indeed I do. :wink:
easy peasy - no automatism can go wrong
and you can hibernate to disk

1 Like

This looks like not much RAM to begin with.
How much is that really?

This is mine - 8 GB RAM

$ LANG=C free
              total        used        free      shared  buff/cache   available
Mem:        8036244     1953028     3769800      657892     2313416     5167200
Swap:      10623292           0    10623292

or, more readable:

LANG=C free -h
              total        used        free      shared  buff/cache   available
Mem:          7.7Gi       1.9Gi       3.6Gi       656Mi       2.2Gi       4.9Gi
Swap:          10Gi          0B        10Gi
[jr@fm ~]$ systemctl status systemd-swap.service
● systemd-swap.service - Manage swap spaces on zram, files and partitions.
     Loaded: loaded (/usr/lib/systemd/system/systemd-swap.service; enabled; vendor preset: disabled)
     Active: active (running) since Tue 2021-02-02 02:23:40 AEDT; 12h ago
   Main PID: 631 (systemd-swap)
     Status: "Monitoring memory status..."
      Tasks: 1 (limit: 77091)
     Memory: 18.2M
     CGroup: /system.slice/systemd-swap.service
             └─631 /usr/bin/python3 -u /usr/bin/systemd-swap start

Feb 02 02:23:40 fm systemd[1]: Starting Manage swap spaces on zram, files and partitions....
Feb 02 02:23:40 fm systemd-swap[631]: INFO: Removing working directory...
Feb 02 02:23:40 fm systemd-swap[631]: INFO: Removing files in /var/lib/systemd-swap/swapfc/...
Feb 02 02:23:40 fm systemd-swap[631]: INFO: Writing destroy info...
Feb 02 02:23:40 fm systemd-swap[631]: INFO: swapD: pick up devices from systemd-gpt-auto-generator
Feb 02 02:23:40 fm systemd-swap[631]: INFO: swapD: searching swap devices
Feb 02 02:23:40 fm systemd-swap[631]: INFO: swapFC: on-demand swap activation at >41808 MiB memory usage
Feb 02 02:23:40 fm systemd[1]: Started Manage swap spaces on zram, files and partitions..
[jr@fm ~]$

I have 64 GB of RAM, total.

[jr@fm ~]$ free -h
              total        used        free      shared  buff/cache   available
Mem:           62Gi        23Gi        34Gi       1.1Gi       4.9Gi        37Gi
Swap:            0B          0B          0B
[jr@fm ~]$

It could be that automated swap management doesn’t think any swap is needed because there is already heaps of memory, but that doesn’t solve the problem of it freezing. I suppose reverting to using manual swap partitions is worth a try to fix it.