Do I need to adjust my SWAP size?

I recently went from 2GB of memory to 8GB. However I noticed that my swap size is only a little over 2GB.

In the Microsoft world I know that swap needs to be at least 1.5 times the amount of physical memory. Does the same rule apply to the OpenSuSE world?

If so, how do I adjust it to the correct size? And is there a way for the system to just automatically calculate the correct size?

On my CentOS box, it has 4GB of memory with about 5.4GB of swap…so it seemed to have followed that same logic on its own.

You usually only need to adjust the size if you want to use suspend to disk.

That ‘rule of thumb’ is wrong for Microsoft and is wrong for Linux. Something like it used to be suggested in the late eighties or early nineties, when relatively few megabytes of ram was the norm; even then, for the ‘rule’ to have any utility, computers that had heavier workloads had to to have more ram, which may have sometimes been the case, with the then cost of ram, but was not universally the case.

I recently went from 2GB of memory to 8GB. However I noticed that my swap size is only a little over 2GB.

For normal operation, if the workload has not changed, this means that you need less swap; as lOtz1009 has pointed out, if you suspend to disk, you may need more. OTOH, you might have bought more ram because the workload (or, potentially, bloat in some application(s) that you use) has increased…

(Whether or not you suspend to disk) I would not reduce the amount of swap, unless you are really very pushed for disk space; the normal case is that wastes a little disk space, of which you have plenty - not a problem.

If you do have to add swap space for suspend to disk to work reliably, add another swap partition. It can be easy (depending on how your partition table looks currently and where you have spare space), and it works.

If so, how do I adjust it to the correct size? And is there a way for the system to just automatically calculate the correct size?

Prior to 11.2 (?), SUSE did not compress on suspend. In those days, you needed an amount of swap equal to the maximum memory consumption (ram+ swap) that you use. This is easy to measure from ksysguard (or similar).

Currently, you should need less, but as I don’t know how to quantify how much less, I’d still go for the same amount, maybe just a shade less, if that came to a convenient round number, or was the amount that you have now.

On 2010-09-14 15:40, abacabb wrote:
>
> I recently went from 2GB of memory to 8GB. However I noticed that my
> swap size is only a little over 2GB.
>
> In the Microsoft world I know that swap needs to be at least 1.5 times
> the amount of physical memory. Does the same rule apply to the OpenSuSE
> world?

No.

> If so, how do I adjust it to the correct size?

Add a second swap partition, or enlarge it. Manually.

> And is there a way for
> the system to just automatically calculate the correct size?

No.
What is the correct size? There is no such thing.

Rule:

Create as much or as little swap as you really need. How much do I need? As much as you need. >:-P

If you are hibernating, you need as much swap as ram is in use, plus the swap previously used.
Roughly a bit more as ram, plus the maximum ammount of swap already in use.

This can be ·1, or ·100. Anything.

If you have lots of ram, and you don’t hibernate, and swap is not used, then you don’t need any swap.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” GM (Minas Tirith))

I’m sure someone will correct me if I am wrong but I think you need a pae kernel to take advantage of all this RAM; I assume you were running a default kernel with 2Gb.

32 bit desktop kernel is a pae so it will use it. But pae is a bank switch solution so there is a fair amount of extra overhead used in the address translations. If you want the best performance use 64 bit OS. The OP did not say if he is running 32 or 64 bit.

Running 32 bit OpenSuSE 11.1

Hmmm not sure if the 11.1 desktop kernel is pae. ???

You can always install the pae version if the system is not seeing more then 4gig.

It sees all 8gigs just fine. The only thing that was concerning me was swap size. But according to the other posters here it’s really not important unless I am suspending to disk.

Opening and changing large compressed files right? That would be time where I could see the swap being used heavily.

Is there a way to not dedicate a partition to swap? So as to have it auto expand as need be from an original set size?

On 2010-09-15 02:36, binaryfudge wrote:

> Is there a way to not dedicate a partition to swap? So as to have it
> auto expand as need be from an original set size?

You can use a static file, not dynamic.


Cheers / Saludos,

Carlos E. R.
(from 11.2 x86_64 “Emerald” GM (Minas Tirith))

Do (as root):

dd if=/dev/zero of=/root/swapfile.img bs=1M count=8000
chmod ou-rwx /root/swapfile.img
mkswap swapfile.img
swapon swapfile.img

This creates a 8G swapfile (adjust the count parameter for other sizes) and mounts it. You might want to adjust the path to the swapfile to a filesystem that has enough space for it.
To make the file mount on every startup you have to add an entry to your /etc/fstab:

/root/swapfile.img swap swap defaults 0 0

Note: The swap file should only be readable (and of course writeable) by root only. Also note that dd overwrites files without prompting so make sure the file in of=… does not exist. I don’t recommend using the above for a partition, because if you don’t know exactly what you are doing you might loose data (e.g. writing to the wrong partition. Use the YaST partition manager instead. )

EDIT of above post:

It has to be: chmod og-rwx /root/swapfile.img