Systemd-swap problem?

Mod-edit: Formatting and spelling


I have not used a swap the last couple of years, because I have 32GB RAM and have never even been close to maxing out my RAM.
But a few days ago I installed OpenShot and started working on videos and when I export the videos, it uses a lot of RAM, and yesterday I had my first freeze when memory was at 31.7 GB.
My guess is that, of course, that was an out of memory-freeze.

So I tried to set up systemd-swap by following this guide.

I got no errors while following this guide, and I don’t see any errors in journalct after the reboot.
By using journalctl -n 1000 | grep swap I get the following result, which to me seems ok?:

dec 27 19:30:22 CURIE systemd[1]: Starting Manage swap spaces on zram, files and partitions....
dec 27 19:30:23 CURIE systemd-swap[744]: INFO: Load: /etc/systemd/swap.conf.d/myswap.conf
dec 27 19:30:23 CURIE systemd-swap[744]: INFO: Removing working directory...
dec 27 19:30:23 CURIE systemd-swap[744]: INFO: Removing files in /var/lib/systemd-swap/swapfc/...
dec 27 19:30:23 CURIE systemd-swap[744]: INFO: Load: /etc/systemd/swap.conf.d/myswap.conf
dec 27 19:30:23 CURIE systemd-swap[744]: INFO: Writing destroy info...
dec 27 19:30:23 CURIE systemd-swap[744]: INFO: swapD: pick up devices from systemd-gpt-auto-generator
dec 27 19:30:23 CURIE systemd-swap[744]: INFO: swapD: searching swap devices
dec 27 19:30:23 CURIE systemd-swap[744]: INFO: swapFC: on-demand swap activation at >20874 MiB memory usage
dec 27 19:30:23 CURIE audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 subj==unconfined msg='unit=systemd-swap comm="systemd" exe="/usr/lib/systemd/systemd" hostname=? addr=? terminal=? res=success'
dec 27 19:30:23 CURIE systemd[1]: Started Manage swap spaces on zram, files and partitions..

Still swapon -s gives me no result, but if I interpret the wiki correctly I should see something similar to this:

NAME                           TYPE SIZE USED PRIO
/var/lib/systemd-swap/swapfc/1 file 512M   0B   -2

Can I assume that it is working, even though swapon gives no result?
Has systemd-swap just chosen to not use a swap file for now?
Will the swap file be created when I start exporting in OpenShot again?

A not so important follow up question:

  • Will a swap eventually stop the applications from asking for more memory (or rather, will the kernel eventually tell the applications “no, you can’t have more memory, I’m out”)?
    Otherwise I don’t see why I wouldn’t get a new freeze at 64GB used RAM (if I in this example had 32GB swap), or that the swap file would eventually fill the entire hard drive (when using an automatically handled swap file, like systemd-swap)?
Inxi
Inxi -Fayz
System:
  Kernel: 5.4.80-2-MANJARO x86_64 bits: 64 compiler: gcc v: 10.2.0 
  parameters: BOOT_IMAGE=/boot/vmlinuz-5.4-x86_64 
  root=UUID=5f0455e6-c280-495c-a6fb-976924a79721 rw quiet apparmor=1 
  security=apparmor udev.log_priority=3 
  Desktop: Cinnamon 4.8.0 tk: GTK 3.24.23 dm: LightDM 1.30.0 
  Distro: Manjaro Linux 
Machine:
  Type: Desktop System: Inet_AB product: N/A v: N/A serial: <filter> 
  Mobo: ASUSTeK model: PRIME B450M-A v: Rev X.0x serial: <filter> 
  UEFI: American Megatrends v: 2006 date: 11/13/2019 
