Is it possible to reduce or disable swap memory on FreeBSD? In this example, 32 GB swap is enabled by using 16 GB on each of 2 SSDs. I would prefer this to be closer to 8 GB by using 4 GB on each of 2 SSDs.
Information about current swap devices.
Get information about currently active swap devices and sizes.
# swapinfo -h
Device Size Used Avail Capacity
/dev/nda0p3 16G 0B 16G 0%
/dev/nda1p3 16G 0B 16G 0%
Total 32G 0B 32G 0%
Get information about partitions on disks and GEOM providers. Each device and partition has a unique identifier, that can be used to make changes.
# gpart show
=> 40 4000797280 nda0 GPT (1.9T)
40 532480 1 efi (260M)
532520 1024 2 freebsd-boot (512K)
533544 984 - free - (492K)
534528 33554432 3 freebsd-swap (16G)
34088960 3966707712 4 freebsd-zfs (1.8T)
4000796672 648 - free - (324K)
=> 40 3907029088 nda1 GPT (1.8T)
40 532480 1 efi (260M)
532520 1024 2 freebsd-boot (512K)
533544 984 - free - (492K)
534528 33554432 3 freebsd-swap (16G)
34088960 3872940032 4 freebsd-zfs (1.8T)
3907028992 136 - free - (68K)
The devices can be listed. This also shows the naming convention for the partitions.
# gpart status
nda0p1 OK nda0
nda0p2 OK nda0
nda0p3 OK nda0
nda0p4 OK nda0
nda1p1 OK nda1
nda1p2 OK nda1
nda1p3 OK nda1
nda1p4 OK nda1
Disabling swap on FreeBSD.
Move swapped pages out from swap devices and disable them.
# swapoff -a
swapoff: removing /dev/nda0p3 as swap device
swapoff: removing /dev/nda1p3 as swap device
If you want to re-enable swap, it is as easy as reverting that.
# swapon -a
swapon: adding /dev/nda0p3 as swap device
swapon: adding /dev/nda1p3 as swap device
Reducing swap partitions?
Is it possible to reduce the swap partition on each SSD and then have ZFS use the free space? Is it possible to split the partitions?
Deleting swap partitions?
Delete or comment out the swap partitions from the static information about file systems. This ensures, that they do not get re-mounted during boot.
# nano /etc/fstab
# Device Mountpoint FStype Options Dump Pass#
/dev/gpt/efiboot0 /boot/efi msdosfs rw 2 2
#/dev/nda0p3 none swap sw 0 0
#/dev/nda1p3 none swap sw 0 0
proc /proc procfs rw 0 0
Is it possible to delete the swap partition on each SSD and then have ZFS use the free space? The handbook does mention growing partitions, but it is not clear, if ZFS can in fact grow directly or it will be necessary to re-create partitions, format, import and encrypt.
Links
- Add swap
- 20.3. Resizing and Growing Disks in FreeBSD Handbook.