LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   What is the size of the swap partition ? (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-size-of-the-swap-partition-4175473039/)

wlaw 08-11-2013 10:52 PM

What is the size of the swap partition ?
 
When I installed Ubuntu, I was asked the size of the swap partition.

I got a 500G partition for Ubuntu, and my RAM size is 8G, and will expand to 16G in a year or two. What should be the size of the swap partition then ?

Thank you !

EDDY1 08-12-2013 12:12 AM

Swap partition is usually twice the size of ram, but nowadays ram exceeds the amount necessary so you can decrease the size of swap if you like.
Running top will tell you how much you're using.

r0w225 08-12-2013 05:21 AM

hi

Well i think ubuntu precise pangolin 12.04LTS (for example) recquires at least 4 gig for the swap, as you have plenty of memory it will be no harm to set more.

Regards

__--__--__
You know nothing until you start sharing it!

TobiSGD 08-12-2013 05:38 AM

There are no rules of thumb regarding the size of the swap partition, although some ancient ones (like swap=2xRAM) still are seen sometimes in the wild. Ubuntu, like any other Linux distro, will run just fine even without a swap partition, unless you run out of RAM.

It depends solely on your usage of the machine how much swap is needed. On typical modern desktop machines with 4-32GB of RAM usually a swap partition of 1GB is more than sufficient, unless you run really huge workloads. The only exception to this is when you want to use the hibernate/suspend-to-disk feature, in that case you should have a swap partition that is as least as large as physical RAM.

As an example, on my main machine with 16GB of RAM I have a 1GB swap partition and no problems at all with that, while on my laptop with 4GB of RAM I use the hibernate/suspend-to-disk function and therefore use a 4GB swap partition.

AwesomeMachine 08-12-2013 06:54 AM

You can always add swap space if need be:

$ dd if=/dev/zero of=/swap.file bs=1M count=1000
$ mkswap /swap.file
$ swapon /swapfile

Will give you 1.0 GB of swap space on the fly. I like swap space, because of the way I work, but for most people running a lappy or desktop for entertainment or office-productivity applications, the machine will never use swap space.

jpollard 08-12-2013 02:26 PM

One thing to remember... If this is for a laptop (unlikely) you need enough swap to at least hold active memory. If swap is actually used, you need enough for active memory + that used during normal swap activity. This is to support hibernation (to disk - it allows you to turn off your system, replace battery, put new battery in, then resume). Suspend to memory is faster- but you cannot turn off your system without causing a crash.

PECONET009 08-12-2013 04:33 PM

Quote:

Originally Posted by wlaw (Post 5007539)
When I installed Ubuntu, I was asked the size of the swap partition.

I got a 500G partition for Ubuntu, and my RAM size is 8G, and will expand to 16G in a year or two. What should be the size of the swap partition then ?

Thank you !

My rule of thumb for a Swap partition is twice your ram, example going on your type of ram of 8gb it would be 2x8=16gb, so I would give your swap partition 16gb of space.
I have 16gb swap on my system and it runs nice and sweet, but you can always do a test yourself with different swap sizes.

johnsfine 08-12-2013 04:52 PM

Quote:

Originally Posted by PECONET009 (Post 5008043)
My rule of thumb for a Swap partition is twice your ram, example going on your type of ram of 8gb it would be 2x8=16gb, so I would give your swap partition 16gb of space.
I have 16gb swap on my system and it runs nice and sweet, but you can always do a test yourself with different swap sizes.

Probably wasting 16GB of disk space did no harm on your system, so I won't second guess you regarding "runs nice and sweet". But your rule of thumb was useless long ago when it was in common use. Now it is obsolete as well.

On an ordinary desktop or laptop (not server) system (assuming you are not using hibernate) there is no correlation between the amount of ram you have and the amount of swap space you ought to have.

Given zero info about the usage of a system, my best guess at an appropriate swap size is 2GB. If you have 0.5GB of ram, 2GB of swap is a good choice, though 2x ram would suggest less. If you have 16GB of ram, 2GB of swap is a good choice, though 2x ram would suggest absurdly more.

BTW, on your system that HAS 16GB of swap, did you ever check how much swap was USED? I expect swap use was around zero.

On ordinary systems, swap use is near zero. On ordinary systems, swap is mainly a safety valve for unexpected situations. If almost no swap is used, 2GB makes a good safety valve. In the unlikely event that you notice more than a few hundred MB of swap actually getting used, you ought to increase the swap allocation above 2GB.

lleb 08-12-2013 05:02 PM

Quote:

Originally Posted by wlaw (Post 5007539)
When I installed Ubuntu, I was asked the size of the swap partition.

I got a 500G partition for Ubuntu, and my RAM size is 8G, and will expand to 16G in a year or two. What should be the size of the swap partition then ?

Thank you !

with that much RAM there is really no need to have a HUGE swap partition any longer. please keep in mind that the performance of your RAM is going to be drastically faster read/write then standard HDDs (note that SSD drives are almost as fast as physical RAM)

With that in mind lets look at the older settings for swap:

systems with less then 1G ram you typically had a 2:1 ratio of swap:ram

systems between 1G-4G you could typically use a 1:1 or 1.5:1 ratio of swap:ram

systems greater then 4G you can cap your swap at 4G as there really is no need to have much more swap then that. If you are running applications/programs that are consuming more then 4G of physical RAM then you will want to increase the amount of RAM.

As you are already starting with 8G of ram and will be upgrading to 16G within the next year/2year a 4G swap should be fine. You can always use more swap if you wish to consume extra HDD space.

TobiSGD 08-12-2013 08:38 PM

Quote:

Originally Posted by lleb (Post 5008058)
(note that SSD drives are almost as fast as physical RAM)

Not at all. Typical modern SSDs have transfer rates (read) of about 500 MB/s (about 450-500 MB/s when writing, dependent on number of Flash chips), single channel DDR3-1333 RAM has a maximum data rate of 10.6 GB/s. In modern PCs you will more likely see DDR3-1600 or even -1866, with data rates of 12.8 GB/s and 14.9 GB/s, so RAM is at least 20 times faster than SSDs.

lleb 08-12-2013 08:50 PM

Yes SSDs are still slower then RAM, but they are considerably faster then HDDs and id never waist the space of a SSD for swap, they are just to bloody expensive for the time bean to use for swap. thus i dont consider them for a swap partition.

suicidaleggroll 08-12-2013 08:57 PM

Quote:

Originally Posted by johnsfine (Post 5008052)
Probably wasting 16GB of disk space did no harm on your system, so I won't second guess you regarding "runs nice and sweet". But your rule of thumb was useless long ago when it was in common use. Now it is obsolete as well.

On an ordinary desktop or laptop (not server) system (assuming you are not using hibernate) there is no correlation between the amount of ram you have and the amount of swap space you ought to have.

Given zero info about the usage of a system, my best guess at an appropriate swap size is 2GB. If you have 0.5GB of ram, 2GB of swap is a good choice, though 2x ram would suggest less. If you have 16GB of ram, 2GB of swap is a good choice, though 2x ram would suggest absurdly more.

BTW, on your system that HAS 16GB of swap, did you ever check how much swap was USED? I expect swap use was around zero.

On ordinary systems, swap use is near zero. On ordinary systems, swap is mainly a safety valve for unexpected situations. If almost no swap is used, 2GB makes a good safety valve. In the unlikely event that you notice more than a few hundred MB of swap actually getting used, you ought to increase the swap allocation above 2GB.


What he said

Ignoring hibernation on a laptop (which is often finicky anyway), swap is just used as a safety valve for problems. There is absolutely no reason why swap needs to be 2x RAM, that "rule of thumb" has been obsolete for longer than it was applicable. It's right up there with the default 5% root reserve space for ext3 partitions. My systems never use any swap unless a process goes awry and eats all the RAM. In that case, it's simply a matter of how quickly I catch it versus how "awry" the process has gone. I typically keep my swap partitions to 2GB or smaller, except for development machines where excess RAM usage by prototype codes can be a "regular" occurrence.

frieza 08-12-2013 11:50 PM

Quote:

Originally Posted by lleb (Post 5008179)
Yes SSDs are still slower then RAM, but they are considerably faster then HDDs and id never waist the space of a SSD for swap, they are just to bloody expensive for the time bean to use for swap. thus i dont consider them for a swap partition.

perhaps, an SSD being solid state rather than mechanical will have faster seek times than an HDD to be certain (though actual transfer rates for contiguous data are probably not so disparate), SSDs, like HDs, however, are still limited to the speed of the SATA bus, which as lleb and TobiSgd have stated is significantly slower than ram.

as for rules of the size of swap, really it depends on what you intend to do with your machine, most people who do light use of there machines can get away with no swap, but with the size of HDDs being so huge these days, a few gigs wouldn't hurt anyways.

TobiSGD 08-13-2013 06:39 AM

Quote:

Originally Posted by lleb (Post 5008179)
Yes SSDs are still slower then RAM, but they are considerably faster then HDDs and id never waist the space of a SSD for swap, they are just to bloody expensive for the time bean to use for swap. thus i dont consider them for a swap partition.

I see that quite contrary. If you have the need for a fast system even when swap is going to be used then using the significantly faster SSD for swap would be the option I would choose. But since i know that this isn't an issue with my systems my swap also lies on the slower HDD, although in a LVM spanned over two disks. On my laptop I have no problem with using swap on the SSD, since this machine does not have a mechanical drive and having swap on the SSD gives me the benefit of a shorter wake-up time from hibernate.

cascade9 08-13-2013 08:50 AM

Quote:

Originally Posted by frieza (Post 5008241)
perhaps, an SSD being solid state rather than mechanical will have faster seek times than an HDD to be certain (though actual transfer rates for contiguous data are probably not so disparate)

A SSD is a lot faster for reading/writing contiguous files than a HDD.

http://www.pcstats.com/articleview.c...id=2718&page=4

Its not a very good review I know, sorry. But you get the idea. ;)

Quote:

Originally Posted by frieza (Post 5008241)
SSDs, like HDs, however, are still limited to the speed of the SATA bus, which as lleb and TobiSgd have stated is significantly slower than ram.

For now its slower.

Quote:

The latest revision of the long-running SATA specification, SATA 3.2 brings a number of improvements for storage devices - but by far the most interesting is SATA Express. A variant of SATA first announced back in January this year, SATA Express uses up to two PCI Express 3.0 lanes to offer a peak transfer rate of 16Gb/s, or 2GB/s, compared to SATA 3's 6Gb/s.
http://www.bit-tech.net/news/hardwar...8/13/sata-32/1

But just putting a current SATAIII SSD on a SATA express port wont make much if any 'real world' difference, and only minor differences in benchmarking....just like when HDDs moved from SATAI->SATAII or SATAII-> SATAIII (its only just been in the last year or two that HDDs have got close to the bandwidth limit of SATAI).

SSDs will move to SATA express sooner or later, they are already touching the edge of the bandwidth limit for SATAIII.

BTW, the fastest SATAIII SSDs are as fast as RAM....as long as you are talking PC-66 SD-RAM or slower. ;)


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