This page provides an introduction to swap space and paging on PacBSD. It covers creation and activation of swap partitions and swap files.
- In computer operating systems, paging is a memory management scheme by which a computer stores and retrieves data from secondary storage[a] for use in main memory. In this scheme, the operating system retrieves data from secondary storage in same-size blocks called pages. Paging is an important part of virtual memory implementations in modern operating systems, using secondary storage to let programs exceed the size of available physical memory.
Swap space can either be a disk partition or a file on the system. Users may create a swap space during installation of PacBSd or at any later time should it become necessary. Swap space is generally recommended for users with less that 1GB of RAM, but becomes more a matter of personal preference on systems with gratuitous amounts of physical RAM.
To check swap status use:
An easy way to make a partition for using as swap space is with
# gpart add -s 1g -t freebsd-swap ada0
The above command will create a new partition on /dev/ada0 that is 1 GB in size for use as swap space.
The partition can be formatted and used as swap space with one command:
# swapon /dev/ada0s1
This will format the partition as swap space and immediately make it available to the system for use.
To automatically add this swap partition on boot, add an entry to /etc/fstab:
# echo "/dev/ada0s1 none swap sw 0 0" >> /etc/fstab
As an alternative to creating an entire partition, a swap file offers the ability to vary the size on-the-fly, and is more easily removed altogether.
Create the swap file:
# dd if=/dev/zero of=/usr/swap0 bs=1m count=64
This creates a 64Mb /usr/swap0 file that can be used as swap space rather than a partition.
Set the proper permissions on the new file:
# chmod 0600 /usr/swap0
Add the file to /etc/fstab:
# echo "md99 none swap sw,file=/usr/swap0,late 0 0" >> /etc/fstab
This will add the swap space on the system boot, to add it immediately use
# swapon -aL
ZFS Swap Volume
PacBSD is able to use a ZFS pre-allocated volume as your swap area. The only disadvantage is that you will no more be able to save core dumps in your swap volume, because PacBSD can only save them in a separate swap partition. So, if you want to save core dumps, please consider to create a swap partition with gpart, as described in the Official Installation Guide, and skip this step. A swap volume should have the checksum property turned off and it should be a pre-allocated volume.
# zfs create -V2G -o checksum=off -o org.freebsd:swap=on tank/swap
-V2G parameter is necessary to make a pre-allocated volume. ZFS cannot manage swap area on a normal dataset.
Remember that in every pre-allocated volumes you cannot use the quota property for limiting the volume's capacity.
org.freebsd:swap is a special property of FreeBSD (and PacBSD) for manage the swap area with ZFS.