IT management/strategy

Unix: Adding swap space on the fly

June 24, 2009, 08:02 PM — 

All Unix systems support virtual memory, sometimes referred to simply as "VM". With VM in service, active applications and processes on your system can reside in physical memory or space on your hard disks that serves as an extension to physical memory. The amount of swap space (the portion of virtual memory that resides on disk) that you need on any particular server depends both on how much physical memory the system has and on how you use it. A server endowed with a copious amount of physical memory may rarely make use of any significant amount of swap. A server with only one or two gigabytes of memory may rely on swap to perform adequately.

The primary advantage of swap is that it allows physical memory to be used more efficiently. Running processes and the data they use can be offloaded from physical memory and stored in swap until it is needed again. As a result, more applications that could effectively share physical memory can be handled as if run simultaneously. The larger addressable memory space can streamline development while providing good performance.

In general, the rule of thumb is to configure enough swap space to allow your system to perform well, while not so much that you short yourself on available disk space. You might try to allocate as much swap as you have physical memory or you might aim at a figure that brings your virtual memory to something between 4 and 8 GB on a development system or busy server.

An inadequate amount of memory can result in an inability to run as many applications or processes as you want to support. You might see errors such as "WARNING /tmp: File system full, swap space limit exceeded" or applications refusing to load. You might even see segmentation faults or core dumps.

Fortunately, adding memory on the fly is generally easy. On Solaris systems, you can add an unused partition to your swap space just by issuing the "swap -a partition" command (e.g., swap -a /dev/dsk/c1t0d0s4). Use the "swap -l" command to get a listing of your swap space.

If you don't have an unused partition, you can create a file using the mkfile command and swap on it. Here are some sample mkfile commands:

# mkfile 1024m /var/swapfile
# mkfile 2g /spare/bigswap

To add the new swap space to active swap, use "swap -a":

# swap -a /var/swapfile
# swap -a /spare/bigswap

Your new swap space should be available immediately.

To make the swap space addition permanent, you have to add it to /etc/vfstab.

/dev/dsk/c1t0d0s4 - - swap - no -

In spite of the "no" listed in the "mount at boot" column, swap space set up this way will be set up for use when the system reboots.

If you later feel that you've allocated too much disk space for your swapfile, you can remove it with a "swap -d" command and allocate a smaller amount.

Linux systems use a very similar set of commands for creating swap partitions. You can use the "mkswap" command as shown here and the "swapon" command to put the swap space into use:

# mkswap /dev/hda2
Setting up swapspace version 1, size = 2056314 kB
# swapon /dev/hda2

For swapfiles on Linux, a mkfile command (like that on Solaris) is generally available and "swap -a" or "swapon" can be used to make the swap space available for use.

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Comments

Raw versus Cooked Swap Space

Adding swap space is one of those things I do infrequently enough to never remember exactly how to do it. I always have to look up the format of the commands.

What is your opinion about the performance issues of using raw disk versus pre-formatted, file system disk? Is there any difference?

Cheers!
Monsoon
| reply
peer-to-peer

Esther Schindler
If the comments are ugly, the code is ugly

claird
SVG a graphics format for 21st century

pasmith
Take Chrome OS for a test spin

Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?

sjvn
64-bits of protection?

jfruh
Android fragments vs. the iPhone monolith

mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive

 

Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace