Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
we don't. used to be relevant when you could swap RAM for a kidney in a dark alley way, nowadays really not relevant. having said that with the size of hard disks, it's still often done as 1 or 2gb of 320gb is nothing.
It can slow down your computer considerably. I have laptop with 1.25 GB RAM and swap space about 1.5 GB and I never needed to turn it on.
That's an inappropriate generalisation. If you said
"my machine never uses swap" that's fine, but to say
there's no need is not only wrong it's dangerous.
And as for the slowing down: I'd rather have my machine
slow down than randomly shoot a process to be able to
meet another ones needs.
And welcome to LQ, btw :}
And as for the old rule that the original poster was
referring true: it was definitely true in the days
when machines with 64MB were top-notch. Today it all
depends on the machines memory usage patterns (thus
in case of workstation on the users behaviour).
If all your processes will run in the amount of memory in your machine then you don't NEED swap. To Be Honest, the fact that you're asking the question implies that you're a long way away from needing to consider the swap question. It's true that if you don't have any swap, then the system will start shooting processes when it runs out of memory. It's also true that the system will start shooting processes when it runs out of swap. So, in the end, there are two things to consider.
1. Total process space needed - If 1GB will do it, then it doesn't matter whether it's 256MB RAM and 756 MB swap, or 1GB of ram.
2. However, you are unlikely to enjoy using a system that is using swap heavily as much as you will a system that doesn't swap at all. Swap can be considered as very slow speed RAM. If you have to run a process that uses an enormous memory footprint, but you don't care how long it takes, then use a lot of swap. If it's important to you how long it takes for that process to run, then you'd probably want to be sure you have enough RAM to run it.
To reinforce what I said above, most people who ask this question do not need to be concerned about it, unless they're running an old decrepit system and have no money, but do have spare disk space. The rest of us run faster machines with lots of RAM, and if the machine slows down due to swappage, we order some more RAM.
When you provide swap-space (and "2x RAM" seems to be a good amount, based on many years of practical experience), you leave your operating-system with plenty of options. It can choose what to keep in RAM, and what to move out to disk, because there's always a place for it to go. Furthermore, since the space available greatly-exceeds the amount of RAM, "running out" of swap space isn't a reasonable possibility.
If your computer finds no reason to swap, of course it never will. It won't slow your system down in any way, one way or the other.
At the prompt, issue
you will see how much RAM you are using right now, and how much swap too. Based on this, you can chose to disable swap completely or increase your swap space or do nothing. Very likely, if you add RAM, you will need less swap. If you suspend to ram, you need a swap space, which is at least half your RAM.
You can tune your usage of swap/ram in /proc/sys/vm/swappiness, depending on what you are doing with your computer.
Distribution: Ubuntu, Debian, Various using VMWare
One useful thing about swap space - if you suspend to disk, the image is normally written to your swap partititon. Therefore, if you intend to suspend to disk, then make sure you have sufficient swap space.
I generally give about 1.5x RAM to swap. One of my machines has 500Gb, the other has 1Tb. Therefore the space taken is not significant in the scheme of things. Having said that, I have 2Gb RAM in one of my boxes, and it never uses Swap. The other one has 1Gb RAM, and only uses swap when re-encoding MythTV recordings.
RAM is used because it's faster than storing stuff on disk. If you run out of RAM, your machine may start feeling ill unless it can store the stuff somewhere, when RAM is full. This is one place where SWAP comes into the picture.
In the past people had something like 12MB of RAM, and that was a lot. Nowadays a lot of people have 1...2GB. It might not be filled entirely, and as long as it is not, you don't need SWAP. I personally have 1GB SWAP space, but 95% of the time it's not used at all. Why do I need it then? Because I do heavy work at times, process huge image or video files and so on, and when I do, sometimes RAM just isn't enough. It doesn't mean it's 100% filled all the time and makes my life hell, but there are short times when it gets close or up to 100% full, and then it's just convenient to have SWAP. You could of course use a SWAP file too, instead of a partition, but for me it's just less hazzle to have a partition instead of a file.
1 or 2GB out of 250..500GB is like a drop in the ocean. If you start having so little free space that 1GB is "too much consumed for SWAP", you better buy a bigger harddisk - they're not that expensive nowadays. If your SWAP usage is 0%, you can be happy. And when you do one day run into trouble when your memory fills up for some odd reason, you're just thankful if you had that 512MB or 1GB of SWAP - it saves your day and your machine from freezing to death.
SWAP = 2 x RAM is just a thumb rule, like said. In the past, like I said, people had less RAM, so memory-consuming tasks did need more SWAP at times than there was RAM available. It takes time to explain this all for a complete newbie, and that newbie might not want to hear it at all, or might not remember anything about the long explanation. It's just easier done if somebody says "you need twice as much space for SWAP than you have RAM". 256MB was a good size for a SWAP partition when you had 128MB RAM and a disk of few gigabytes or less. If you nowadays have 8GB of RAM, I don't think it's wise to reserve 16GB for SWAP..well, unless you're working with a spacecraft in outer space, where it's Really vital.