|Contents||Bulletin||Scripting in shell and Perl||Network troubleshooting||History||Humor|
|News||Recommended Links||Solaris Volume Manager (SVM)||Solaris TMPFS||UFS filesystem||Ext2/Ext3|
|ZFS||NFS||Floppy FAT filesystem||CdRom||Flashdrives||Solaris snapshots|
On modern hardware with 32GB memory or more swap space is rarely used for its primary purpose. Bu Solaris has a very elegant idea of linking swap space and /tmp. In other words /tmp in Solaris is memory based filesystem and files in it disappear on reboot. That means that it is important for Solaris administrators to understand the features of the Solaris swap. There are three major area of interest here:
Solaris 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. In can be less but some application, such as Oracle requires the size swap to be equal to the size of RAM .
But if RAM is bigger then 2GB usually it sufficient to allocate about 25-30% of physical RAM.
Operations with swap are performed using swap utility. It has several options (-a add, -s summary, -l list, -d delete):
# swap -s total: 106256k bytes allocated + 8512k reserved = 114768k used, 587512k available
-dTo delete a swap slice or swap slice from the current swap configuration.
# swap -d /dev/dsk/c1t0d0s3To 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.
Operations on swap file are similar to operation on swap slice:
- Delete a swap file from the current swap configuration.
# swap -d /export/data/swapfile
- Remove the file to free the disk space that it is occupying.# rm /export/data/swapfile
- 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.
# vi /etc/vfstab #device device mount FS fsck mount mount #to mount to fsck point type pass at boot opt
Add the following line to create the swap slice./dev/dsk/c1t0d0s3 --swap -no -
Use the swap -a command to add additional swap area.# swap -a /dev/dsk/c1t0d0s3
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/vfstab file.
To add a swap file, complete the following steps:
# mkfile 1000m /export/data/swapfile
# swap -a /export/data/swapfile
# 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 -
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 spaces plus a portion of the currently available physical memory.
Virtual swap space has these advantages:
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 rather than on disk, which speeds access to those files (in other words the /tmp directory is mapped to virtual memory, not a disk) . This results in a major performance enhancement for applications such as compilers and DBMS products that use /tmp heavily.
At the same time it makes some common practices like writing log files in /tmp less desirable as they can affect the performance of the system. It is better to use home directory or /var for this purpose in Solaris.
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:
TMPDIRenvironment variable to point to a larger, real directory.
Using your compiler's
TMPDIR variable only controls whether the compiler is using
/tmp or not. It has no effect on other programs' use of /tmp.
This section lists several possible error messages displayed when you run out of swap space.
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)
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.
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 ...|
|greater than 512Mb||256 Mb|
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.
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:
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.
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 swap space equal to the size of RAM or even bigger. At the same time most "regular" application do not need much swap space and the system with such application rarely uses more then 1-2 GB of swap space and for then 4-8 GB swap for their needs is usually enough. Virtual disk for /tmp requirements are extra.
Please note that many systems with large RAM can work perfectly well without swap at all. As strange as it sounds for modern sizes of hard drives, when 600 GB drives are common, but large and unused swap is essentially wasted disk space. This leads us to desirability of using Windows-style swap file in such cases and advantages of "split swap" -- combination of small partition and a swap file. This is especially important for installation of Oracle which generally over specifies the required size of swap. In case of this combination swap can be reduced after then installation.
Consult your application vendor for swap space requirements for any application which hange large data files.
If you are unable to determine swap space requirements from the application vendor, use the following guidelines to allocate swap space:
Never allocate swap with size less then 30% of RAM.
Determine whether large applications (such as compilers and databases) will be using the /tmp directory. If one or several of your application have a huge demand for swap space, use the swap -s command to monitor swap resources on a similar existing system tro get estimate of the actual requirements. Then double and round to the nearest gigabyte. For example:
# swap -s
total: 10492k bytes allocated + 7840k reserved = 18332k used, 21568k available
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 (which display space in 512 blocks) to identify a system's swap areas. Activated swap devices or files are listed under the swapfile column.
# swap -l swapfile dev swaplo blocks free /dev/dsk/c0t2d0s1 32,17 8 205624 192704
Use the swap -s command to monitor swap resources.
# swap -s
total: 10492k bytes allocated + 7840k reserved = 18332k used, 21568k available
The used plus available 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 used + available (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.
|bytes allocated||The total amount of swap space in 1024-byte blocks that is currently allocated as backing store (disk-backed swap space).|
|reserved||The total amount of swap space in 1024-byte blocks not currently allocated, but claimed by memory for possible future use.|
|used||The total amount of swap space in 1024-byte blocks that is either allocated or reserved.|
|available||The total amount of swap space in 1024-byte blocks that is currently available for future reservation and allocation.|
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.
The following general steps are involved in creating a swap file:
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.
|-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.
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.
The swap file of the size nnn (in Kbytes, bytes, or Mbytes) and name you specify is created.
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.
/path/filename - - swap - no -
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
If the user no longer needs the extra swap space, you can remove it.
The swap file name is removed from the list so that it is no longer available for swapping. The file itself is not deleted.
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.
The following examples shows how to delete the /files/swapfile swap file.
# swap -d /files/swapfile # (Remove the deleted swap entry from the /etc/vfstab file) # rm /files/swapfile# swap -l
swapfile dev swaplo blocks free /dev/dsk/c0t2d0s1 32,17 8 205624 192720
Swap space in the Solaris 10 OS is misunderstood or poorly understood by most SA's, myself included. Here is my shot at explaining what I think it means from a Systems standpoint (as opposed to a programming or design standpoint).
Q: When I run 'swap -s', what does the output mean?
# swap -s
total: 61541352k bytes allocated + 10156312k reserved = 71697664k used, 5965344k available
'allocated' is the sum total of all the user process address spaces (including shared memory), plus all the data in /tmp.
'reserved' is memory which has been allocated but which is not in use. Solaris attempts to put these pages onto the swap device so as to not occupy physical memory with unused pages.
'used' + 'available' should equal all of the RAM on the host, minus anything used by the kernel.
Q: Why does 'used' + 'available' not add up to the RAM on my server?
A: kernel memory pages are not counted in the output of the swap command because they are not directly accessible by processes.
Q: How can I see how much memory the kernel is occupying?
A: Here is one way:
# echo "::memstat" | mdb -k
Page Summary Pages MB %Tot
------------ ---------------- ---------------- ----
Kernel 1483266 11588 9%
ZFS File Data 4445637 34731 27%
Anon 7034973 54960 43%
Exec and libs 249329 1947 2%
Page cache 787194 6149 5%
Free (cachelist) 2036135 15907 12%
Free (freelist) 416189 3251 3%
Total 16452723 128536
Physical 16430557 128363
Q: OK, I see that the kernel is occupying 11Gb of memory. So why does the total of used + available only equal about 77Gb on a 128Gb host? Shouldn't it equal 115Gb or 117Gb?
A: ZFS has played a sneaky trick on you by using kernel pages for its adaptive read cache (ARC). On this system, the ARC has grown large and is occupying 34Gb of space. 'swap -s' does not display kernel memory and therefore your total available memory will shrick as the ARC grows. But the pages in the ARC are readily freed and should not have a great impact on user-level memory allocation unless memory becomes fragmented and user processes are requesting large memory pages.
Q: What if I am running Solaris Containers?
A: The swap usage of containers can be limited by defining the zone.max-swap resource control (rctl). In a container which has a zone.max-swap rctl defined, 'swap -s' used+available should add up to the value of the rctl. For example, in a container with
zone.max-swap = 4Gb:
zone# swap -s
total: 3624128k bytes allocated + 0k reserved = 3624128k used, 570176k available
Note that the zone.max-swap rctl also limits the amount of /tmp space which a container can use.
As one of the 60 or so OS Ambassadors in Sun world wide, I frequently see the question asked about how to configure Solaris swap. Apparently, there is quite a bit of mystery about swap space even though it is clearly documented in the Solaris administrator collection. I decided to publish a collection of my favorite myths and facts about Solaris swap space. Note that certain applications (such as Oracle) that use "Intimate Shared Memory" will require more swap than most applications. Please refer to the application docs for swap size recommendations.
Myth: Always set Solaris swap to 2 x RAM size
This myth is clearly a case of users who have been around since the Solaris 4.x days. Virtual memory today consists of the sum total of physical RAM and swap space on disk.
Solaris DOES NOT require any swap space to be configured at all. If you choose this option, once RAM is full, you will not be able to start new processes. There are recommendations for swap space size in the Solaris documentation but the rule of thumb in general is that swap should be configured about 30% of physical RAM.
Myth: Solaris swap requires raw partitions to be available
Swap can easily be added using standard UFS files in addition to raw disk slice, online without a reboot. The added swap space takes effect immediately. The instructions are documented but because I'm a nice guy (and it is so easy) I'll put an example here.
- mkfile 500m /swapfile
- swap -a /swapfile
- Make this added swap area persistent across reboots by adding a new entry in /etc/vfstab
There now, that didn't hurt a bit did it? The file can be any size you choose and any location in a UFS file system. You can add as many swap files as you like. ZFS is not currently supported for swap files. You can use the vmstat or swap commands to show the changes. Swap space is used in a round robin rotation.
Myth: Swap partitions are also dump partitions
It was back in the Solaris 8 timeframe (late 1999) that the dumpadm command was added to Solaris. To quote the S8 documentation (because I'm lazy):
The new dumpadm command, which allows system administrators to configure crash dumps of the operating system. The dumpadm configuration parameters include the dump content, dump device, and the directory in which crash dump files are saved. See the Solaris 10 dumpadm documentation for more information.
Myth: You can't control swap space for Solaris 10 containers
With the latest update of Solaris 10 08/07, we added new resource controls for swap space and containers. These provide significantly better control and help eliminate denial of service attacks caused by memory leaks and "malloc bombs."
- project.max-locked-memory - Replaces project.max-device-locked-memory
- zone.max-swap - Provides swap capping for zones through the capped-memory resource
Fact: Swap and tmpfs are the same
This is true. This design has a number of benefits but we also offer a number of options for controlling tmpfs usage. I'll refer you directly to the documentation again.
Fact: Using swap is bad for performance
Think of swap space as an overflow area for RAM. It's OK if non-active processes are using swap space, however, if actively used processes are constantly having their pages moved back and forth from RAM to disk based swap areas, performance will suffer. You can monitor this using the vmstat FREE column. In Solaris 7 and earlier this number wass relatively meaningless. Since Solaris 8, however, the FREE column provides an accurate indicator of your free memory. If the number is too low, page scanning begins (as indicated by the 'sr' column in vmstat). Any non-zero number in the 'sr' column for an extended period of time is an indicator that it's time to buy more RAM.
Jim Maura and Rich McDougall have written excellent books about Solaris Internals which described memory utilization in excruciating details. See their Solaris Internals wiki for more FAQ and to purchase the books.
Why should you care?
Solaris continues to be updated and improved with every update based upon feedback from our customers. If you are not staying up with the latest technology, you're still "living in the 90s" and not getting the most from your compute resource. We work hard to provide you the facilities in Solaris to increase your availability and utilization of you compute farms.
Explain virtual memory concepts and, given a scenario, configure and manage swap space.
Physical memory is the random-access memory (RAM) installed in a computer. To view the amount of physical memory installed in your computer, type the following:prtconf| grep "Memory size"
The system displays a message similar to the following:Memory size: 384 Megabytes
Not all physical memory is available for Solaris processes. Some memory is reserved for kernel code and data structures. The remaining memory is referred to as available memory. Processes and applications on a system can use available memory.
Physical memory is supplemented by specially configured space on the physical disk that is known as swap space; together they are referred to as virtual memory. Swap space is configured either on a special disk partition known as a swap partition or on a swap file system (swapfs). In addition to swap partitions, special files called swap files can also be configured in existing Unix file systems (UFS) to provide additional swap space when needed.
Every process running on a Solaris system requires space in memory. Space is allocated to processes in units known as pages. Some of a process's pages are used to store the process executable, andand other pages are used to store the process's data.
Physical memory is a finite resource on any computer, and sometimes there are not enough pages in physical memory for all of a system's processes. When a physical memory shortfall is encountered, the virtual memory system begins moving data from physical memory out to the system's configured swap areas. When a process requests data that has been sent to a swap area, the virtual memory system brings that data back into physical memory. This process is known as paging.
The Solaris virtual memory system maps the files on disk to virtual addresses in memorythis is referred to as virtual swap space. As data in those files is needed, the virtual memory system maps the virtual addresses in memory to real physical addresses in memory. This mapping process greatly reduces the need for large amounts of physical swap space on systems with large amounts of available memory.
The virtual swap space provided by swapfs reduces the need for configuring large amounts of disk-based swap space on systems with large amounts of physical memory. This is because swapfs provides virtual swap space addresses rather than real physical swap space addresses in response to the requests to reserve swap space.
With the virtual swap space provided by swapfs, real disk-based swap space is required only with the onset of paging, because when paging occurs, processes are contending for memory. In this situation, swapfs must convert the virtual swap space addresses to physical swap space addresses in order for paging to actual disk-based swap space to occur.
Swap Space and TMPFS
The temporary file system (TMPFS) makes use of virtual memory for its storagethis can be either physical RAM or swap space; it is transparent to the user. /tmp is a good example of a TMPFS file system where temporary files and their associated information are stored in memory (in the /tmp directory) rather than on disk. This speeds up access to those files and results in a major performance enhancement for applications such as compilers and database management system (DBMS) products that use /tmp heavily.
TMPFS allocates space in the /tmp directory from the system's virtual memory resources. This means that as you use up space in /tmp, you are also using up virtual memory space. So if your applications use /tmp heavily and you do not monitor virtual memory usage, your system could run out of this resource.
Sizing Swap Space
The amount of swap space required on a system is based on the following criteria:
- Application programs need a minimum amount of swap space to operate properly. This information is usually contained in the documentation that comes with the application. You should follow the manufacturer's recommendation for swap space requirements.
- You need to determine whether large applications (such as compilers) will be using the /tmp directory. Then you need to allocate additional swap space to be used by TMPFS.
- To prevent any possible panic dumps resulting from fatal system failures, there must be sufficient swap space to hold the necessary kernel memory pages in RAM at the time of a failure. Kernel memory accounts for around 20% of total memory, so if you have 1GB of physical memory, you will need about 256MB of disk-based space for a worst-case crash dump.
Movement of Swap Starting with the release of Solaris 9, the installation program allocates swap at the first available cylinder on the disk (this is normally cylinder 0). This practice allows the root file system the maximum space on the disk and allows for expansion of the file system during an upgrade.
The amount of disk-based swap space on a system must be large enough to be able to accommodate a kernel memory dump, plus the requirements of any concurrently running processes, including third-party applications and compilers. Many other factors also contribute to the amount of swap space you need to configure, such as the number of concurrent users and the naming service, Network Information System Plus (NIS+). It is quite rare nowadays to need more swap space than RAM, which used to be a recommendation with older versions of Solaris; in fact the opposite is often trueyou now often need less swap space than physical RAM.
If you are prepared to keep track of your swap space and administer it regularly, you can run with much less swap space than in older versions of Solaris. (How to monitor swap space and how to add additional space to a running system are discussed in the next few sections.)
Reducing Swap Space Problems If the amount of swap space is equal to the amount of physical RAM, you should generally experience no swap space problems, although the type of application being used on the system will be a major factor.
Monitoring Swap Resources
If you run into a swap shortfall due to heavy demand on memory, you get error messages on your system's console. The error might look something like this:<application> is out of memory malloc error O messages.1:SJul 18 15:12:47 ultra genunix: [ID 470503 kern.warning] WARNING: Sorry, no swap space to grow stack for pid 100295 (myprog)
This error means that an application is trying to get more memory and there is no swap space available to back it.
You could fill up a TMPFS due to the lack of available swap and get the following error message:<directory>: File system full, swap space limit exceeded
or this one:<directory>: File system full, memory allocation failed
This type of message is displayed if a page cannot be allocated when a file is being written. This can occur, for example, when TMPFS tries to write more than it is allowed or when TMPFS runs out of physical memory while attempting to create a new file or directory.
You need to regularly monitor your swap space. This helps you determine whether you are running on the edge and need to increase the resource or maybe you have too much swap space allocated and are wasting disk space. Most commercial performance monitoring tools keep track of swap space or can be configured to generate warnings when it gets low. Besides these commercial tools, you can use the helpful tools that Solaris provides (see Table 9.1). System performance monitoring is not covered on the administrator certification exams, so this chapter describes only the /usr/sbin/swap command.
Table 9.1. Swap Monitoring Tools
Command Description /usr/sbin/swap The /usr/sbin/swap utility provides a method for adding, deleting, and monitoring the system swap areas used by the memory manager. /usr/bin/ps You can use the -al options with the /usr/bin/ps command to report the total size of a process that is currently in virtual memory. The value includes all mapped files and devices, and it is reported in pages. These device mappings do not use swap space. /usr/ucb/ps You can use this Berkley version of the ps command with the -alx options to report the total size of a process that is currently in virtual memory. The value includes all mapped files and devices, and it is reported in kilobytes rather than pages. /usr/bin/vmstat This tool reports virtual memory statistics. /usr/bin/sar This is a system activity reporter.
You can use two options with the /usr/sbin/swap command to monitor swap space. You can use the -l option to list swap space and to determine the location of a system's swap areas:swap -l
The system displays details of the system's physical swap space. This system has a 512MB swap slice allocated, as shown below:swapfile dev swaplo blocks free /dev/dsk/c0t0d0s1 136,9 16 1049312 1049312
This output is described in Table 9.2.
Table 9.2. Output from the swap -l Command[*]
Keyword Description path The pathname for the swap area (for example, /dev/dsk/c0t0d0s1). dev The major/minor device number for a block special device; this value is zeros otherwise. swaplo The swaplo value for the area, in 512-byte blocks. swaplo is a kernel parameter that you can modify, and it represents the offset, in 512-byte blocks, where usable swap space begins. blocks The swaplen value for the area, in 512-byte blocks. swaplen is a kernel parameter that you can modify, and it defines the size of the swap area, in 512-byte blocks. free The number of 512-byte blocks in this area that are not currently allocated.
[*] This table does not include swap space in the form of physical memory because that space is not associated with a particular swap area.
You use the -s option to list a summary of the system's virtual swap space:swap -s
The system displays the following information, which shows the details of the system's physical swap space and includes physical memory too. This system has 384MB of physical memory and a 512MB swap slice:total: 67648k bytes allocated + 19032k reserved = 86680k used, 724512k \ available
This output is described in Table 9.3
Table 9.3. Output from the swap -s Command
Keyword Description bytes allocated The total amount of swap space, in 1,024-byte blocks, that is currently allocated as backing store (that is, disk-backed swap space). reserved The total amount of swap space, in 1,024-byte blocks, that is not currently allocated but is claimed by memory for possible future use. used The total amount of swap space, in 1,024-byte blocks, that is either allocated or reserved. available The total amount of swap space, in 1,024-byte blocks, that is currently available for future reservation and allocation.
You can use the amounts 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, you can use swap -s to see how much swap space is available. When the performance of a system slows down, you can 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 the swap command that the amount of physical memory available for swap usage changes dynamically as the kernel and user processes reserve and release physical memory.
Swap Space Calculations The swap -l command displays swap space in 512-byte blocks, and the swap -s command displays swap space in 1,024-byte blocks. If you add up the blocks from swap -l and convert them to kilobytes, you'll see that it is less than the swap space used plus available (as shown in the swap -s output) because swap -l does not include physical memory in its calculation of swap space.
Setting Up Swap Space
Swap space is initially configured during software installation through the installation program. 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 slice of 512MB.
Crash Dumps As described later in this chapter, a crash dump is a disk copy of the kernel memory of the computer at the time of a fatal system error. When a fatal operating system error occurs, a message describing the error is printed to the console. The operating system then generates a crash dump by writing the contents of kernel memory to a predetermined dump device, which is typically a local disk partition. You can then analyze this crash dump to determine the cause of the system error. By default, the dump device is configured to be an appropriate swap partition. Therefore, it's necessary to make sure that your swap area is at least as large as about 25% of your physical RAM; otherwise, the system may not have enough room to store the crash dump. Crash dumps and core files are discussed later in this chapter, in the sections "Core File Configuration" and "Crash Dump Configuration."
The software installation program adds entries for swap slices and files in the /etc/vfstab file. These swap areas are activated each time the system is booted by /sbin/swapadd.
As system configurations change, more users are added, and new software packages are installed, you might need to add more swap space. There are two methods for adding more swap to a system:
- Create a secondary swap partition.
- Create a swap file in an existing UFS.
Creating a secondary swap partition requires additional, unused disk space. You use the format command as described in Chapter 1, "Managing File Systems," to create a new partition and file system on a disk. After you create the swap partition, you make an entry in the /etc/vfstab file so that the swap space is activated at bootup. The process is described in Step by Step 9.1.Step By Step 9.1: Creating a Secondary Swap File
1. Add an additional 512MB of swap space to your system. You don't have any more room on the disk for more swap space, but the /data directory (currently mounted on slice 4 of disk c0t1d0) is 512MB in size. Move all the data in /data to another server to free up the partition so that you can use it as a swap partition. You can use any one of the methods described in Chapter 7, "Performing System Backups and Restorations," to do this.
2. After freeing up the /data directory and unmounting /dev/dsk/c0t1d0s4, use the format utility to set the tag name to swap and the permission flag to wu (writable and unmountable), as follows:
[View full width] partition> 4 Part Tag Flag Cylinders Size Block 4 unassigned wm 3400 - 4480 512.37MB (1041/0/0) 1049328 Enter partition id tag[unassigned]: swap Enter partition permission flags[wm]: wu Enter new starting cyl: <return> Enter partition size[1049328b, 1041c, 1040e, 512.37mb, 0.50gb]: <return>
The bold text here identifies the keystrokes entered by the user during execution of the command.
Label the disk, as follows:Partition> la Ready to label disk? Y3. Make an entry to the /etc/vfstab file, where the fields are as follows:
Device to mount: <name of swap block device or swap file>
Device to fsck: --
Mount point: --
fsck pass: --
Mount at boot: no
Mount options: --
Here's an example of an entry for the swap partition just added:/dev/dsk/c0t1d0s4 - - swap - no -4. Run the swapadd script to add the swap to your system:/sbin/swapadd5. Verify that the swap has been added:swap -l
The system responds with this:swapfile dev swaplo blocks free /dev/dsk/c0t0d0s1 136,9 16 1049312 1049312 /dev/dsk/c0t1d0s4 136,3 16 1052624 1052624
/dev/dsk/c0t1d0s4 has been added to the list of available swap areas.
/etc/vfstab syntax You should be familiar with the entry for swap files in /etc/vfstab. The syntax can be tricky, especially because of the hyphens.
The following are additional notes that explain how to add swap partitions:
- On systems running the 32-bit version of Solaris, swap areas must not exceed 2GB. If you wanted to add a 9GB disk to a swap area, you should slice it up into 2GB chunks. Then, you need to put a separate entry in /etc/vfstab for each slice. On systems running the 64-bit version of Solaris 10, you can use a block device larger than 2GB.
- You get a large performance benefit from having swap partitions spread across separate disks. Swap space is allocated in a round-robin fashion from swap partition to swap partition, and it is not possible to prioritize usage of the various swap areas. Swap space is allocated 1MB at a time from each swap partition in turn, unless one is full.
- It is not worth making a striped metadevice to swap on; that would just add overhead and slow down paging.
The easiest way to add more swap space is to use the mkfile and swap commands to designate a part of an existing UFS as a supplementary swap area. You can do this as a temporary or semi-temporary solution for a swap shortage. Although you can do this for longer durations as well, it has a few disadvantages:
- A swap file is considered a file within a file system; therefore, when you back up a file system, a rather large swap file (empty file) is also backed up if you don't specifically exclude it.
- Because a swap file is simply a file in some file system, you are not able to unmount that file system while the swap file is in use.
- This method of creating a swap file has a negative effect on system performance because the swap file is slower than a dedicated swap slice.
Step by Step 9.2 explains how to add more swap space without repartitioning a disk.Step By Step 9.2: Adding Swap Space Without Repartitioning a Disk 1. As root, use the df -h command to locate a file system that has enough room to support a swap file that's the size that you want to add:
# df -h Filesystem size used avail capacity Mounted on /dev/dsk/c0t0d0s0 4.9G 3.7G 1.2G 77% / /devices 0K 0K 0K 0% /devices ctfs 0K 0K 0K 0% /system/contract proc 0K 0K 0K 0% /proc mnttab 0K 0K 0K 0% /etc/mnttab swap 1.2G 1.0M 1.2G 1% /etc/svc/volatile objfs 0K 0K 0K 0% /system/object fd 0K 0K 0K 0% /dev/fd /dev/dsk/c0t0d0s7 4.0G 1.5G 2.4G 40% /var swap 1.2G 304K 1.2G 1% /tmp swap 1.2G 48K 1.2G 1% /var/run /dev/dsk/c0t1d0s0 3.9G 1.7G 2.2G 44% /data1 /dev/dsk/c0t1d0s7 5.2G 7.1M 5.1G 1% /data2
Swap Permissions 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 prevent someone from accidentally overwriting it.2. Use the mkfile command to add a 512MB swap file named swapfile in the /data2 partition:
mkfile 512m /data2/swapfile
Use the ls -l /data2 command to verify that the file has been created:
ls -l /data2/swapfile -rw------T 1 root root 536870912 Aug 19 23:31 /data2/swapfile
The system shows the file named swapfile along with the file size. Notice that the sticky bit (which is described in Chapter 4, "User and Security Administration") has automatically been set.
3. Activate the swap area by using the swap command:
/usr/sbin/swap -a /data2/swapfile
You must use the absolute pathname 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 the swap file is still being used or a process is swapping to the swap file.
4. Verify that the new swap area was added:
The system should respond with a message such as the following that shows the swap file:
swapfile dev swaplo blocks free /dev/dsk/c0t0d0s1 136,9 16 1049312 1049312 /data2/swapfile - 16 1048560 1048560
5. If this will be a permanent swap area, add to the /etc/vfstab file an entry for the swap file that specifies the full pathname of the swap file and designate swap as the file system type:/data2/swapfile - - swap - no -
There is some disagreement as to which type of swap area provides the best performance: a swap partition or a swap file. There are factors in favor of both scenarios; however, these are two of the best reasons in favor of swap partitions:
- A partition provides contiguous space and can be positioned between the specific cylinders that will provide the best performance.
- A swap file has to work through the file system when updates are made, whereas a swap partition has data written to it at a lower level, bypassing the interaction with the file system; this makes a swap partition slightly faster than a swap file.
Sun's official statement, and the general consensus in the user community, is that there will be a performance impact if you go the swap file route rather than the partition route. Sun recommends that you use swap files only as a temporary solution, until you can add a swap partition.
Swap Files on NFS In an emergency, when no other local space is available, it's possible to add a swap file to a networked file system by using NFS; this is described later in this chapter. Using NFS to access swap space on another host is not recommended, however, because it puts an increased load on your network and makes performance unacceptable. If you do need to use NFS for additional swap files, try using the -n option when you run mkfile, as this will only allocate disk blocks as they are written.
Swap files can be deleted as well as added. For example, you might determine that you have allocated too much swap space and that you need that disk space for other uses. Alternatively the additional swap space might have been temporarily added to accommodate a one-off large job. The steps involved in removing a swap file are outlined in Step by Step 9.3.
Step By Step 9.3: Removing a Swap File1. As root, use the swap -d command to remove the swap area:swap -d /dev/dsk/c0t0d0s4 for a swap partition or, swap -d /data2/swapfile for a swap file.2. Issue the swap -l command to ensure that the swap area is gone:swap -l swapfile dev swaplo blocks free /dev/dsk/c0t0d0s1 136,9 16 1049312 1049312
The swap file filename is removed from the list, so you know it is no longer available for swapping. The file itself is not deleted.
3. In the /etc/vfstab file, delete the entry for the swap file.4. Remove the swap file to recover the disk space:
If the swap area was in a partition, you can now allocate this disk space as you would a normal file system.
Softpanorama hot topic of the month
Solaris 8 Memory Architecture
Memory and swapping
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"
Solaris Tunable Parameters Reference Manual
Getting to know the Solaris filesystem, Part 3 - SunWorld - July 1999
Getting the Best AIPS Performance from Solaris
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available in our efforts to advance understanding of environmental, political, human rights, economic, democracy, scientific, and social justice issues, etc. We believe this constitutes a 'fair use' of any such copyrighted material as provided for in section 107 of the US Copyright Law. In accordance with Title 17 U.S.C. Section 107, the material on this site is distributed without profit exclusivly for research and educational purposes. If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner.
ABUSE: IPs or network segments from which we detect a stream of probes might be blocked for no less then 90 days. Multiple types of probes increase this period.
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Haterís Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least
Copyright © 1996-2015 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. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License.
Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|You can use PayPal to make a contribution, supporting development of this site and speed up access. In case softpanorama.org is down currently there are two functional mirrors: softpanorama.info (the fastest) and softpanorama.net.|
The statements, views and opinions presented on this web page are those of the author (or referenced source) 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.
Last modified: February 23, 2015