LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-11-2013, 09:52 PM   #1
wlaw
Member
 
Registered: Jun 2004
Location: HK
Distribution: Ubuntu
Posts: 245

Rep: Reputation: 30
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 !
 
Old 08-11-2013, 11:12 PM   #2
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,841

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
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.
 
Old 08-12-2013, 04:21 AM   #3
r0w225
Member
 
Registered: Jul 2012
Location: South Africa
Distribution: Ubuntu precise pangolin 12.04LTS
Posts: 48

Rep: Reputation: Disabled
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!
 
Old 08-12-2013, 04:38 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
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.
 
Old 08-12-2013, 05:54 AM   #5
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
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.
 
Old 08-12-2013, 01:26 PM   #6
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
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.
 
Old 08-12-2013, 03:33 PM   #7
PECONET009
Member
 
Registered: Sep 2006
Location: Finland.
Distribution: kali linux.
Posts: 156

Rep: Reputation: 21
Lightbulb

Quote:
Originally Posted by wlaw View Post
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.
 
Old 08-12-2013, 03:52 PM   #8
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by PECONET009 View Post
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.
 
1 members found this post helpful.
Old 08-12-2013, 04:02 PM   #9
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
Quote:
Originally Posted by wlaw View Post
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.
 
Old 08-12-2013, 07:38 PM   #10
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by lleb View Post
(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.
 
Old 08-12-2013, 07:50 PM   #11
lleb
Senior Member
 
Registered: Dec 2005
Location: Florida
Distribution: CentOS/Fedora/Pop!_OS
Posts: 2,983

Rep: Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551Reputation: 551
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.
 
Old 08-12-2013, 07:57 PM   #12
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,573

Rep: Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142Reputation: 2142
Quote:
Originally Posted by johnsfine View Post
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.
 
Old 08-12-2013, 10:50 PM   #13
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
Quote:
Originally Posted by lleb View Post
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.

Last edited by frieza; 08-12-2013 at 10:52 PM.
 
Old 08-13-2013, 05:39 AM   #14
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by lleb View Post
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.
 
Old 08-13-2013, 07:50 AM   #15
cascade9
Senior Member
 
Registered: Mar 2011
Location: Brisneyland
Distribution: Debian, aptosid
Posts: 3,753

Rep: Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935Reputation: 935
Quote:
Originally Posted by frieza View Post
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 View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Size of the swap partition Nitram Linux - Newbie 5 12-04-2007 05:05 AM
Swap Partition Size Murdock1979 Slackware 11 07-27-2005 01:09 AM
What size should I make my swap partition? bobotoes Linux - Newbie 7 09-30-2004 10:36 PM
swap partition size alaios Linux - General 4 09-27-2004 01:21 PM
swap partition size? Toker Linux - Newbie 16 10-12-2003 11:19 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration