LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 10-21-2010, 07:48 PM   #1
Anubis
Member
 
Registered: Mar 2002
Location: /dev/null
Distribution: Ubuntu - Fedora - or whatever works or gets handed to me.
Posts: 119

Rep: Reputation: 15
Is a swap file necessary?


I notice that on desktops, now a days systems run anywhere from 2GB to 6GB.

Long ago I would setup twice the amount of physical ram as a swap file on the hard drive. This was when 486 were the thing to have with 16MB of ram. (Yes, it's been that long)

I started wondering while monitoring my current systems with "htop" that the swap file/partition is never used.

I can think of many reasons it would come in handy in a server setup, but on desktops is it worth or absolutely needed on desktops?
Thanks for you input on the matter.
 
Old 10-21-2010, 08:45 PM   #2
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,502

Rep: Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489Reputation: 2489
It should not be necessary. It depends upon how much physical RAM you have and what you use your computer for. 2GB is generally enough unless you are using the hibernate function or using extreme RAM intensive programs.
 
Old 10-21-2010, 09:27 PM   #3
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -
Quote:
Long ago I would setup twice the amount of physical ram as a swap file on the hard drive.
I remember those days, too

yancek is absolutely correct. The old rule no longer applies. Most systems can get along quite happily with no swap most of the time. In fact, if you ever run "top" and find non-zero swap usage, that's usually a red flag.

However...

In the same spirit that "things have changed": disk is cheap, and swap can be useful (and/or [/i]necessary[/i]).

I would discourage you from eliminating your swap partition altogether. I would just take the default that's created on your system. The "rule of thumb" nowadays is "swap == RAM". If you have 2GB RAM, I would encourage you to have 2GB swap.

These links give more details:

https://help.ubuntu.com/community/SwapFaq

http://lissot.net/partition/partition-04.html#SwapSize
 
1 members found this post helpful.
Old 10-22-2010, 01:02 AM   #4
indietrash
LQ Newbie
 
Registered: Aug 2008
Posts: 24

Rep: Reputation: 1
the "rule of thumb" as far as I know it has been (for ten years or so) swap should be ½RAM.
 
1 members found this post helpful.
Old 10-22-2010, 01:54 AM   #5
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
I still keep a 2 gig swapfile on my 8 gig RAM machine. My system even occasionally makes some use of it.

I no longer think it is essential, but storage space is cheap and this gives a reserve that will keep the system out of trouble, so why not.
 
Old 10-22-2010, 06:29 AM   #6
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
It will only prevent the OOM killer when you run out of RAM, that's all, and not reliably so. Not much use, but I do keep a 1 GB swap file, so that can delete it if I need more space.
 
Old 10-22-2010, 07:22 AM   #7
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 Anubis View Post
Long ago I would setup twice the amount of physical ram as a swap file on the hard drive.
Long ago that was a bad rule. It is even less valid now.

Quote:
I can think of many reasons it would come in handy in a server setup, but on desktops is it worth or absolutely needed on desktops?
Typically swap is more important on a server than on a desktop. In most cases it isn't "absolutely needed" on either. In my opinion, it is worth having for both.

Quote:
Originally Posted by paulsm4 View Post
The "rule of thumb" nowadays is "swap == RAM".
Quote:
Originally Posted by indietrash View Post
the "rule of thumb" as far as I know it has been (for ten years or so) swap should be ½RAM.
I don't think there is even a positive correlation between the amount of ram you have and the amount of swap you should have. For any given workload, the more ram you have the less swap you need.

If ram were expensive and if purchase decisions about ram were typically careful well informed decisions, then we might infer a strong positive correlation between the memory requirements of the workload and the amount of ram purchased. Then we could infer a weaker, but still positive, indirect correlation between the amount of ram and the appropriate amount of swap space. But none of that fits real world behaviors regarding ordinary desktop computers.

If you need a "rule of thumb" for uninformed decisions about swap size for desktop systems, I prefer this one:
If your hard drive is over 250GB, the swap size should be 2GB. I don't care if your ram is 0.5GB or 32GB. Ram size doesn't usefully inform the choice of swap size.
Smaller hard drives might call for a more careful choice of swap size.

Ram size should inform later resizing of swap space: If you have 0.5GB ram and 2GB swap you should expect significant swap usage. If you use more than half the swap space, you probably should get a new system with more ram (I'm assuming a system with .5GB ram is too old for upgrading just ram to make sense).

If you have 8GB or more of ram and 2GB swap you should expect tiny or zero use of swap. If you use even a quarter of the swap space, you should reconfigure to have more than four times the max swap you ever used (but if that is over 2% of your hard drive size you may want to compute requirements more carefully).
 
Old 10-22-2010, 08:00 AM   #8
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Actually, just as an example, I have 2GB RAM, and 1 GB swap file ... usually, no swap is used at all.
 
Old 10-22-2010, 08:12 AM   #9
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Sigh.....YAISNP (yet another "is swap necessary" post).

Does anyone ever try the using "search for similar threads" option?

Although I'll say johnsfine's last post is nicely stated.
 
Old 10-22-2010, 08:28 AM   #10
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
What's being missed in all this (later) discussion is yancek's allusion to hibernation. If you hibernate to swap, it'd better be there, and at least as big as occupied RAM plus some.

Swap is almost always used - generally cached these days, but it's a tier in the storage hierachy that memory management wants to use. Give it some, and forget about it - as said, disk is cheap.
 
1 members found this post helpful.
Old 10-22-2010, 08:40 AM   #11
H_TeXMeX_H
LQ Guru
 
Registered: Oct 2005
Location: $RANDOM
Distribution: slackware64
Posts: 12,928
Blog Entries: 2

Rep: Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301Reputation: 1301
Actually, my monitors say that swap isn't even being used for cache. Not even all 2GB of RAM is being used for cache, only 150 MB, and total of 350 MB, even with FF open.
 
Old 10-22-2010, 08:49 AM   #12
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
I haven't used hibernation myself and haven't seen any clear answer to an obvious question about hibernation:

Is hibernation implemented in some super crude manner that writes out essentially all of ram in addition to whatever was already in the swap space? Or does hibernation only write out the ram pages that don't already have known backing locations on disk?

Most ram use on a typical home system is either caching or file mappings (especially mapped code) both of which correspond to known locations on disk. So if ordinary memory management forced those pages out, they would not be written to swap. If dirty (unlikely) they would be written to their known locations and if/once clean they can just be dropped.

A sane design for hibernation would drop all those pages the same way they would be dropped if ordinary memory pressure forced them out. If that is how hibernation works, then the swap file size needed for using hibernation would still be larger than what one would need if not using hibernation, but not larger by nearly the full ram size (as is often suggested when hibernation is discussed relative to swap file size).
 
Old 10-22-2010, 09:40 AM   #13
edbarx
Member
 
Registered: Sep 2010
Distribution: Used Debian since Sarge. (~2005)
Posts: 373

Rep: Reputation: 21
A swap partition although not normally used can also act a safety valve when a program misbehaves and requests huge amounts of RAM. I think, sacrificing about 2GB of hard-disk space shouldn't be a problem with most of today's hard disks.
 
Old 10-22-2010, 11:43 AM   #14
DavidMcCann
LQ Veteran
 
Registered: Jul 2006
Location: London
Distribution: PCLinuxOS, Debian
Posts: 6,140

Rep: Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314Reputation: 2314
One point to consider is how many partitions you have. If you don't want to mess with an extended partition, you want to keep Windows, and the latter came with a recovery partition, then you are limited to home and root.

Load up your computer with as much stuff as possible and run free; if swap isn't being used, you don't need it.
 
Old 10-22-2010, 12:05 PM   #15
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 DavidMcCann View Post
One point to consider is how many partitions you have. If you don't want to mess with an extended partition, you want to keep Windows, and the latter came with a recovery partition, then you are limited to home and root.

Load up your computer with as much stuff as possible and run free; if swap isn't being used, you don't need it.
Such a short post with so much in it I disagree with!

"mess with" is a very negative phrase for something as simple, common and problem free as an extended partition. If you think you might want more than three partitions, you should make some of them logical partitions inside an extended partition. No "mess". You just need a moment of forethought to decide to do it that way. You could set up four primary partitions with no extended nor logical, but you probably shouldn't. Next time you want to shrink existing partitions to create one more, having no extended would make that change much harder.

Don't split /home from the / partition unless you have a good idea of what that accomplishes for you as well as a good idea of how much space each should get. That is a topic of many other threads, so here I don't want to go into any details beyond my opinion that most Linux users should not split /home from /. Even if you do decide to split /home that is a silly reason (partition count) to decide to not have swap.

What is "as much stuff as possible" supposed to mean? If you have some swap, you can easily load up your computer with enough running programs to use most of that swap. To make that extra easy, pretend the computer is shared by multiple family members (maybe you don't even need to pretend). So open up a bunch of programs and lock the desktop session and walk away, so some other family member logs into a new session without closing your session, then she starts up a bunch of programs as well.

Whether swap is used or not in some artificial test load only tells you something about that artificial test load. It tells you nothing about whether you really have use for swap.

If your test load is a better representation of the specific maximum set of programs you might legitimately run together, and swap isn't used then your test does prove swap is not needed, but even that doesn't prove swap wouldn't be useful. The same set of programs loaded with more natural timing would tend to use more cache and more swap. If the extra swap weren't available, it couldn't use the extra cache and might run a little slower due to using less cache. Not likely to be a big deal, but half a percent of your 400GB hard drive is even less of a big deal. (My hard drive is a few years old and 500GB, but I assume some people still get stuck with even smaller ones).

Last edited by johnsfine; 10-22-2010 at 12:09 PM.
 
1 members found this post helpful.
  


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
swap file vs. swap partition verndog Ubuntu 16 07-09-2012 08:49 PM
Can swap file or a swap partition be mounted and read? Mr-Bisquit Linux - General 3 06-08-2009 02:16 PM
swap file or swap space? simonb1975uk Linux - General 11 08-15-2008 02:39 PM
swap space (or) swap file yusufs Linux - Newbie 8 07-17-2008 02:02 AM
Need Help Increasing Swap by creating a swap file froggo Red Hat 3 06-13-2006 08:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 01:27 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