4

I'm running a webserver and database server on the same AWS EC2 instance. I know it's a bad idea to have swap for web server, so should I just turn it off? Will it affect the database service (I guess not but I'm not sure on this). If yes, how do I turn it off?

I'm running Amazon Linux AMI.

Thanks ;-).

  • 1
    Can you share where you read that /swap is not required? I know that some AMIs have /swap disabled. E.g. the alestic ones used to come with swap disabled. I never understood the reason. – Till Oct 31 '10 at 19:34
2

No. No. No. No. No.

Also, this is wrong information that you have:

I know it's a bad idea to have swap for web server

  • 3
    +1 (I wish i could upvote this more). Never turn off swap, It's there for a reason, and the OS is better at managing it than you are. – Tom O'Connor Oct 25 '10 at 16:30
  • I remember reading this thing about swap somewhere, couldn't find it. Here's something similar: modperlbook.org/html/5-11-2-Swapping-Prevention.html – Jason Dinh Oct 25 '10 at 17:01
  • 1
    Did you read the actual link? It says to minimize swapping (which is great advice). If your system needed to swap, and you had turned it off, you've got a mess on your hands. It's like realizing "You shouldn't drive off the road" and then removing the guardrails. – mfinni Oct 25 '10 at 17:35
  • 2
    Rather than berating the questioner I suggest giving him an explanation so he understands what is happening. – Mark Wagner Oct 25 '10 at 19:01
  • Absent a cogent argument or supporting information, this is simply argument by authority. A good answer would describe the tradeoffs and what the poster could do to determine whether this is appropriate. – Chris Adams Dec 18 '14 at 20:32
2

In general, no, you should not disable swap even if you have plenty of RAM. Having swap can improve system performance because the contents of little-used memory can be copied to swap and then the memory can be reallocated to do something useful.

However, sometimes there are odd circumstances. Where did you get the information that it is bad idea to have swap for web server?

0

Amazon suggests you fit the server to the workload:

"Using swap space for memory paging is not as fast or efficient as using RAM. If your workload is regularly paging memory into swap space, you should consider migrating to a larger instance type with more RAM."

Amazon will add a swap partition for c1.medium and m1.small inrtances. Other instances do not have one by default.

So, if we are to listen to the advice of people saying to trust your OS, your OS is telling you that you should NOT have swap.

0

It's not a good idea to turn off swap for the server. If you think you have enough memory available for the system, you can set vm.swappiness = 10 (or any small value). So the system will not swap unless memory is not available (90% used).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.