<chapter id="fsswap-14677"><title>Configuring Additional Swap Space
(Tasks)</title><highlights><para>This chapter provides guidelines and step-by-step instructions for configuring
additional swap space after the Solaris OS is installed.</para><para>This is a list of the step-by-step instructions in this chapter.</para><itemizedlist><listitem><para><olink targetptr="fsswap-37376" remap="internal">How to Create a Swap File
and Make It Available</olink></para>
</listitem><listitem><para><olink targetptr="fsswap-13" remap="internal">How to Remove Unneeded Swap Space</olink></para>
</listitem>
</itemizedlist><para>This is a list of the overview information in this chapter.</para><itemizedlist><listitem><para><olink targetptr="fsswap-29713" remap="internal">About Swap Space</olink></para>
</listitem><listitem><para><olink targetptr="fsswap-31555" remap="internal">How Do I Know If I Need More
Swap Space?</olink></para>
</listitem><listitem><para><olink targetptr="fsswap-66891" remap="internal">How Swap Space Is Allocated</olink></para>
</listitem><listitem><para><olink targetptr="fsswap-31050" remap="internal">Planning for Swap Space</olink></para>
</listitem><listitem><para><olink targetptr="fsswap-52195" remap="internal">Monitoring Swap Resources</olink></para>
</listitem><listitem><para><olink targetptr="fsswap-59089" remap="internal">Adding More Swap Space</olink></para>
</listitem>
</itemizedlist>
</highlights><sect1 id="fsswap-29713"><title>About Swap Space</title><para>You should understand the features of the <trademark>SunOS</trademark> swap
mechanism to determine the following:</para><itemizedlist><listitem><para>Swap space requirements</para>
</listitem><listitem><para>The relationship between swap space and the TMPFS file system</para>
</listitem><listitem><para>How to recover from error messages related to swap space</para>
</listitem>
</itemizedlist><sect2 id="fsswap-89187"><title>Swap Space and Virtual Memory</title><para>Solaris
software uses some disk slices for temporary storage rather than for file
systems. These slices are called <emphasis>swap</emphasis> slices. Swap slices
are used as virtual memory storage areas when the system does not have enough
physical memory to handle current processes.     </para><para>The virtual memory system maps physical copies of files on disk to virtual
addresses in memory. Physical memory pages that contain the data for these
mappings can be backed by regular files in the file system, or by swap space.
If the memory is backed by swap space it is referred to as <emphasis>anonymous</emphasis> <emphasis>memory</emphasis> because no identity is assigned to the disk space that is
backing the memory.</para><para>The Solaris OS uses the concept of <emphasis>virtual swap space</emphasis>,
a layer between anonymous memory pages and the physical storage (or disk-backed
swap space) that actually back these pages. A system's virtual swap space
is equal to the sum of all its physical (disk-backed) swap space plus a portion
of the currently available physical memory.</para><para>Virtual swap space has these advantages:</para><itemizedlist><listitem><para>The need for large amounts of physical swap space is reduced
because virtual swap space does not necessarily correspond to physical (disk)
storage.</para>
</listitem><listitem><para>A pseudo file system called SWAPFS provides addresses for
anonymous memory pages. Because SWAPFS controls the allocation of memory pages,
it has greater flexibility in deciding what happens to a page. For example,
SWAPFS might change the page's requirements for disk-backed swap storage.</para>
</listitem>
</itemizedlist>
</sect2><sect2 id="fsswap-76986"><title>Swap Space and the TMPFS File System</title><para>The TMPFS file system is activated automatically in the Solaris environment
by an entry in the <filename>/etc/vfstab</filename> file. The TMPFS file system
stores files and their associated information in memory (in the <filename>/tmp</filename> directory)
rather than on disk, which speeds access to those files. This feature results
in a major performance enhancement for applications such as compilers and
DBMS products that use <filename>/tmp</filename> heavily.</para><para>The TMPFS file system allocates space in the <filename>/tmp</filename> directory
from the system's swap resources. This feature means that as you use up space
in the <filename>/tmp</filename> directory, you are also using up swap space.
So, if your applications use the <filename>/tmp</filename> directory heavily
and you do not monitor swap space usage, your system could run out of swap
space. </para><para>Do use the following if you want to use TMPFS, but your swap resources
are limited:</para><itemizedlist><listitem><para>Mount the TMPFS file system with the size option (<option>o</option> <replaceable>size</replaceable>) to control how much swap resources TMPFS can use.</para>
</listitem><listitem><para>Use your compiler's <envar>TMPDIR</envar> environment variable
to point to another larger directory.</para><para>Using your compiler's <envar>TMPDIR</envar> variable only controls whether the compiler is using the <filename>/tmp</filename> directory.
This variable has no effect on other programs' use of the <filename>/tmp</filename> directory.</para>
</listitem>
</itemizedlist>
</sect2><sect2 id="fsswap-20"><title>Swap Space as a Dump Device</title><para>A <emphasis>dump device</emphasis> is usually disk space that is reserved
to store system crash dump information. By default, a system's dump device
is configured to be a swap slice. If possible, you should configure an alternate
disk partition as a <emphasis>dedicated dump device</emphasis> instead to
provide increased reliability for crash dumps and faster reboot time after
a system failure. You can configure a dedicated dump device by using the <command>dumpadm</command> command. For more information, see <olink targetdoc="sysadv2" targetptr="tscrashdumps-40145" remap="external">Chapter 17, <citetitle remap="chapter">Managing System Crash Information (Tasks),</citetitle> in <citetitle remap="book">System Administration Guide: Advanced Administration</citetitle></olink>.</para><para>If you are using a volume manager to manage your disks, such as Solaris
Volume Manager, do not configure your dedicated dump device to be under its
control. You can keep your swap areas under Solaris Volume Manager's control,
which is a recommended practice. However, for accessibility and performance
reasons, configure another disk as a dedicated dump device outside of Solaris
Volume Manager's control.</para>
</sect2><sect2 id="fsswap-23"><title>Swap Space and Dynamic Reconfiguration</title><para>A good practice is to allocate enough swap space to support a failing
CPU or system board during dynamic reconfiguration. Otherwise, a CPU or system
board failure might result in your host or domain rebooting with less memory.</para><para>Without having this additional swap space available, one or more of
your applications might fail to start due to insufficient memory. This problem
would require manual intervention either to add additional swap space or to
reconfigure the memory usage of these applications.</para><para>If you have allocated additional swap space to handle a potential loss
of memory on reboot, all of your intensive applications might start as usual.
This means the system will be available to the users, perhaps possibly slower
due to some additional swapping.</para><para>For more information, see your hardware dynamic reconfiguration guide.</para>
</sect2><sect2 id="gfuco"><title>Configuring Swap Space in a SAN Environment</title><para>Review the following points to determine whether you might configure
swap space on a network-connected disk, such as in a SAN environment:</para><itemizedlist><listitem><para>Diagnosing swap space issues on a locally-attached disk is
easier than diagnosing swap space issues on a network-connected disk.</para>
</listitem><listitem><para>The performance of swap space over a SAN should be comparable
to swap space configured on a locally-attached disk.</para>
</listitem><listitem><para>Adding more memory to a system with performance issues, after
analyzing performance data, might resolve a swap over SAN performance problem
better than moving the swap to a locally-attached disk.</para>
</listitem>
</itemizedlist>
</sect2>
</sect1><sect1 id="fsswap-31555"><title>How Do I Know If I Need More Swap Space?</title><para>Use the <command>swap</command> <option>l</option> command to determine
if your system needs more swap space.</para><para>For example, the following <command>swap</command> <option>l</option> output
shows that this system's swap space is almost entirely consumed or at 100%
allocation.</para><screen>% <userinput>swap -l</userinput>
swapfile             dev   swaplo blocks   free
/dev/dsk/c0t0d0s1   136,1      16 1638608    88</screen><para>When a system's swap space is at 100% allocation, an application's memory
pages become temporarily locked. Application errors might not occur, but system
performance will likely suffer. </para><para>For information on adding more swap space to your system, see <olink targetptr="fsswap-37376" remap="internal">How to Create a Swap File and Make It Available</olink>.</para><sect2 id="fsswap-1"><title>Swap-Related Error Messages</title><para>These messages indicate that an application was trying to get more anonymous
memory. However, no swap space was left to back it.</para><screen><replaceable>application</replaceable> is out of memory
 
