2

I recently added 1 GB of swap to my Ubuntu virtual private server to prevent MySQL crashes on RAM overloading. I followed this tutorial.

I use htop to monitor resources. When I use loadimpact to test my server it crashes when no more RAM is available, but not a single byte of swap is used...

I got the current setting now:

# swapon -s

Filename Type Size Used Priority
/var/swap.img file 1023996 0 100


# free
total used free shared buffers cached
[...]
Swap: 999 0 999

/etc/fstab contains:

LABEL=DOROOT / ext4 errors=remount-ro 0 1
/var/swap.img none swap defaults,pri=100 0 0

Last note: when I used the tutorial I got the following error message executing swapon -p 100 /var/swap.img

swapon: /var/swap.img: swapon failed: Device or resource busy

Could you help me with any advices to activate swap?

  • swapon: /var/swap.img: swapon failed: Device or resource busy. This means that your swap is already on. – Danila Ladner Jan 24 '14 at 15:01
  • could you please write about what do you have in the logs, when your server crashes? Is it only MySQL crashing, or the whole server? Also, have you checked vm.swapinnes as mentioned in the guide? – Andrey Sapegin Jan 24 '14 at 16:40
  • In mysql log there is only a query mentioned, that failed. The problem is when the system is run out of memory. The system kills processes to free memory, and mySQL get killed first. Yes I also set wm-swapiness (but 20, not 30). – Patartics Milán Jan 24 '14 at 16:53

1 Answers1

3

This looks like behavior of OpenVZ VPS, where swap cannot be controlled (added/enabled/disabled) from within the VPS itself. Only from the Host machine, or via configuration controls exposed to VPS users from the host, ie from control panel.

If you're using OpenVZ - speak with your hosting provider to increase your limits or add swap, or upgrade to a beefier plan.

Alec Istomin
  • 312
  • 1
  • 8