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.
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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.