Вы находитесь на странице: 1из 10

Swap Space and Virtual Memory http://www.softpanorama.org/Solaris/Processes_and_memory/swap_spa...

May the source be with you, but remember the KISS principle ;-)

(slightly skeptical) Open Source Software Educational


Society

Softpanorama Search

Swap Space and Virtual Memory


Swap Space and Virtual Memory
Swap Space and the TMPFS File System
How Do I Know If I Need More Swap Space?
How Swap Space Is Allocated
Planning for Swap Space
Monitoring Swap Resources
Adding More Swap Space
Removing a Swap File From Use

Summary
A system’s virtual memory is a combination of the available random access memory
(RAM) and disk space. Portions of the virtual memory are reserved as swap space.
Swap space can be defined as a temporary storage location that is used when system’s
memory requirements exceed the size of available RAM. The default page size for
Solaris is 8K. Usual size of Solaris swap partition is the size of RAM.

swap utility usage (-a add, -s


summary, -l list, -d delete):

To view the summary of the


current swap space allocation:\

total: 106256k bytes


allocated + 8512k reserved =
114768k used, 587512k
available

To list details of the system’s


virtual swap space:

swapfile dev swaplo blocks free


/dev/dsk/c0t0d0s1 136,1 16 1206736 1084736
/export/data/swapfile -16 40944 40944

1 of 10 10/1/2010 8:06 AM
Swap Space and Virtual Memory http://www.softpanorama.org/Solaris/Processes_and_memory/swap_spa...

To delete a swap slice from the current swap configuration.

-a To add additional swap area

To add a swap slice Edit the /etc/vfstab file to add information describing the swap slice.

Add the following line to create the swap slice.

Use the swap -a command to add additional swap area.

Note – When the system is subsequently rebooted, the new swap slice /dev /dsk/c1t0d0s3
will be automatically included as part of the swap space as a result of adding the entry to the
/etc/v fstab file.

Adding Swap Files. Swap files can be used when you need to add swap space and do not have a
free partition to use.
To add a swap file, complete the following steps:
1. Create a 1G swap file named swapfile in the partition that have enough free space, for
example directory.

2. Add the swap file to the system’s swap space.

3. List the details of the modified system swap space with

4. List a summary of the modified system swap space with

5. To use a swap file when the system is subsequently rebooted, add an entry for the swap file
in the file.

# vi /etc/vfstab
#device device mount FS fsck mount mount
#to mount to fsck point type pass at boot opt
/export/data/swapfile --swap -no -

Removing Swap Slices

1. Delete a swap slice from the current swap configuration.

2. To prevent the swap slice from being configured as part of the swap configuration during a reboot or
change of run level, edit the /etc/vfstab file, and remove the swap slice entry from the file.

2 of 10 10/1/2010 8:06 AM
Swap Space and Virtual Memory http://www.softpanorama.org/Solaris/Processes_and_memory/swap_spa...

Delete a swap file from the current swap configuration.

Remove the file to free the disk space that it is occupying.

To prevent the swap file from being configured as part of the swap configuration during a reboot or
change of run level, edit the /etc/vfstab file, and remove the swap file entry.

Note – The output of the df -h /export/data/swapfile command shows the space in use until you
remove the swap file.

About Swap Space


It is important for administrators to understand the features of the SunOS swap mechanism in determining:

Swap space requirements


The relationship with the TMPFS file system
Recovery from error messages related to swap space

Swap Space and Virtual Memory


Beginning with the Solaris 9 multiple page sizes can be supported on UltraSPARC processors so administrators
can optimize performance by changing the page size on behalf of an application. Typical performance
measurement tools do not provide sufficient detail for evaluating the impact of page size and do not provide the
needed support to make optimal page size choices.

Swap slices are used as virtual memory storage areas when the system does not have enough physical memory to
handle current processes.

The virtual memory system maps physical copies of files on disk to virtual addresses in memory. Physical
memory pages which 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 anonymous memory because there is no
identity assigned to the disk space backing the memory.

Solaris uses the concept of virtual swap space, 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.

Virtual swap space has these advantages:

The need for large amounts of physical swap space is reduced because virtual swap space does not
necessarily correspond to physical (disk) storage.
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, it might change the page's requirements for disk-backed swap storage.

Swap Space and the TMPFS File System

3 of 10 10/1/2010 8:06 AM
Swap Space and Virtual Memory http://www.softpanorama.org/Solaris/Processes_and_memory/swap_spa...

The TMPFS file system is activated automatically in the Solaris environment by an entry in the /etc/vfstab
file. The TMPFS file system stores files and their associated information in memory (in the /tmp directory)
rather than on disk, which speeds access to those files. This results in a major performance enhancement for
applications such as compilers and DBMS products that use /tmp heavily.

The TMPFS file system allocates space in the /tmp directory from the system's swap resources. This means that
as you use up space in /tmp, you are also using up swap space. So if your applications use /tmp heavily and you
do not monitor swap space usage, your system could run out of swap space.

Use the following if you want to use TMPFS but your swap resources are limited:

