Solaris · Swap

Solaris · Lesson 21

Swap

Swap is part of Solaris virtual memory. Understanding the difference between physical RAM and swap, and knowing how to create and manage ZFS-based swap devices, is critical for real-world administration.

What is swap? How is it different from physical memory?

Solaris uses virtual memory, which combines physical RAM and swap space. Swap is disk space used to store memory pages when RAM is not enough.

Physical RAM

Fast semiconductor memory. Directly used by running processes. Limited but very fast.

Swap Space

Disk-based extension of memory. Much slower than RAM but allows more processes to run than physical RAM alone.

When RAM pressure increases, Solaris can move less-used pages to swap (paging out). When needed again, pages are read back into RAM (paging in). Excessive swap I/O (thrashing) usually means the system needs more RAM or fewer workloads.

Swap implementation in Solaris (ZFS volumes)

On modern Solaris systems, swap is often provided by ZFS volumes (zvols) inside the root pool rpool, exposed as block devices under /dev/zvol/dsk.

This gives flexibility: you can create, resize or remove swap volumes using zfs commands, and then activate or deactivate them dynamically using swap commands.

Swap commands and ZFS integration – step by step

Use these flows in your lab Solaris system. Be careful on production systems, especially if memory is already tight.

1. Check memory and swap with top

top (or prstat) gives a quick view of RAM, swap and process usage.

terminal — swap
solaris-lab
[root@solaris ~]# top
last pid: 3210; load averages: 0.25, 0.20, 0.15 up 10+04:20:10 10:12:34
98 processes: 95 sleeping, 2 running, 1 zombie
CPU states: 2.0% user, 3.0% kernel, 95.0% idle
Memory: 8192M real, 2048M free, 4096M swap in use, 8192M swap free

2. swap -l and swap -s – what do they show?

swap -l shows swap devices; swap -s shows virtual memory summary (allocated, reserved, available).

terminal — swap
solaris-lab
[root@solaris ~]# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 256,1 16 4194288 4194288
 
[root@solaris ~]# swap -s
total: 1024M allocated + 512M reserved = 1536M used, 6656M available
 
# Meaning:
# allocated = actually used swap
# reserved = promised to processes but not yet used
# available = free virtual memory (RAM + swap still available)

3. Check existing ZFS swap volume size

In Solaris 11, default swap is often a ZFS volume in rpool. volsize is the logical volume size.

terminal — swap
solaris-lab
[root@solaris ~]# zfs list rpool/swap
NAME USED AVAIL REFER MOUNTPOINT
rpool/swap 2.00G 30G 2.00G - # (ZFS volume, not a filesystem)
 
[root@solaris ~]# zfs get volsize rpool/swap
NAME PROPERTY VALUE SOURCE
rpool/swap volsize 2G local

4. Create new ZFS volume for swap (step-by-step)

Create a ZFS volume (block device) that we can later add as swap with swap -a.

terminal — swap
solaris-lab
# Create a 4G ZFS volume
[root@solaris ~]# zfs create -V 4G rpool/swap2
 
[root@solaris ~]# zfs list rpool/swap2
NAME USED AVAIL REFER MOUNTPOINT
rpool/swap2 4.00G 30G 16K -
 
# Confirm volsize
[root@solaris ~]# zfs get volsize rpool/swap2
NAME PROPERTY VALUE SOURCE
rpool/swap2 volsize 4G local

5. Enable the new swap device (swap -a)

Use the ZFS volume device path from /dev/zvol/dsk. swap -a makes it active immediately.

terminal — swap
solaris-lab
[root@solaris ~]# ls -l /dev/zvol/dsk/rpool/swap2
lrwxrwxrwx 1 root root 50 Jan 11 10:30 /dev/zvol/dsk/rpool/swap2 -> ../../devices/.../rpool%2Fswap2
 
[root@solaris ~]# swap -a /dev/zvol/dsk/rpool/swap2
 
[root@solaris ~]# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 256,1 16 4194288 4194288
/dev/zvol/dsk/rpool/swap2 256,3 16 8388576 8388576

6. Remove swap device (swap -d) and keep ZFS volume

swap -d removes it from active swap. ZFS volume still exists and can be reused or destroyed later.

terminal — swap
solaris-lab
[root@solaris ~]# swap -d /dev/zvol/dsk/rpool/swap2
 
[root@solaris ~]# swap -l
swapfile dev swaplo blocks free
/dev/zvol/dsk/rpool/swap 256,1 16 4194288 4194288
 
# If you no longer need the swap volume:
[root@solaris ~]# zfs destroy rpool/swap2

Command cheat sheet – swap & ZFS

Monitoring swap

  • top → quick view of memory + swap usage
  • swap -l → list swap devices and sizes
  • swap -s → virtual memory summary (allocated/reserved/available)

Managing ZFS-based swap

  • zfs get volsize rpool/swap → see default swap volume size
  • zfs create -V 4G rpool/swap2 → create 4G swap volume
  • swap -a /dev/zvol/dsk/rpool/swap2 → activate new swap
  • swap -d /dev/zvol/dsk/rpool/swap2 → deactivate swap
  • zfs destroy rpool/swap2 → remove swap volume (after swap -d)

Important safety notes for swap changes

  • Never remove all swap from a busy system – it may cause performance collapse or even panics under heavy load.
  • Always check swap -s and top before disabling a swap device.
  • For permanent swap entries across reboots, you typically add the swap volume to /etc/vfstab (do this only when you fully understand your environment policies).
  • Avoid placing critical application data on the same disks that are heavily used for swap, to reduce I/O contention.

In the next topics, this understanding will help when tuning performance, planning memory, and troubleshooting slow systems.