Unix: Adding swap space on the fly

By Sandra Henry-Stocker  1 comment

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.

1 comment

    Anonymous 2 years ago
    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

      Add a comment

      Post a comment using one of these accounts
      Or join now
      At least 6 characters

      Note: Comment will appear soon after you have activated your account.
      Obscene/spam comments will be removed and accounts suspended.
      The information you submit is subject to our Privacy Policy and Terms of Service.

      ITworld LIVE

      IT Management/StrategyWhite Papers & Webcasts

      White Paper

      Evaluator Group: Storage Federation - IT Without Limits (Analysis of HP Peer Motion with Storage Federation)

      As the role of IT increases within organizations, the need to move data when and where it is needed is critical to support emerging business requirements. This has become increasingly difficult due to the huge growth of data volumes. This white paper sponsored by HP + Intel evaluates a solution that aims to enable the movement of data without physical limitations. Read now and see how this could enable agility and efficiency.

      White Paper

      ESG Lab Validation Report: HP Data Protector & Deduplication Solutions

      Many organizations have deployed disk-to-disk backup technologies to improve the speed and reliability of their backup and disaster recovery operations. A growing number of these now look to data deduplication to enhance retention periods and reduce costs. This ESG Lab Validation Report sponsored by HP + Intel examines a number of backup and recovery solutions and evaluates their ease of implementation as well as their ability to improve reliability and reduce costs.

      White Paper

      Business Value of Blade

      The nature of the blade platform makes system management, monitoring and provisioning easy and efficient. Access this resource to learn how blade migration will save your data center time and money while increasing performance.

      White Paper

      Accelerate time to application value

      For your IT organization to keep pace with the business, you need a new, faster approach to infrastructure deployment-an approach that increases agility and accelerates time to application value. That's HP Converged Systems. Built on Converged Infrastructure, these systems deliver the industry's first portfolio of pre-integrated, tested, and optimized infrastructure solutions for applications running in virtual, cloud, dedicated, or hybrid environments.

      White Paper

      Converged Infrastructure for Dummies

      As you know, everything is mobile, connected, interactive, and immediate. This is exactly why organizations need a highly agile IT infrastructure in order to keep pace with extreme fluctuations in business demand. This book will help you understand why infrastructure convergence has been widely accepted as the optimal approach for simplifying and accelerating your IT to deliver services at the speed of business while also shifting significantly more IT resources from operations to innovation.

      See more White Papers | Webcasts

      Ask a question

      Ask a Question