Mount the TMPFS file system with the size option (-o size) to control how much of the swap resources
TMPFS can use.
If you are close to running out of swap space, you can use your compiler's environment variable
to point to a larger, real directory.

Using your compiler's variable only controls whether the compiler is using /tmp or not. It has no
effect on other programs' use of /tmp.

How Do I Know If I Need More Swap Space?


This section lists several possible error messages displayed when you run out of swap space.

Swap-Related Error Messages

These messages indicate that an application was trying to get more anonymous memory and there was no swap
space left to back it.

application 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)

TMPFS-Related Error Messages

directory: File system full, swap space limit exceeded

This message is displayed if a page could not be allocated when writing a file. This can occur when TMPFS tries
to write more than it is allowed or if currently executed programs are using a lot of memory.

directory: File system full, memory allocation failed

This message means TMPFS ran out of physical memory while attempting to create a new file or directory.

See TMPFS(7FS) for information on recovering from the TMPFS-related error messages.

How Swap Space Is Allocated

4 of 10 10/1/2010 8:06 AM
Swap Space and Virtual Memory http://www.softpanorama.org/Solaris/Processes_and_memory/swap_spa...

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 default swap slices as shown in the table below.

If Your System Has n Mbytes of Physical Memory ... Then the Default Swap Space Allocated Is ...

16-63 32 Mbytes

64-127 64 Mbytes

128-511 128 Mbytes

greater than 512 256 Mbytes

Additional swap space can also be added to the system by creating a swap file. See "Adding More Swap Space"
for information about creating a swap file.

The /etc/vfstab File


After the system is installed, swap slices and files are listed in the /etc/vfstab file and are activated by the
/sbin/swapadd script when the system is booted.

An entry for a swap device in the /etc/vfstab file contains:

The full path name of the swap slice or file


File system type of swap

Because the file system containing a swap file must be mounted before the swap file is activated, make sure that
the entry that mounts the file system comes before the entry that activates the swap file in the /etc/vfstab file.

Planning for Swap Space


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-1000 Mbytes of
swap space.

Consult your application vendor for swap space requirements for any application whose data files typically
exceed 10-20 Mbytes in size.

If you are unable to determine swap space requirements from the application vendor, use the following
guidelines to allocate swap space:

If you are unsure of system or application requirements 100% of the system's physical memory. You need
more that that if you plan to run a lot of application. To support all your applications, you need to allocate
allocate:
1 Mbyte per trivial application such as xterm.
2-3 Mbytes per lightweight application such as a calendar or mail application.
20-50 Mbytes for large applications such as desktop publishing software.
To save crash dumps, allocate 100% of physical memory to save a worst-case crash dump.

5 of 10 10/1/2010 8:06 AM
Swap Space and Virtual Memory http://www.softpanorama.org/Solaris/Processes_and_memory/swap_spa...

Determine whether large applications (like compilers) will be using the /tmp directory.

Monitoring Swap Resources


The /usr/sbin/swap command is used to manage swap areas. Two options, -l and -s, are used to display
information about swap resources.

Use the swap -l command to identify a system's swap areas. Activated swap devices or files are listed under the
column.

swap -l

Use the swap -s command to monitor swap resources.

swap -s

The plus figures equals total swap space on the system, which includes a portion of physical
memory and swap devices (or files).

You can use the amount of swap space available and used (in the swap -s output) as a way to monitor swap
space usage over time. If a system's performance is good, use swap -s to see how much swap space is available.
When the performance of a system slows down, check the amount of swap space available to see if it has
decreased. Then you can identify what changes to the system might have caused swap space usage to increase.

Keep in mind when using this command that the amount of physical memory available for swap usage changes
dynamically as the kernel and user processes lock down and release physical memory.

Note - The swap -l command displays swap space in 512-byte blocks and the swap -s command displays swap
space in 1024-byte blocks. If you add up the blocks from swap -l and convert them to Kbytes, it will be less
than + (in the swap -s output) because swap -l does not include physical memory in its
calculation of swap space.

The output from the swap -s command is summarized in the table below.

Keyword Description

The total amount of swap space in 1024-byte blocks that is currently allocated as backing
store (disk-backed swap space).

The total amount of swap space in 1024-byte blocks not currently allocated, but claimed
by memory for possible future use.

The total amount of swap space in 1024-byte blocks that is either allocated or reserved.

6 of 10 10/1/2010 8:06 AM
Swap Space and Virtual Memory http://www.softpanorama.org/Solaris/Processes_and_memory/swap_spa...

Keyword Description

The total amount of swap space in 1024-byte blocks that is currently available for future
reservation and allocation.

Adding More Swap Space


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 mkfile and swap commands to designate a part of
an existing UFS or NFS file system as a supplementary swap area. These commands, described below, enable
you to add more swap space without repartitioning a disk.

Alternative ways to add more swap space are to repartition an existing disk or add another disk. See Chapter 28,
Disk Management (Overview) for information on how to repartition a disk.

Creating a Swap File

The following general steps are involved in creating a swap file:

