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!
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Swap is virtual RAM. If you are running a program and your RAM is full, then the data the program would normally store in RAM will be written to the swap partition.
3GB is a pretty large amount of RAM. Depending on your usage of the system, you may not need swap. I would recommend doing at least 1 to 2GB unless you really need to save that space on your hard disk.
The general guideline of 2x the size of your RAM can make sense when you have a smaller amount of RAM, but when you get over 1GB RAM there isn't much point in doing 2x.
I have 2GB of RAM on my laptop, and I rarely, if ever, hit swap.
If you are doing suspends or hibernates (never can recall which) then you need to have more swap then you do memory because it'll suspend/hibernate to the swap area. Otherwise it really depends on how you are using the system.
These days, with plenty of RAM available, the amount of SWAP you need is just the amount needed for getting Suspend-to-disk (usually = to-swap) working, if you intend to use this feature. For security in case of exceptionnal workload, I wouldn't go under 512MB.
The rule 'Swap = RAM x 2' which underlies the original question is a stupid myth from the dark ages of computers with 8 MB RAM for text processing and 16 MB (yay!) for what passed as multimedia back then.
I have a system with only 768 MB of RAM which rarely ever uses even one MB of the 996 MB of swap I have set up. With 3 GB I'd not bother with swap at all. Depends on what the system is supposed to do of course.
The maximum amount of swap would be 2xRAM, but normally 1xRAM is enough. For me I have 2 GB RAM, 2 GB swap, but just a few days ago opening some large image files used up almost all the RAM and swap, so it really depends on what you do with your system.
The amount of swap needed is determined by what you are doing on the machine. I have a mcahine with 2 gigs of ram and four of swap, in some situations I have used 2/3 of that swap. However I would not consider my use of that particular system as "typical". When you consider that a 320gig drive is well under $70 now is it really costing you that much to follow the worst case rule of 2X ram?
The thing is that if you run out of physical ram and you have no swap, then the system will start closing programs without previous notice, and you can lose data.
So, it's always (and affordable nowadays) to have some swap just in case. At least, that way, you can notice the huge performance penalty when your ram is filled, and you have some extra time to save your work and close apps normally.
For the rest, there's little point in using more than 512 mb of swap, unless you need it for hibernation or whatever. If you hit more than half a GB of ram your system is going to be ususable anyway and you simply need more ram, or you need to use lighter stuff.
If I have 3GB RAM do I need to have 6GB Swap. Is it really necessary.what is the purpose of having swap.
As others have stated, in general, no, not with 3GB of ram, unless you get into some video editing situation where you are editing gigabytes of video in ram. I generally view the swap question as one of those "if you have to ask, then you don't need it" types of questions.
I usually stick by the old rule of thumb and have twice as much swap as ram. You may scoff if you like, but I have no reason not to...I can't even fill 50 GB of my 250 GB hard drive.
I usually stick by the old rule of thumb and have twice as much swap as ram. You may scoff if you like, but I have no reason not to...I can't even fill 50 GB of my 250 GB hard drive.
If there's no reason to do so, then there's no reason to do so. We might as well say that there's no reason to have 6gb of swap space. So, that argument is invalid by itself Believe me, I have a total of 1.2 TBs, and I am going to buy a new disk soon because I have only ~100GB left.
If the swap starts filling up due to a memory lack in firefox (just an example ) and the computer hangs without you being able even to move the mouse pointer, you are going to wish that your swap space was smaller, so the program crashes and is closed soon. Otherwise, you might have to wait for a long time until you can do anything with your box. That can be minutes to hours, depending on the hardware.
There's really no point in having such a huge swap space, unless it's for very concrete tasks. And even then, if you really fill 6gb of swap and you only have 3gb of ram, you definitely are running software that your box is simply not capable of running, and you need an upgrade.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.