malloc error O
 
messages.1:Sep 21 20:52:11 mars genunix: [ID 470503 kern.warning] 
WARNING: Sorry, no swap space to grow stack for pid 100295 (myprog)</screen>
</sect2><sect2 id="fsswap-2"><title>TMPFS-Related Error Messages</title><para>The following message is displayed if a page could not be allocated
when a file was being written. This problem can occur when TMPFS tries to
write more than it is allowed or if currently executed programs are using
a lot of memory.</para><screen><replaceable>directory</replaceable>: File system full, swap space limit exceeded</screen><para>The following message means that TMPFS ran out of physical memory while
attempting to create a new file or directory:</para><screen><replaceable>directory</replaceable>: File system full, memory allocation failed</screen><para>For information on recovering from the TMPFS-related error messages,
see <olink targetdoc="refman7" targetptr="tmpfs-7fs" remap="external"><citerefentry><refentrytitle>tmpfs</refentrytitle><manvolnum>7FS</manvolnum></citerefentry></olink>.</para>
</sect2>
</sect1><sect1 id="fsswap-66891"><title>How Swap Space Is Allocated</title><para>Initially, swap space is allocated as part of the Solaris installation
process. If you use the installation program's automatic layout of disk slices
and do not manually change the size of the swap slice, the Solaris installation
program allocates a default swap area of 512 Mbytes. </para><para>Starting in the Solaris 9 release, the installation program allocates
swap space starting at the first available disk cylinder (typically cylinder
0). This placement provides maximum space for the root (<filename>/</filename>)
file system during the default disk layout and enables the growth of the root
(<filename>/</filename>) file system during an upgrade.</para><para>For general guidelines on allocating swap space, see <olink targetptr="fsswap-31050" remap="internal">Planning for Swap Space</olink>.</para><para>You can allocate additional swap space to the system by creating a swap
file. For information about creating a swap file, see <olink targetptr="fsswap-59089" remap="internal">Adding More Swap Space</olink>.</para><sect2 id="fsswap-3"><title>Swap Areas and the <filename>/etc/vfstab</filename> File</title><para>After
the system is installed, swap slices and swap files are listed in the <filename>/etc/vfstab</filename> file. They are activated by the <command>/sbin/swapadd</command> script
when the system is booted.</para><para>An entry for a swap device in the <filename>/etc/vfstab</filename> file
contains the following:</para><itemizedlist><listitem><para>The full path name of the swap slice or swap file</para>
</listitem><listitem><para>File system type of the swap slice or swap file</para>
</listitem>
</itemizedlist><para>The file system that contains a swap file must be mounted before the
swap file is activated. So, in the <filename>/etc/vfstab</filename> file,
ensure that the entry that mounts the file system comes before the entry that
activates the swap file.</para>
</sect2>
</sect1><sect1 id="fsswap-31050"><title>Planning for Swap Space</title><para>The most important factors in determining swap space size are the requirements
of the system's software applications. For example, large applications such
as computer-aided design simulators, database management products, transaction
monitors, and geologic analysis systems can consume as much as 200&ndash;1000
Mbytes of swap space.</para><para>Consult your application vendors for swap space requirements for their
applications.</para><para>If you are unable to determine swap space requirements from your application
vendors, use the following general guidelines based on your system type to
allocate swap space.</para><informaltable frame="topbot"><tgroup cols="3" colsep="0" rowsep="0"><colspec colname="colspec0" colwidth="25*"/><colspec colname="colspec1" colwidth="25*"/><colspec colname="colspec2" colwidth="25*"/><thead><row rowsep="1"><entry><para>System Type</para>
</entry><entry><para>Swap Space Size</para>
</entry><entry><para>Dedicated Dump Device Size</para>
</entry>
</row>
</thead><tbody><row><entry><para>Workstation with about 4 Gbytes of physical memory</para>
</entry><entry><para>1 Gbyte</para>
</entry><entry><para>1 Gbyte</para>
</entry>
</row><row><entry><para>Mid-range server with about 8 Gbytes of physical memory</para>
</entry><entry><para>2 Gbytes</para>
</entry><entry><para>2 Gbytes</para>
</entry>
</row><row><entry><para>High-end server with about 16 to 128 Gbytes of physical memory</para>
</entry><entry><para>4 Gbytes</para>
</entry><entry><para>4 Gbytes</para>
</entry>
</row>
</tbody>
</tgroup>
</informaltable><para>In addition to these general guidelines, consider allocating swap space
or disk space for the following:</para><itemizedlist><listitem><para>A dedicated dump device.</para>
</listitem><listitem><para>Determine whether large applications (such as compilers) will
be using the <filename>/tmp</filename> directory. Then, allocate additional
swap space to be used by TMPFS. For information about TMPFS, see <olink targetptr="fsswap-76986" remap="internal">Swap Space and the TMPFS File System</olink>.</para>
</listitem>
</itemizedlist>
</sect1><sect1 id="fsswap-52195"><title>Monitoring Swap Resources</title><para>The <command>/usr/sbin/swap</command> command is used to manage swap
areas. Two options, <option>l</option> and <option>s</option>, display information
about swap resources.</para><para>Use the <command>swap -l</command> command to identify a system's swap
areas. Activated swap devices or files are listed under the <literal>swapfile</literal> column.</para><screen># <userinput>swap -l</userinput>
swapfile             dev  swaplo blocks   free
/dev/dsk/c0t0d0s1   136,1      16 1638608 1600528</screen><para>Use the <command>swap -s</command> command to monitor swap resources.</para><screen># <userinput>swap -s</userinput>
total: 57416k bytes allocated + 10480k reserved = 67896k used, 
833128k available</screen><para>The <literal>used</literal> value plus the <literal>available</literal> value
equals the total swap space on the system, which includes a portion of physical
memory and swap devices (or files). </para><para>You can use the amount of available and used swap space (in the <command>swap
-s</command> output) as a way to monitor swap space usage over time. If a
system's performance is good, use <command>swap -s</command> to determine
how much swap space is available. When the performance of a system slows down,
check the amount of available swap space to determine if it has decreased.
Then you can identify what changes to the system might have caused swap space
usage to increase. </para><para>When using this command, keep in mind that the amount of physical memory
available for swap usage changes dynamically as the kernel and user processes
lock down and release physical memory. </para><note><para>The <command>swap -l</command> command displays swap space in
512-byte blocks. The <command>swap -s</command> command displays swap space
in 1024-byte blocks. If you add up the blocks from <command>swap -l</command> and
convert them to Kbytes, the result is less than <literal>used</literal> + <literal>available</literal> (in the <command>swap -s</command> output). The reason
is that <command>swap -l</command> does not include physical memory in its
calculation of swap space.</para>
</note><para>The output from the <command>swap -s</command> command is summarized
in the following table.</para><table frame="topbot" id="fsswap-22177"><title>Output of the <command>swap
-s</command> Command</title><tgroup cols="2" colsep="0" rowsep="0"><colspec colnum="1" colname="column1" colwidth="3*"/><colspec colnum="2" colname="column2" colwidth="7*"/><thead><row rowsep="1"><entry><para>Keyword</para>
</entry><entry><para>Description</para>
</entry>
</row>
</thead><tbody><row><entry><para><literal>bytes allocated</literal></para>
</entry><entry><para>The total amount of swap space in 1024-byte blocks that is currently
allocated as backing store (disk-backed swap space).</para>
</entry>
</row><row><entry><para><literal>reserved</literal></para>
</entry><entry><para>The total amount of swap space in 1024-byte blocks that is not currently
allocated, but claimed by memory for possible future use.</para>
</entry>
</row><row><entry><para><literal>used</literal></para>
</entry><entry><para>The total amount of swap space in 1024-byte blocks that is either allocated
or reserved.</para>
</entry>
</row><row><entry><para><literal>available</literal></para>
</entry><entry><para>The total amount of swap space in 1024-byte blocks that is currently
available for future reservation and allocation.</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
</sect1><sect1 id="fsswap-59089"><title>Adding More Swap Space</title><para>As
system configurations change and new software packages are installed, you
might need to add more swap space. The easiest way to add more swap space
is to use the <command>mkfile</command> and <command>swap</command> commands
to designate a part of an existing UFS or NFS file system as a supplementary
swap area. These commands, described in the following sections, enable you
to add more swap space without repartitioning a disk.  </para><para>Alternative ways to add more swap space are to repartition an existing
disk or to add another disk. For information on how to repartition a disk,
see <olink targetptr="disksconcepts-29477" remap="internal">Chapter&nbsp;10, Managing Disks
(Overview)</olink>.</para><sect2 id="fsswap-4"><title>Creating a Swap File</title><para>The following general steps are involved in creating a swap file:</para><itemizedlist><listitem><para>Creating a swap file by using the <command>mkfile</command> command.</para>
</listitem><listitem><para>Activating the swap file by using the <command>swap</command> command.</para>
</listitem><listitem><para>Adding an entry for the swap file in the <filename>/etc/vfstab</filename> file
so that the swap file is activated automatically when the system is booted.</para>
</listitem>
</itemizedlist><sect3 id="fsswap-5"><title><command>mkfile</command> Command</title><para>The <command>mkfile</command> command creates a file that is suitable
for use as either an NFS-mounted swap area or a local swap area. The sticky
bit is set, and the file is filled with zeros. You can specify the size of
the swap file in bytes (the default) or in Kbytes, blocks, or Mbytes by using
the <command>k</command>, <command>b</command>, or <command>m</command> suffixes,
respectively.</para><para>The following table shows the <command>mkfile</command> command options.</para><table frame="topbot" id="fsswap-26020"><title>Options to the <command>mkfile</command> Command</title><tgroup cols="2" colsep="0" rowsep="0"><colspec colnum="1" colname="column1" colwidth="2*"/><colspec colnum="2" colname="column2" colwidth="7*"/><thead><row rowsep="1"><entry><para>Option</para>
</entry><entry><para>Description</para>
</entry>
</row>
</thead><tbody><row><entry><para><option>n</option></para>
</entry><entry><para>Creates an empty file. The size is noted. However, the disk blocks are
not allocated until data is written to them.</para>
</entry>
</row><row><entry><para><option>v</option></para>
</entry><entry><para>Reports the names and sizes of created files.</para>
</entry>
</row>
</tbody>
</tgroup>
</table><note><para>Use the <option>n</option> option only when you create an NFS
swap file.</para>
</note>
</sect3>
</sect2><task id="fsswap-37376"><title>How to Create a Swap File and Make It Available</title><procedure><step id="fsswap-step-7"><para>Become superuser.</para><para>You can create
a swap file without root permissions. However, to avoid accidental overwriting,
root should be the owner of the swap file.</para>
</step><step id="fsswap-step-21"><para>Create a directory for the swap file, if needed.</para>
</step><step id="fsswap-step-8"><para>Create the swap file. </para><screen># <userinput>mkfile</userinput> <replaceable>nnn</replaceable><userinput>[k|b|m]</userinput> <replaceable>filename</replaceable></screen><para>The swap file of the size <emphasis>nnn</emphasis> (in Kbytes, bytes,
or Mbytes) with the <replaceable>filename</replaceable> you specify is created.</para>
</step><step id="fsswap-step-9"><para>Activate the swap file.</para><screen># <userinput>/usr/sbin/swap -a</userinput> <replaceable>/path/filename</replaceable></screen><para>You must use the absolute path name to specify the swap file. The swap
file is added and available until the file system is unmounted, the system
is rebooted, or the swap file is removed. Keep in mind that you cannot unmount
a file system while some process or program is swapping to the swap file.</para>
</step><step id="fsswap-step-10"><para>Add an entry for the swap file to the <filename>/etc/vfstab</filename> file that specifies the full path name of the file, and designates <filename>swap</filename> as the file system type.</para><screen><replaceable>/path/filename</replaceable>   -      -       swap     -     no     -</screen>
</step><step id="fsswap-step-11"><para>Verify that the swap file is added.</para><screen>$ <userinput>/usr/sbin/swap -l</userinput></screen><note><para>If a swap file does not get activated, make sure that the following
service is running:</para><screen># svcs nfs/client
STATE          STIME    FMRI
enabled        14:14:34 svc:/network/nfs/client:default </screen>
</note>
</step>
</procedure><example id="fncrl"><title>Creating a Swap File and Making It Available</title><para>The following examples shows how to create a 100-Mbyte swap file called <filename>/files/swapfile</filename>.</para><screen># <userinput>mkdir /files</userinput>
# <userinput>mkfile 100m /files/swapfile</userinput>
# <userinput>swap -a /files/swapfile</userinput>
# <userinput>vi /etc/vfstab</userinput>
(<emphasis>An entry is added for the swap file</emphasis>):
/files/swapfile   -      -       swap     -     no     -
# <userinput>swap -l</userinput>
swapfile             dev  swaplo blocks   free
/dev/dsk/c0t0d0s1   136,1      16 1638608 1600528
/files/swapfile        -       16 204784  204784</screen>
</example>
</task>
</sect1><sect1 id="fsswap-88340"><title>Removing a Swap File From Use</title><para>If you have unneeded
swap space, you can remove it.</para><task id="fsswap-13"><title>How to Remove Unneeded Swap Space</title><procedure><step id="fsswap-step-15"><para>Become superuser.</para>
</step><step id="fsswap-step-16"><para>Remove the swap space.</para><screen># <userinput>/usr/sbin/swap -d</userinput> <replaceable>/path/filename</replaceable></screen><para>The swap file name is removed so that it is no longer available for
swapping. The file itself is not deleted.</para>
</step><step id="fsswap-step-17"><para>Edit the <filename>/etc/vfstab</filename> file
and delete the entry for the swap file.</para>
</step><step id="fsswap-step-18"><para>Recover the disk space so that you can use
it for something else.</para><screen># <userinput>rm</userinput> <replaceable>/path/filename</replaceable></screen><para>If the swap space is a file, remove it. Or, if the swap space is on
a separate slice and you are sure you will not need it again, make a new file
system and mount the file system.</para><para>For information on mounting
a file system, see <olink targetptr="fsmount-42780" remap="internal">Chapter&nbsp;18, Mounting
and Unmounting File Systems (Tasks)</olink>.</para>
</step><step id="fsswap-step-22"><para>Verify that the swap file is no longer available.</para><screen># <userinput>swap -l</userinput></screen>
</step>
</procedure><example id="fncrm"><title>Removing Unneeded Swap Space</title><para>The following examples shows how to delete the <filename>/files/swapfile</filename> swap
file.</para><screen># <userinput>swap -d /files/swapfile</userinput>
# (<emphasis>Remove the swap entry from the /etc/vfstab file</emphasis>)
# <userinput>rm /files/swapfile</userinput>
# <userinput>swap -l</userinput>
swapfile             dev  swaplo  blocks   free
/dev/dsk/c0t0d0s1   136,1      16 1638608 1600528</screen>
</example>
</task>
</sect1>
</chapter>