How to increase swap space on a live server [duplicate]

Solution 1:

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.

Solution 2:

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.