6

On Ubuntu 14.04, the swap file has to be increased as the memory and swap usage are reaching 100% usage.

On a live production server, can the swap be increased with minimal disruption to the service?

Output of free -h:

             total       used       free     shared    buffers     cached
Mem:          3.9G       3.4G       435M        24K       1.2M       7.5M
-/+ buffers/cache:       3.4G       443M
Swap:         8.0G       6.6G       1.4G
Nyxynyx
  • 1,509

3 Answers3

9

I agree with comment about more RAM. Answering your question: you can create either additional swap partition (if you have extra space on a hard drive) or create swap file.

dd if=/dev/zero of=/path/to/swap_file bs=1024 count=${size_of_additional_swap}
mkswap /path/to/swap_file
swapon /path/to/swap_file

The more swap in use the more load on your hard disk and definitely the slower the system.

David Houde
  • 3,240
stimur
  • 894
  • 6
  • 11
1

As Michael Hampton alluded to in his comment, you need more RAM, not swap.

Swap space is generally only used if your applications cannot fit into the available RAM - this is typically a different use pattern than Windows, where the page file is typically used for infrequently-accessed pages.

If your swap space is not residing on flash storage, then it will likely perform a lot worse than actual RAM.

However to answer the question, you cannot live-extend swap. You will need to unmount/swapoff, extend the underlying storage, then remount/swapon.

Craig Watson
  • 9,790
0

Forget about real OS support for dynamical resizing : You are NOT using WINDOWS®! :-) Pushing the Limits of Windows: Virtual Memory
More seriously : you can increase the size of the swap file while using it, but you would need to run mkswap again, which implies unmounting it first.

I would also say using a file instead of a partition typically multiply the access time if you use a fragmented filesystem, making your probably slow system, slower.

Due your used swap size, I would set/proc/sys/vm/swappinessto 100, it may decrease disk the activity at the expanse of an higher swap space usage.
I don't know your ratio of RAM/used swap; but given the used swap size, I'm suspecting it too be high. If this true you should really consider adding some memory modules before you start to get big stall on your server.