5

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 ;-).

Jason Dinh
  • 151
  • 1
  • 3
  • 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

4 Answers4

3

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?

Mark Wagner
  • 17,764
  • 2
  • 30
  • 47
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

mfinni
  • 35,711
  • 3
  • 50
  • 86
  • 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: http://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
  • This site is all about argument from authority. – mfinni Dec 18 '14 at 20:53
  • @mfinni I'm sorry you think so but given the number of responses which include links to authoritative documentation, source code and actual technical commentary your opinion is clearly not widely shared – Chris Adams Jan 09 '15 at 17:27
  • I was making a joke. – mfinni Jan 09 '15 at 17:36
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.

Rich Remer
  • 125
  • 6
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).

Anto
  • 139
  • 6