Creating a swap file using the mkfile command.


Activating the swap file with the swap command.
Adding an entry for the swap file in the /etc/vfstab file so that it's activated automatically when the
system is booted.

The mkfile Command

The mkfile command creates a file that is suitable for use either as an NFS-mounted or 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 kilobytes, blocks, or megabytes using the k, b, or m suffixes, respectively.

The table below shows the options to the mkfile command.

Option Description

-n Creates an empty file. The size is noted, but the disk blocks are not allocated until data is written
to them.

-v Verbose. Reports the names and sizes of created files.

Use the -n option only when creating an NFS swap file.

How to Create a Swap File and Make It Available

1. Become superuser.

You can create a swap file without root permissions, but it is a good idea for root to be the owner of the
swap file to avoid accidental overwriting.

2. Create the swap file.

7 of 10 10/1/2010 8:06 AM
Swap Space and Virtual Memory http://www.softpanorama.org/Solaris/Processes_and_memory/swap_spa...

# mkfile nnn[k|b|m] filename

The swap file of the size nnn (in Kbytes, bytes, or Mbytes) and name you specify is created.

3. Activate the swap file.

# /usr/sbin/swap -a /path/filename

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
can't unmount a file system while some process or program is swapping to the swap file.

4. Add an entry for the swap file to the /etc/vfstab file that specifies the full path name of the file, and
designates swap as the file system type, like this:
/path/filename - - swap - no -
5. Verify that the swap file is added.

$ /usr/sbin/swap -l

Example--Creating a Swap File and Making It Available

The following examples shows how to create a 24 Mbyte swap file called /files/swapfiles.

# mkdir /files
# mkfile 24m /files/swapfile
# swap -a /files/swapfile
# vi /etc/vfstab
(An entry is added for the swap file):
/files/swapfile - - swap - no -
# swap -l
swapfile dev swaplo blocks free
/dev/dsk/c0t2d0s1 32,17 8 205624 192704
/files/swapfile - 8 40952 40952

Removing a Swap File From Use


If the user no longer needs the extra swap space, you can remove it.

1. Become superuser.
2. Use the swap -d command to remove swap space.
# /usr/sbin/swap -d /path/filename

The swap file name is removed from the list so that it is no longer available for swapping. The file itself is
not deleted.

3. Edit the /etc/vfstab file and delete the entry for the swap file.
4. Recover the disk space so that you can use it for something else.

8 of 10 10/1/2010 8:06 AM
Swap Space and Virtual Memory http://www.softpanorama.org/Solaris/Processes_and_memory/swap_spa...

# rm swap-filename

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.

See Chapter 36, Mounting and Unmounting File Systems (Tasks) for information on mounting a file
system.

Example--Removing Extra Swap Space

The following examples shows how to delete the /files/swapfile swap file.

swap -d /files/swapfile

rm /files/swapfile
swap -l

Recommended Links

In case of broken links please try to use Google search. If you find the page please notify us about new location

Solaris Internals

Solaris 8 Memory Architecture

Memory and swapping

Solaris processes

Supporting Multiple Page Sizes in the Solaris Operating System

Beginning with the Solaris 9 OS, multiple page sizes can be supported on UltraSPARC processors so
administrators can optimize performance by changing the page size on behalf of an application. Typical
performance measurement tools do not provide sufficient detail for evaluating the impact of page size and do
not provide the needed support to make optimal page size choices.

This article explains how to use new tools to determine the potential performance gain. In addition, it explains
how to configure larger page sizes using the multiple page size support (MPSS) feature of the Solaris 9 OS.
The article addresses the following topics:

"Understanding Why Virtual-to-Physical Address Translation Affects Performance"


"Working With Multiple Page Sizes in the Solaris OS"
"Configuring for Multiple Page Sizes"

9 of 10 10/1/2010 8:06 AM
Swap Space and Virtual Memory http://www.softpanorama.org/Solaris/Processes_and_memory/swap_spa...

Solaris Tunable Parameters Reference Manual

Getting to know the Solaris filesystem, Part 3 - SunWorld - July 1999

Getting the Best AIPS Performance from Solaris

Copyright © 1996-2009 by Dr. Nikolai Bezroukov. www.softpanorama.org was created as a service to the UN Sustainable Development
Networking Programme (SDNP) in the author free time. Submit comments This document is an industrial compilation designed and created
exclusively for educational use and is placed under the copyright of the Open Content License(OPL). Site uses AdSense so you need to be
aware of Google privacy policy. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in
compliance with the fair use doctrine.

Disclaimer:

The statements, views and opinions presented on this web page are those of the author and are not endorsed by, nor do they necessarily
reflect, the opinions of the author present and former employers, SDNP or any other organization the author may be associated with.
We do not warrant the correctness of the information provided or its fitness for any purpose
In no way this site is associated with or endorse cybersquatters using the term "softpanorama" with other main or country domains with
bad faith intent to profit from the goodwill belonging to someone else.

Last modified: August 12, 2009

10 of 10 10/1/2010 8:06 AM

Вам также может понравиться