CPU:
  Info: 6-Core model: AMD Ryzen 5 3600 bits: 64 type: MT MCP arch: Zen 2 
  family: 17 (23) model-id: 71 (113) stepping: N/A microcode: 8701013 
  L2 cache: 3072 KiB 
  flags: avx avx2 lm nx pae sse sse2 sse3 sse4_1 sse4_2 sse4a ssse3 svm 
  bogomips: 86277 
  Speed: 2697 MHz min/max: 2200/3600 MHz boost: enabled Core speeds (MHz): 
  1: 2697 2: 3050 3: 2391 4: 2220 5: 2092 6: 2327 7: 2294 8: 2191 9: 3249 
  10: 2015 11: 2097 12: 3577 
  Vulnerabilities: Type: itlb_multihit status: Not affected 
  Type: l1tf status: Not affected 
  Type: mds status: Not affected 
  Type: meltdown status: Not affected 
  Type: spec_store_bypass 
  mitigation: Speculative Store Bypass disabled via prctl and seccomp 
  Type: spectre_v1 
  mitigation: usercopy/swapgs barriers and __user pointer sanitization 
  Type: spectre_v2 mitigation: Full AMD retpoline, IBPB: conditional, STIBP: 
  conditional, RSB filling 
  Type: srbds status: Not affected 
  Type: tsx_async_abort status: Not affected 
