Solaris FAQ: Myths and facts about Solaris swap space

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 SunOS 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."

  • zone.max-locked-memory
  • zone.max-msg-ids
  • zone.max-sem-ids
  • zone.max-shm-ids
  • zone.max-shm-memory
  • 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.

Comments:

Thanks for the useful article - would it be at all possible to get the hyperlinks working?

Posted by Colin Hill on January 06, 2012 at 02:31 AM EST #

Thanks for the useful article - would it be at all possible to get the hyperlinks working?

Posted by Colin Hill on January 06, 2012 at 02:32 AM EST #

I have a problem with virtual memory usage on my 2 node RAC based on Solaris 10. Can ou please see following thread and answer if possible.

https://forums.oracle.com/forums/thread.jspa?messageID=10134349#10134349

Thanks.

Posted by Salman on February 08, 2012 at 10:10 PM EST #

I have a problem with virtual memory usage on my 2 node RAC based on Solaris 10. Can ou please see following thread and answer if possible.

https://forums.oracle.com/forums/thread.jspa?messageID=10134349#10134349

Thanks.

Posted by Salman on February 08, 2012 at 10:10 PM EST #

On Solaris 10 is the output from swap -l accurate? It doesn't seem to jive with the output from vmstat.

Posted by guest on February 23, 2012 at 11:38 AM EST #

See the discussion on the usage of the swap -l and swap -s commands at:
http://docs.oracle.com/cd/E23823_01/html/817-5093/fsswap-52195.html#scrolltoc

Also, keep in mind that vmstat and swap command are simply snapshots of data that is changing all the time.

Posted by Jim Laurent on February 23, 2012 at 11:53 AM EST #

There are two definitions of swap:

1) Virtual memory. As in memory that is virtualized, referring to memory accessed via an MMU. This could be disk and/or RAM.

2) Disk space set aside to be used as memory. This is a subset of #1.

Vmstat's swap column is referring to the amount of unreserved #1.

The command "swap -l" is referring to allocated and used #2.

Also keep in mind that reserved is not the same as allocated. A program can reserve memory but if it doesn't actually access those pages the kernel will never allocate them memory. That is, vmstat's swap column will go down but neither vmstat's free column will reduce nor will swap -l show consumed disk blocks.

Posted by guest on February 27, 2012 at 08:07 PM EST #

This appears to be an updated URL for the documentation:
http://docs.oracle.com/cd/E19253-01/817-5093/fsswap-14677/index.html

Posted by guest on May 24, 2012 at 12:26 PM EDT #

It is not possible to swap from a file that is on a ZFS file system! In this day and age, most people are using nothing but ZFS, so in the end, a new disk/slice is required, and that's just plain silly. The kernel should be able to mark the swapfile as used, continues blocks on the disk that are no longer available to the file system, and reroute all I/O around ZFS so that it "just works".

Posted by guest on June 20, 2012 at 01:07 PM EDT #

Myth: You can't add more swap if you use ZFS.

You can't use a file for swap space, but you *can* use a ZFS volume:
zfs create -V 2G rpool/swap2
swap -a /dev/zvol/dsk/rpool/swap2

Posted by guest on September 18, 2012 at 01:12 PM EDT #

I think it's amazing how there are so many references to "read the documentation" by the author here.

I've searched through about 80 documents so far and not found any references to the above material. I have done explicit searches for the word "swap" and only found hits in the NIS+, DNS, and zone admin guides.

It would be far more helpful if your links pointed to the actual relevant documents instead of a homepage with hundreds of links and sub-links.

PT

Posted by guest on October 23, 2012 at 03:14 PM EDT #

PT,

Thanks for your comments. As you can see, this document was written in 2007 while we were still Sun Microsystems. Unfortunately, during the transition to Oracle (after about 1 year) the docs.sun.com links were all migrated to oracle.com so the links in the blog entry are no good anymore.

If you google "solaris 10 documentation" you will find the current docs.

Posted by Jim Laurent on October 23, 2012 at 03:21 PM EDT #

Thanks for sharing .
Here is some useful documents about solaris swap.
Adding ZFS swap on fly
http://www.unixarena.com/2012/07/procedure-to-add-new-swap-in-solaris-10.html
Calculating free swap & memory
http://www.unixarena.com/2013/03/how-to-calculate-sar-and-vmstat-memory.html

Posted by Lingeswaran on May 03, 2013 at 10:55 AM EDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Jim Laurent is an Oracle Sales consultant based in Reston, Virginia. He supports US DoD customers as part of the North American Public Sector hardware organization. With over 17 years experience at Sun and Oracle, he specializes in Solaris and server technologies. Prior to Oracle, Jim worked 11 years for Gould Computer Systems (later known as Encore).

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today