Problem
My system is configured to swap to the default swap device on the
root disk. This is impacting my system performance. I want to
move the swap area to a different drive that isn't as busy. Is
there an easy way to do this?NOTE: The best solution is to prevent the system from swapping in the
first place. Memory access is on the order of 20-100 times faster
than disk access, so any swapping is going to have a huge impact
on system performance. Overhead of the swapping mechanism makes
the performance degradation even worse. Solution
There is more than one way to accomplish this. This article
addresses moving the swap space to a regular file on an existing
filesystem. In most cases, this is perhaps the easiest way, in
that it requires no reconfiguring of the divvy tables for any of
the disks. There are drawbacks to this method.One drawback is that this doesn't free up the space currently used
by /dev/swap on the root hard disk. Another is that swapping to a
file, instead of a raw device, introduces even more overhead because
all reads and writes must now go through the filesystem.Swap space can be manipulated using the swap(ADM) command. If you want to add swap space using a file on a mounted filesystem, use the following commands:
>/u/swap
swap -a /u/swap 100000where /u would be replaced by the mount point for the filesystem
and 100000 would be replaced by the number of 512 byte blocks to
be used. This space will not actually be taken from the filesystem
until it is needed by the memory management subsystem.To see the configured swap space, use the command swap -l. The output will now look something like this:
# swap -l
path dev swaplo blocks free
/dev/swap 1,41 0 131064 98144
/u/swap 76,1 0 100000 100000Note the /dev/swap will still be the primary swap device. The
swap space just added will not be used until the primary has been
used up. If your goal is to have all the swap activity on a
secondary disk, you need to delete the swap space allocated to
/dev/swap with the command:swap -d /dev/swapIf this swap space is in use, this command may take a little while
to complete as the system will move the blocks allocated on
/dev/swap to /u/swap. Once this is done, the system will no
longer use /dev/swap for swapping.NOTE: Deleting swap with the swap(ADM) command doesn't delete the
swap division. It only removes it from the list of devices
that can be swapped to. When the system is rebooted, the swap
list will revert to the default.To have the swap moved automatically at boot time, add these lines to /etc/rc2.d/P88USRDEFINE:
> /u/swap
swap -a /u/swap 100000 && swap -d /dev/swap || echo \
"Couldn't add swap device\\nSwapping to /dev/swap\\n" \
| mail -s "Swap add failed" rootThe conditional statement prevents /dev/swap from being deleted
if the addition of the secondary swap fails. It also causes mail
to be sent to root with notification of the problem.NOTE: The space in /u/swap will not be available as a dump device. If
you need to increase available swap space so there is room for a
panic dump, you must use divvy to increase the size of the existing
swap device or create a new dump device that is large enough to
hold the entire contents of physical memory. If /dev/swap is large
enough to hold a panic dump, then you can continue to use it as the
dump device.