Jump to content
Nytro

How to Increase the Swap File in UNIX(-like) Operating Systems

Recommended Posts

Posted

How to Increase the Swap File in UNIX(-like) Operating Systems

First of all, I’m not saying on which operating system because this applies to numerous UNIX, UNIX derivates and UNIX-like operating systems. For example, the process of increasing the swap file is the same on all Linux, AIX, HP-UX, FreeBSD, NetBSD, OpenBSD, IRIX, Tru64 and possibly more. So, assuming that we have approximately 2GB of swap…

1root:~# free

2 total used free shared buffers cached

3Mem: 1026140 690164 335976 0 226408 246340

4-/+ buffers/cache: 217416 808724

5Swap: 2064376 0 2064376

6root:~#

We first create an empty file with the size of additional swap we need. For example if we need 512MB of additional swap we’ll create a file like this:

1root:~# dd if=/dev/zero of=/example_swap bs=1024 count=500000

2500000+0 records in

3500000+0 records out

4512000000 bytes (512 MB) copied, 7.03446 seconds, 72.8 MB/s

5root:~#

Which will obviously create file with size of 512MB filled with zeros…

1root:~# ls -l /example_swap

2-rw-r--r-- 1 root root 512000000 May 24 11:49 /example_swap

3root:~#

Next, we are making this a swap area using the provided utility.

1root:~# mkswap /example_swap

2Setting up swapspace version 1, size = 511995 kB

3root:~#

And we attach this to the system’s swap file as shown below…

1root:~# swapon /example_swap

2root:~# free

3 total used free shared buffers cached

4Mem: 1026140 1005904 20236 0 197632 579308

5-/+ buffers/cache: 228964 797176

6Swap: 2564368 0 2564368

As you can see the space was increased. It would be wise to also update /etc/fstab to map this area at boot time or when using swapon -a command.

In order to stop using this area, simply remove it with the appropriate system call’s wrapper utility.

1root:~# swapoff /example_swap

2root:~# free

3 total used free shared buffers cached

4Mem: 1026140 1005780 20360 0 197648 579316

5-/+ buffers/cache: 228816 797324

6Swap: 2064376 0 2064376

7root:~#

Sursa: How to Increase the Swap File in UNIX(-like) Operating Systems « xorl %eax, %eax

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...