LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Yet another SWAP question: Should I resize? (https://www.linuxquestions.org/questions/linux-newbie-8/yet-another-swap-question-should-i-resize-929004/)

michaelmas 02-12-2012 03:23 PM

Yet another SWAP question: Should I resize?
 
I know this topic has been disucssed to death and that there is no one truly optimal SWAP size for any case, but hear me out.

I have nearly 3gb RAM and a 250gb hard disk on my Lenovo laptop, running Ubuntu 10.04 LTS. Being a newbie, I chose the default install option, and the installer set up an 8gb SWAP space. That's nearly 3xRAM.

I am asking because I've been reading that in the old days, when RAM was more scarce, the swap should be 2xRAM, but currently I believe I have plenty of RAM and that the SWAP should be 2xRAM at best.

Code:

free -m
            total      used      free    shared    buffers    cached
Mem:          2770      2644        125          0        91      2086
-/+ buffers/cache:        466      2304
Swap:        8112          0      8112

Since I will be switching operating systems in few weeks (Fedora LXDE or Xfce) and possibly pre-partioning for dual boot, should I choose my own SWAP size? Or should I trust the automatic installer?

Is there a likely gain from choosing SWAP of, say, 5gb?

TobiSGD 02-12-2012 03:28 PM

The 2xRAM rule of thumb is way outdated. If you would need so much RAM that it would need 6GB (or even the 8GB given to you by the installer) of swap to run your workload the machine would be slow as hell. On a normal desktop machine (which includes laptops) 1-2GB should be more than sufficient, unless you want to use hibernate. In that case the swap partition should be at least the size of your physical RAM.
6 or more GB would simply be a waste of space.

ukiuki 02-12-2012 03:30 PM

Do you use Hibernation? The usual size of swap is the same as RAM so yours could be 3Gb, Even when it shows a lot of RAM in use there is a lot cached too so all good and there is no swap in use at all! How about your partitions space? Are things getting too big and space too small?

Regards

johnsfine 02-12-2012 03:48 PM

Quote:

Originally Posted by michaelmas (Post 4600753)
a 250gb hard disk
...
Is there a likely gain from choosing SWAP of, say, 5gb?

The maximum gain is that making SWAP 3GB smaller allows you to make some other partition 3GB larger.

How important is that to you? Do you have a 250GB drive because you need that much? Or do you need much less than that and have it because that is what was convenient to buy? Or do you need more than that and upgrading is inconvenient and you frequently move things to offline storage because you are out of space?

Next question, what is the downside of reducing swap from 8GB to 5GB. That amount of swap is basically insurance. In case of software memory leak, things slow down smoothly and let the problem be more easily diagnosed, rather than failing sooner in a harder to diagnose way. In case you start running certain unlikely large tasks, your system can handle it (maybe slowly) rather than fail. All very unlikely.

I don't know how you use your system. For ordinary use with your system specs the upside of reducing your swap size is small and the downside smaller. Basically, don't care.

michaelmas 02-12-2012 03:54 PM

@ TobiSGD
I never use hibernation and I'm just a regular desktop user, so clearly I'm wasting space here. Just hoping it's not affecting the performance.

@ ukiuki
Are you saying that my SWAP could be 3gb even though free -m shows 8gb?
I only have the SWAP and the root partition, and I haven't noticed anything unusual, yet.

michaelmas 02-12-2012 04:04 PM

Quote:

Originally Posted by johnsfine (Post 4600771)
The maximum gain is that making SWAP 3GB smaller allows you to make some other partition 3GB larger.

How important is that to you? Do you have a 250GB drive because you need that much? Or do you need much less than that and have it because that is what was convenient to buy? Or do you need more than that and upgrading is inconvenient and you frequently move things to offline storage because you are out of space?

Next question, what is the downside of reducing swap from 8GB to 5GB. That amount of swap is basically insurance. In case of software memory leak, things slow down smoothly and let the problem be more easily diagnosed, rather than failing sooner in a harder to diagnose way. In case you start running certain unlikely large tasks, your system can handle it (maybe slowly) rather than fail. All very unlikely.

I don't know how you use your system. For ordinary use with your system specs the upside of reducing your swap size is small and the downside smaller. Basically, don't care.

I'm actually only using about 30% of the hard drive, trying rather to keep large stuff on my external device. This is mainly because I just don't like having much stuff on my internal disk, not because of space scarcity.

But it's good to know that excessive SWAP only means less storage and not decreasing performance. Then I won't be losing much sleep because of this.

But I'm still wondering why Ubuntu installer would assign so much SWAP in the first place.

TobiSGD 02-12-2012 04:47 PM

Quote:

Originally Posted by michaelmas (Post 4600782)
But I'm still wondering why Ubuntu installer would assign so much SWAP in the first place.

That is a very good question, I never saw such a behavior on systems with "only" 3GB of RAM, may be the Ubuntu developers know something we don't.

johnsfine 02-12-2012 05:51 PM

Quote:

Originally Posted by michaelmas (Post 4600782)
But I'm still wondering why Ubuntu installer would assign so much SWAP in the first place.

My guess is that you have 4GB of physical ram installed and either a BIOS misconfiguration or not using the PAE kernel (or maybe a limitation of the hardware) prevents you from using a significant chunk of ram.

I'm guessing the Ubuntu installer looked at how much ram is physically present, rather than how much ram the about to be installed kernel would be able to use, then it applied the stupid old rule of 2xRAM for swap. Always was a stupid rule, even stupider now, but lacking any non stupid rule, what is a distribution install supposed to default to.

BTW, my guesses tend to be pretty good, but I wouldn't have said "guess" if this post had the level of confidence of my typical answers.

The less generally known fact that went into those guesses is that DMI information about how much ram is physically present is easy to read and totally independent of how much ram the motherboard or BIOS or kernel actually allow you to use.


All times are GMT -5. The time now is 10:18 AM.