Graphics:
  Device-1: AMD Ellesmere [Radeon RX 470/480/570/570X/580/580X/590] 
  vendor: Sapphire Limited Nitro+ driver: amdgpu v: kernel bus ID: 08:00.0 
  chip ID: 1002:67df 
  Display: x11 server: X.Org 1.20.10 driver: amdgpu,ati unloaded: modesetting 
  alternate: fbdev,vesa display ID: :0 screens: 1 
  Screen-1: 0 s-res: 5760x1080 s-dpi: 96 s-size: 1524x285mm (60.0x11.2") 
  s-diag: 1550mm (61") 
  Monitor-1: DisplayPort-0 res: 1920x1080 hz: 60 dpi: 82 
  size: 598x336mm (23.5x13.2") diag: 686mm (27") 
  Monitor-2: DisplayPort-1 res: 1920x1080 hz: 60 dpi: 82 
  size: 598x336mm (23.5x13.2") diag: 686mm (27") 
  Monitor-3: DVI-D-0 res: 1920x1080 hz: 60 dpi: 82 
  size: 598x336mm (23.5x13.2") diag: 686mm (27") 
  OpenGL: renderer: Radeon RX 580 Series (POLARIS10 DRM 3.35.0 
  5.4.80-2-MANJARO LLVM 11.0.0) 
  v: 4.6 Mesa 20.2.3 direct render: Yes 
Audio:
  Device-1: AMD Ellesmere HDMI Audio [Radeon RX 470/480 / 570/580/590] 
  vendor: Sapphire Limited driver: snd_hda_intel v: kernel bus ID: 08:00.1 
  chip ID: 1002:aaf0 
  Device-2: AMD Starship/Matisse HD Audio vendor: ASUSTeK 
  driver: snd_hda_intel v: kernel bus ID: 0a:00.4 chip ID: 1022:1487 
  Device-3: Logitech Logitech BRIO type: USB 
  driver: hid-generic,snd-usb-audio,usbhid,uvcvideo bus ID: 4-4:2 
  chip ID: 046d:085e serial: <filter> 
  Sound Server: ALSA v: k5.4.80-2-MANJARO 
Network:
  Device-1: Realtek RTL8111/8168/8411 PCI Express Gigabit Ethernet 
  vendor: ASUSTeK driver: r8169 v: kernel port: f000 bus ID: 07:00.0 
  chip ID: 10ec:8168 
  IF: enp7s0 state: up speed: 1000 Mbps duplex: full mac: <filter> 
  IF-ID-1: tun0 state: unknown speed: 10 Mbps duplex: full mac: N/A 
Drives:
  Local Storage: total: 3.40 TiB used: 1.39 TiB (40.8%) 
  SMART Message: Required tool smartctl not installed. Check --recommends 
  ID-1: /dev/sda vendor: Toshiba model: TR200 size: 223.57 GiB block size: 
  physical: 512 B logical: 512 B speed: 6.0 Gb/s serial: <filter> rev: 15.3 
  scheme: MBR 
  ID-2: /dev/sdb vendor: Western Digital model: WD20EZRZ-00Z5HB0 
  size: 1.82 TiB block size: physical: 4096 B logical: 512 B speed: 6.0 Gb/s 
  rotation: 5400 rpm serial: <filter> rev: 0A80 scheme: GPT 
  ID-3: /dev/sdc vendor: Samsung model: SSD 850 EVO 500GB size: 465.76 GiB 
  block size: physical: 512 B logical: 512 B speed: 6.0 Gb/s serial: <filter> 
  rev: 1B6Q scheme: GPT 
  ID-4: /dev/sdd vendor: Samsung model: SSD 850 EVO 1TB size: 931.51 GiB 
  block size: physical: 512 B logical: 512 B speed: 6.0 Gb/s serial: <filter> 
  rev: 3B6Q scheme: GPT 
Partition:
  ID-1: / raw size: 931.22 GiB size: 915.60 GiB (98.32%) 
  used: 243.92 GiB (26.6%) fs: ext4 dev: /dev/sdd2 
Swap:
  Alert: No Swap data was found. 
Sensors:
  System Temperatures: cpu: 48.0 C mobo: N/A gpu: amdgpu temp: 37.0 C 
  Fan Speeds (RPM): N/A gpu: amdgpu fan: 828 
Info:
  Processes: 351 Uptime: 12h 36m Memory: 31.36 GiB used: 4.17 GiB (13.3%) 
  Init: systemd v: 246 Compilers: gcc: 10.2.0 clang: 11.0.0 Packages: 1286 
  pacman: 1270 lib: 355 flatpak: 8 snap: 8 Shell: Bash v: 5.0.18 
  running in: gnome-terminal inxi: 3.1.08

Nope, if you don’t have a result for swapon -s it means it isn’t active.
Can you give us:

cat /proc/sys/vm/swappiness
cat /proc/sys/vm/vfs_cache_pressure
ls /etc/systemd/swap.conf.d
cat /etc/systemd/swap.conf.d/myswap.conf
systemctl status systemd-swap

My way of setting up systemd-swap is a little different from the tuto you mentionned:

Mod-edit: Formatting and spelling


> cat /proc/sys/vm/swappiness
60
> cat /proc/sys/vm/vfs_cache_pressure
100
> cat /proc/sys/vm/vfs_cache_pressure
zswap_enabled=0
zram_enabled=0
swapfc_enabled=1
> systemctl-status systemd-swap
bash: systemctl-status: command not found

I will try to follow your guide instead.
I saw the link to that in the forum yesterday, but I didn’t click on it because I don’t speak french :slight_smile:
But you had an English version as well…

Oops my typo:

systemctl status systemd-swap

if you use my tutorial, then remove the file you created:

sudo rm /etc/systemd/swap.conf.d/myswap.conf

Mod-edit: Formatting


● 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 Mon 2020-12-28 08:37:43 CET; 41min ago
   Main PID: 747 (systemd-swap)
     Status: "Monitoring memory status..."
      Tasks: 1 (limit: 38441)
     Memory: 17.5M
     CGroup: /system.slice/systemd-swap.service
             └─747 /usr/bin/python3 -u /usr/bin/systemd-swap start

dec 28 08:37:42 CURIE systemd[1]: Starting Manage swap spaces on zram, files and partitions....
dec 28 08:37:43 CURIE systemd-swap[747]: INFO: Load: /etc/systemd/swap.conf.d/myswap.conf
dec 28 08:37:43 CURIE systemd-swap[747]: INFO: Removing working directory...
dec 28 08:37:43 CURIE systemd-swap[747]: INFO: Removing files in /var/lib/systemd-swap/swapfc/...
dec 28 08:37:43 CURIE systemd-swap[747]: INFO: Load: /etc/systemd/swap.conf.d/myswap.conf
dec 28 08:37:43 CURIE systemd-swap[747]: INFO: Writing destroy info...
dec 28 08:37:43 CURIE systemd-swap[747]: INFO: swapD: pick up devices from systemd-gpt-auto-generator
dec 28 08:37:43 CURIE systemd-swap[747]: INFO: swapD: searching swap devices
dec 28 08:37:43 CURIE systemd-swap[747]: INFO: swapFC: on-demand swap activation at >20874 MiB memory usage
dec 28 08:37:43 CURIE systemd[1]: Started Manage swap spaces on zram, files and partitions..

Well, there it seems to be active.
What did you do ?
Did you activate zswap ?

I followed your guide, and now I get the following output of all the commands that you suggested (and swapon):

Now it looks like it is working correctly.

I do have an SSD, is 5/50 ok for swappiness and cache_pressure? I followed the SSD link in your article, and it said to set swapiness to 1, but it resets back to 5?

This was after I followed the Manjaro guide…

I don’t know, if the Manjaro guide told me to activate it, I did so…

But, when I followed your guide, it seems to work…

Side-note @Hultan, In future please:

  • Use line-breaks after a sentence ends, this will improve readability for everyone.
    And thus helps to help others help you better.
  • Don’t use screenshots unless explicitly asked for.
    Especially with terminal output of commands, this is because then the person trying to help you can quote parts of it to give you better feedback on those parts.

Thanks :wink:

1 Like

That is not how I was taught to write sentences/paragraphs in school. But that was 40 years ago, so maybe things have changed. So sure…:slight_smile:

Got it :slight_smile:

yes :slight_smile:

For the swappiness, give us:

ls  /etc/sysctl.d
per@CURIE : ~ > cat /etc/sysctl.d/99-swappiness.conf
vm.swappiness = 1

per@CURIE : ~ > cat /etc/sysctl.d/99-sysctl.conf
vm.swappiness=5
vm.vfs_cache_pressure=50

Is this correct? Swapiness is 1 and/or 5 :slight_smile:

That kind of files are parsed in alphabetic sequence, that’s why they use the numbers in front of the file-names.
In this case they both have the same number so the next chars are used for the sorting :slight_smile:
That last one (alphabetically) wins as final setting…

1 Like

I’ll amend my tutorial: I gave different names for the conf file, thus they conflict :wink:

To correct this:

sudo sed -i 's/=5/=1/g' /etc/sysctl.d/99-sysctl.conf
sudo rm /etc/sysctl.d/99-swappiness.conf
1 Like

Now that the main issue is solved, does anyone have an answer to my follow-up-question?

  • Will a swap eventually stop the applications from asking for more memory (or rather, will the kernel eventually tell the applications “no, you can’t have more memory, I’m out”)?
    Otherwise I don’t see why I wouldn’t get a new freeze at 64GB used RAM (if I in this example had 32GB swap), or that the swap file would eventually fill the entire hard drive (when using an automatically handled swap file, like systemd-swap )?

I am curios if a swap file really solves my problem (with the out-of-memory-freeze) or if it just pushes the problem on to the future.

Swap functionality of the kernel is not a functionality to increase usable RAM in general…
The kernel will only “put-aside” processes and data, that are in-memory but not needed at that moment, inside the swap (file/partition).
So if your application needs more active memory then you will still get the OOM error…

Here is a random page i found using a search engine about swap in linux:

1 Like

The problem is that you have 2 times the same info.

Move vm.vfs_cache_pressure=50 to /etc/sysctl.d/99-swappiness.conf and delete the file /etc/sysctl.d/99-sysctl.conf

This is my /etc/sysctl.d/99-swappiness.conf

~ > cat /etc/sysctl.d/99-swappiness.conf
vm.swappiness=1
vm.vfs_cache_pressure=50

You should keep everything in 99-swappiness.conf and delete 99-sysctl.conf as the filename makes much more sense that way.

2 Likes

I followed you advice and ran sudo mv 99-sysctl.conf 99-swappiness.conf.
The extra file is already deleted.

1 Like

Its also a good idea to add this file:

cat /etc/systemd/swap.conf.d/overrides.conf
swapfc_enabled=1
swapfc_min_count=1
swapfc_chunk_size=512M

This way, it will only allocate 512Mb, and increase the swap file dynamically in chunks of 512Mb as needed. (you can of course replace 512M with 1G or 2G,… as you want.