Swap not enabled. How to diagnose and enable?

Hello. I can’t figure out why swap is not enabled on my system.
Running free gives

root@truenas:~# free -h
               total        used        free      shared  buff/cache   available
Mem:            15Gi        14Gi       341Mi        90Mi       945Mi       894Mi
Swap:             0B          0B          0B

My TrueNAS Scale 24.04.2 installation has the following drives

root@truenas:~# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINTS
sda           8:0    0 223.6G  0 disk
├─sda1        8:1    0     1M  0 part
├─sda2        8:2    0   512M  0 part
├─sda3        8:3    0 207.1G  0 part
└─sda4        8:4    0    16G  0 part
  └─md127     9:127  0    16G  0 raid1
    └─md127 253:0    0    16G  0 crypt
sdb           8:16   0  16.4T  0 disk
├─sdb1        8:17   0     4G  0 part
└─sdb2        8:18   0  16.4T  0 part
sdc           8:32   0 223.6G  0 disk
├─sdc1        8:33   0     1M  0 part
├─sdc2        8:34   0   512M  0 part
├─sdc3        8:35   0 207.1G  0 part
└─sdc4        8:36   0    16G  0 part
  └─md127     9:127  0    16G  0 raid1
    └─md127 253:0    0    16G  0 crypt
sdd           8:48   0   3.6T  0 disk
├─sdd1        8:49   0     2G  0 part
└─sdd2        8:50   0   3.6T  0 part
sde           8:64   0   3.6T  0 disk
├─sde1        8:65   0     2G  0 part
└─sde2        8:66   0   3.6T  0 part
sdf           8:80   0   3.6T  0 disk
├─sdf1        8:81   0     2G  0 part
└─sdf2        8:82   0   3.6T  0 part
sdg           8:96   0   3.6T  0 disk
├─sdg1        8:97   0     2G  0 part
└─sdg2        8:98   0   3.6T  0 part
sdh           8:112  0 232.9G  0 disk
├─sdh1        8:113  0     4G  0 part
└─sdh2        8:114  0 228.9G  0 part
sdi           8:128  0 232.9G  0 disk
├─sdi1        8:129  0     4G  0 part
└─sdi2        8:130  0 228.9G  0 part
zd0         230:0    0   204G  0 disk
zd16        230:16   0    32G  0 disk

sda and sdc are the mirrored boot drives which clearly have the 16GiB partitions created during installation.

How can I diagnose why swap is not enabled and not used? I tried the logs but found no errors related to swap.
The only related messages are these:

Jul 18 17:02:46 tnsbuilds01.tn.ixsystems.net kernel: Adding 16759804k swap on /dev/mapper/md127.  Priority:-2 extents:1 across:16759804k
Jul 18 17:02:46 tnsbuilds01.tn.ixsystems.net systemd[1]: dev-disk-by\x2did-dm\x2duuid\x2dCRYPT\x2dPLAIN\x2dmd127.swap: Deactivated successfully.
Jul 18 17:02:46 tnsbuilds01.tn.ixsystems.net systemd[1]: dev-mapper-md127.swap: Deactivated successfully.
Jul 18 17:02:46 tnsbuilds01.tn.ixsystems.net systemd[1]: dev-disk-by\x2did-dm\x2dname\x2dmd127.swap: Deactivated successfully.
Jul 18 17:02:46 tnsbuilds01.tn.ixsystems.net systemd[1]: dev-dm\x2d0.swap: Deactivated successfully.
Jul 18 17:02:46 tnsbuilds01.tn.ixsystems.net systemd[1]: Finished ix-swap.service - Configure swap filesystem on boot pool.

How can I configure to enable swap?

There was a bug recently that caused agressive swap usage and therefore the devs decided to disable swap by default.

You should be going to the GUI to look at memory and zfs. zfs could be just using memory for it’s read cache. It gives it up for other uses if necessary.

Thanks! Indeed it is in the 24.04.1 changelog. In this case I will wait for a follow-up update.

Interestingly running swapon -a as suggested in the PR NAS-128988 / 24.04.2 / disable swap by default (by yocalebo) by bugclerk · Pull Request #13733 · truenas/middleware (github.com) does nothing for me.

Additionally looking at swapon’s help page

-a, --all                enable all swaps from /etc/fstab

but my fstab does not include anything related to swap

boot-pool/grub  /boot/grub      zfs     relatime,defaults       0       0
tmpfs   /run/lock       tmpfs   rw,nosuid,nodev,noexec,relatime,size=100m       0       0

Could there be an additional unrelated issue preventing swap on my system?

Are you having issues with memory currently?

I’m running a windows vm and a dozen docker containers in jailmaker with only 16 GiB memory.

I’ve had a few incidents where the OOM killer killed some containers or the vm or even middlewared. I know swapping is slow and bad for performance but performance is not my goal for this home server. I just want to make sure no services are killed and would prefer them to be swapped out if they go unused for a while.

2 Likes

Try searching the forum for this. I have seen it discussed lately but your case is a bit different with small RAM.
One link to check out.

Thanks I had a look at the forums and I did find users facing similar issues.

However I was unable to find information on how to enable swap or if it cannot be enabled manually how to trigger the conditions so that it is automatically enabled.

1 Like

Maybe this?

1 Like

Thanks a lot! That actually worked!
I didn’t realize I had to use /dev/mapper/md127 as the device.

1 Like

One thing to watch for is some dataset management tasks force your swap space to turn back off. I was replacing a drive and suddenly had no swap.

1 Like