I have a VPS with 512MB RAM with 1GB Burst from TelVPS. There is no swap space for the VPS.

I had a discussion regarding this with my service provider but they said that they dont provide swap space for VPS, Can I add SWAP space of my own?

I have the following setup:

  • Apache2/Passenger
  • Ruby on Rails 2,3
  • MySQL
  • Sendmail.

I have 3 rails application running, but they are test apps with low to no traffic.

top and the VPS control panel shows my system is using around 880MB of RAM. But the process list result of top does not show any process eating memory. I have read http://www.linuxatemyram.com/. But following is the output of free -m

root@serveme:/var/www# free -m
             total       used       free     shared    buffers     cached
Mem:          1024        819        204          0          0          0
-/+ buffers/cache:        819        204
Swap:            0          0          0

I have two questions about this situation:

1). How to resolve memory eating issue? (Please let me know if more information is needed)
2). Can I add SWAP space? If yes, how? Is that safe to add swap space after setting up the system?


1). Memory: I ran ps -axu --sort -rss | head -n 10 as suggested by Fox(in comments) and I found that my sunspot (a rails gem for fulltext search based on solr) was eating memory. There are options to limit memory usage for sunspot.

2). Swap space

Followed the steps by Tom in accepted answer.

  • 1
    Hello! It seems you have an interesting situation. However, There appears to be multiple questions or no single direct question. Do you want to know if you can add your own swap space and how? Do you want to know if your current RAM usage is normal? Both? Something else? – Wesley Dec 17 '11 at 7:02
  • Actually looking for both.. – Pravin Dec 17 '11 at 7:20
  • I'd suggest making two questions. One on the more foundational topic of "Is something wrong with my memory" and another on the topic of "can I make my own swap space." But that's just my thoughts. – Wesley Dec 17 '11 at 7:31
  • I have updated the question with what I'm looking for – Pravin Dec 17 '11 at 7:34
  • 1
    just to make sure ... can you please show us output of ps -axu --sort -rss | head -n 10? (edit: doing pretty much the same thing B14D3 is suggesting) – Fox Dec 17 '11 at 9:37

There's probably sod all you can do directly about the memory usage. Ruby on Rails is massively memory hungry, especially when it's ORM builds out recursive ActiveRecords of deep objects. Apache's not particularly lightweight either.

You might wanna grab MySQL Tuner and see how much RAM the database has stolen at peak usage (table cache, query cache, connection pools).

Adding swap after the fact is easy, but can be massively slow. Especially as most VPSes are on overcommitted, underpowered IO backends.

Let's make a 512MB Swapfile

  1. dd if=/dev/zero of=/swapfile1 bs=1024 count=524288 This creates a 512MB sparse file in /swapfile
  2. mkswap /swapfile1 This formats it for Swap usage
  3. swapon /swapfile1 This tells the kernel to use it for swap
  4. vim /etc/fstab Edit Fstab, and then
  5. /swapfile1 swap swap defaults 0 0 Append this line to the bottom of the file so when you reboot, you get the same swap partition mounted again.
  • Thanks for the steps to create swap.. I found the memory issue.. updating in question above .. :) – Pravin Dec 17 '11 at 12:55

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.