Very often I am out of memory. I noticed that I don't have a swapfile. What size should I choose? I have 4GB RAM.

Programs I use are: Firefox, Thunderbird, Grive, Android Studio, that's it, still my laptop freezes pretty often.

  • @karel, thank you. I will probably make 8GB, what do you think? – Kirill Zhukov Aug 28 '14 at 4:21
  • 1
    Standard advice: If you use hibernation: swap > RAM. Else make as much swap as you like (none also works). – muru Aug 28 '14 at 4:22
  • From the Ubuntu Swap FAQ: As a base minimum, it's highly recommended that the swap space should be equal to the amount of RAM. Also, it's recommended that the swap space is twice the amount of RAM, especially if you use hibernation. – karel Aug 28 '14 at 5:00
  • @karel, thank you. What if I will make too big size? – Kirill Zhukov Aug 28 '14 at 7:20
  • From the Ubuntu Swap FAQ: In reality, if you use hibernation you need what was outlined in the relevant paragraph above [my previous comment], otherwise you need as much swap space as your system will use - which actually may be very little in a modern hardware setup. The only downside to having more swap space than you will actually use is the disk space you will be reserving for it. Example: My swap partition is the same size as the amount of RAM (it was the default in my Ubuntu installer) and I hardly ever use any of it. – karel Aug 28 '14 at 7:23

Swap of 500 MB to 1 GB should be fine. I made swap of 500 MB at the time of installation and have not faced any problem so far. I have 2 GB RAM.

| improve this answer | |

Here's a fairly sensible guide from The Linux Questions Wiki

Almost every Linux system will need swap space. The classic piece of advice is "swap should be double the amount of RAM you have", though this is not a rigid guideline. Another guideline is to have at least 1x your RAM size, but this also isn't a fixed, absolute requirement (this used to be necessary for linux, but not anymore for recent versions). It depends mainly on what applications you want to run. Applications like video/movie editing, 3d rendering, large image editing, database servers and web application servers can use a lot of memory and if you don't have that as RAM, it will need a large swap space.

A good way to decide the size, is to just try and see. Pick a size (it is usually easier to reduce the swap size after-wards, so aim high) and run your 'normal' workload for a while and see how much swap is used (See Memory diagnostic tools). You can then adjust/resize the partitions or re-partition completely.

To optimize for speed, it is advisable to put the swap partition on a different hard disk (if you have one) instead of on the main hard disk with the OS on it. It is also possible to spread the swap space over multiple hard disks, this can also increase the speed. Linux can handle multiple swap spaces, and each swap space can have a priority (pri=somenumber in fstab, also see swapon command).

I'm building a file server with 4G of RAM at the moment, and have started off with 8G swap space as I'm going to use a fair bit of RAM by using a union mount. It can always be adjusted later.

| improve this answer | |

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