How to add additional swap area in SuSe/openSUSE

swap space is a dedicated device or a file in one of the mounted file systems to which the system swaps pages of information from the physical memory onto these areas to allow more current application use the physical memory when the physical memory is running out of space.


Let us see here how we can add a file within the File System as a swap area either temporarily to troubleshoot a performance issue or permanently (atleast until you add additional physical memory) to your system in SuSE and openSUSE.

First to start with, lets see how much of total memory we have on the system. This is the sum of Physical memory and any swap space already added to the system using the “free” command:

OPENSUSE11:~ # FREE -TOM
TOTAL       USED       FREE     SHARED    BUFFERS     CACHED
MEM:           998        973         24          0         20        795
SWAP:          739          0        739
TOTAL:        1738        973        764

Here we have 739MB of swap and none of which is used at the moment. To see the swap device or file which provides this 739MB

OPENSUSE11:~ # SWAPON -S
FILENAME                                TYPE            SIZE    USED    PRIORITY
/DEV/MAPPER/SYSTEM-SWAP                 PARTITION       757752  0       -1
/SWAP_1                                 FILE            999992  0       -2

Now, lets say the system is really stressed and is running out of memory (ofcourse not the case here on my system) and we decide to quickly add a big 1Gigabyte file as a temporary swap area. We need to first create thios big monstreous 1Gigabyte file.

OPENSUSE11:~# DD IF=/DEV/ZERO OF=/SWAP_1 BS=1024 COUNT=1000000
1000000+0 RECORDS IN
1000000+0 RECORDS OUT
1024000000 BYTES (1.0 GB) COPIED, 28.7256 S, 35.6 MB/S

We use the DD command to create the 1G file basically writing “0” into the file swap_1 in the “/” file system.

Now, the file is ready and we shall make it a swap area.

OPENSUSE11:~ # MKSWAP /SWAP_1
SETTING UP SWAPSPACE VERSION 1, SIZE = 999996 KIB
NO LABEL, UUID=4AADA58E-D6F7-4053-ADF1-8D4C79122D36

That sets up the file as a swap area.

Now, we’ll simply enable the swapfile so that the system can start paging physical memory pages onto it.

OPENSUSE11:~ # SWAPON /SWAP_1

Thats it. The system should now have an additional 1Gigabyte of swap area. Let’s see if it is true.

OPENSUSE11:~ # FREE -TOM
TOTAL       USED       FREE     SHARED    BUFFERS     CACHED
MEM:           998        973         24          0         20        795
SWAP:         1716          0       1716
TOTAL:        2714        973       1741

It is…We now have 1.7Gigabytes of swap area as against to 739MB we originally had.

To confirm the swap areas we have

OPENSUSE11:~ # SWAPON -S
FILENAME                                TYPE            SIZE    USED    PRIORITY
/DEV/MAPPER/SYSTEM-SWAP                 PARTITION       757752  0       -1
/SWAP_1                                 FILE            999992  0       -2

While this provides the swap space required for the system almost instantly, if you happen to reboot your SuSE server or your openSUSE system then this swap space won’t be available for the system. To make it permanent, we need to add an entry to the /etc/fstab file as follows:

/SWAP_1     SWAP                 SWAP       DEFAULTS              0 0

Where /swap_1 is our new swap file and it instructs the system to mount it at system startup as a swap area.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.