Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Other Things Gentoo
  • Search

Do you really need SWAP?

Still need help with Gentoo, and your question doesn't fit in the above forums? Here is your last bastion of hope.
Post Reply
Advanced search
24 posts • Page 1 of 1
Author
Message
Lupin_the_3rd
Apprentice
Apprentice
User avatar
Posts: 168
Joined: Sun Apr 03, 2005 6:40 pm

Do you really need SWAP?

  • Quote

Post by Lupin_the_3rd » Sun Jul 15, 2007 5:24 am

I have a Santa Rosa notebook with 2.0 GB of ram. Do I really need to setup some swap? Is it mandatory to have swap partition/file or just best practice? What happens if I have no swap, and I run out of memory and try to start a new program, it gives an error?

TIA!
Compaq XP1000 Alpha EV67 667Mhz w/ 2GB ECC
32bit PCI: ATI Radeon 9100 (DRI works!)
32bit PCI: Generic Firewire 400 card
64bit PCI: BCM5703 Gig-E (Compaq NC7771)
64bit PCI: Sil3124 SATA w/ mdadm RAID1 (pair of WD VelociRaptors)
Top
Sven Vermeulen
Retired Dev
Retired Dev
User avatar
Posts: 1345
Joined: Thu Aug 29, 2002 8:10 am
Location: Mechelen, Belgium
Contact:
Contact Sven Vermeulen
Website

  • Quote

Post by Sven Vermeulen » Sun Jul 15, 2007 5:47 am

You do not have to have a swap partition (or file), but it is greatly encouraged.

My laptop has 1.5Gbyte memory and I have a 2Gbyte swap space because I want to be able to run hibernate, but I don't often get to see the swap being used (although it does on occasion happen).
Please add "[solved]" to the initial topic title when it is solved.
Top
Paapaa
l33t
l33t
User avatar
Posts: 955
Joined: Sun Aug 14, 2005 8:45 am
Location: Finland

Re: Do you really need SWAP?

  • Quote

Post by Paapaa » Sun Jul 15, 2007 8:38 am

Lupin_the_3rd wrote:I have a Santa Rosa notebook with 2.0 GB of ram. Do I really need to setup some swap? Is it mandatory to have swap partition/file or just best practice? What happens if I have no swap, and I run out of memory and try to start a new program, it gives an error?
Swap is not mandatory. If you run out of memory I think Linux kills a few processes to make room for new ones. This is done by OOM killer: out-of-memory killer. So there should be no panic or lockup.

The need for swap depends on what you do and how much mem you have. The 2XRAM rule is stupid and doesn't usually apply to new computers having lots of ram. I think swap is just for emergencies - not for real usage. I have 2GB Ram and 512MB Swap and I think I have never needed it. I do normal desktop usage.

Also, you don't have to have a swap partition. You can create a swap file. And you can decide to do it if you find out you need it.
Paludis, the way packages are meant to be managed.
Top
Cyker
Veteran
Veteran
Posts: 1746
Joined: Thu Jun 15, 2006 7:43 pm

  • Quote

Post by Cyker » Sun Jul 15, 2007 9:39 am

I've been told I have to DISABLE swap if I want to max out the RAM (4GB) in my box! (And not use the 64GB kernel extension...)

So I'd say its not necessary at all. I have 512MB of swap at the moment, but it says 2MB used. And that's all it's ever said! :shock: ;)
Top
PaulBredbury
Watchman
Watchman
User avatar
Posts: 7310
Joined: Thu Jul 14, 2005 3:47 pm

  • Quote

Post by PaulBredbury » Sun Jul 15, 2007 9:50 am

Cyker, I don't think swap makes any difference for that - see thread.
Top
jlh
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 145
Joined: Sun May 06, 2007 11:13 am
Location: Switzerland::Zürich

  • Quote

Post by jlh » Sun Jul 15, 2007 4:56 pm

I strongly recommend to have swap. The system will run fine without, but having unused swap should not hurt you in any way. In the worst case you could benefit from it. :D

If the reason is that you don't want to partition your disk, then consider using a swap file instead of a swap partition. A swap partition is usually recommended though, because it can't fragment. A swap partition on a secondary disk is even better (faster in case the primary disk is being used at the same time). If you end up wanting a swap file, take care that it's not fragmented.

Unlike what you might think, swap isn't only used when RAM is eaten up; it will be used much sooner already. As you may know, the kernel ends up using all of your RAM sooner or later. Some of it will be used by applications in the usual way and the rest is for the cache/buffer that will speed up accesses to files/blocks that are in it and therefore won't have to be read from disk. And no matter how much RAM you have, eventually all 'free' RAM will be used for that. When a process needs some memory, the kernel has two choices: Free up some cache/buffer data or swap out memory that hasn't been used in a long time. It will do either of those or a mix of both, whatever it thinks is better; this choice is controllable by the 'swapiness' setting. In some situations it's better to swap out some unused memory of processes instead of deleting some valuable cached data that might speed up things later. But it depends on the situation.

So even if you have plenty of RAM to hold everything, if you also have swap, then you might end up having more RAM avaliable for what you do. Of course this highly depends on lots of things and the best is if you just try yourself: Create 2GB of swap and then use your system normally for an extended period of time. If you ever notice the swap being used, then that's a sign that you should keep it. If it's not being used, keep it anyway, it can't hurt you. If you feel that the swap makes things go slower, then you probably should tweak the swapiness (I lowered it too, because the default of 60 seems a bit high to me).
Top
AaronPPC
Guru
Guru
Posts: 522
Joined: Sun May 29, 2005 8:22 am
Location: Tucson, AZ

  • Quote

Post by AaronPPC » Sun Jul 15, 2007 10:16 pm

There other benefit to having a swap partition is that you can use suspend-to-disk.
--Aaron
Top
Xenoist
n00b
n00b
User avatar
Posts: 26
Joined: Wed Aug 21, 2002 7:27 am
Location: EU/DE/NRW/NEUSS
Contact:
Contact Xenoist
Website

  • Quote

Post by Xenoist » Sun Jul 15, 2007 11:00 pm

I nearly need 1,5GB normal memory on my AMD 64 system at work.

Realy much spam combined with evolution does a fork bottle neck.

The interesting thing was after 750 MB swap and 1 GB of memory in use the system hangs up.

( fixed swap error ... )

After adding 3 GB swap this problem is gone.

By the way it happens when updating my gentoo mostly by glibc updates.

I add swap to solve this 10 to 30 minutes reboot or reset times (worst case).

Swap is needed like MS's pagefile.sys.
Once live is to short to learn all, but keep trying it.

"emerge the world" every day!
Top
broken_chaos
Guru
Guru
Posts: 370
Joined: Wed Jan 18, 2006 7:47 am
Location: Ontario, Canada

  • Quote

Post by broken_chaos » Mon Jul 16, 2007 9:05 pm

Personally I see swap on a desktop as a potentially useful thing (just in case - but you probably don't need it), but as a bad idea on a laptop (due to power consumption issues - touching swap spins up disks, drains more power, slows everything down) if the machine has >=2G of RAM (you might even get away with 1G of RAM and no swap if using lighter programs). It's handy to have some extra disk space around (an empty partition, or just spare space for a swapfile) in case you *need* swap, but having it enabled all the time strikes me as overkill paticularly on laptops.

And having swap as 'emergency' memory on a machine with >=2G of RAM strikes me as, honestly, a silly idea. If you've got something eating up 2G of RAM, how long will it really take to eat up another gig or two of swap, grinding your machine to a halt while doing so? I'd rather it get to killing processes sooner, rather than thrashing my disk from swap usage and then killing things. With 2G of memory, and no swap, I've never run into a problem, even having /var/tmp/portage on a tmpfs filesystem (size=1024M - half my total RAM). Worst happened was that, while doing three simultaneous heavy emerges, /var/tmp/portage ran out of space (which, as noted, is limited to half my RAM's size) - I just remounted it to clear it, and did those emerges in sequence instead.

Currently, for instance, on a reasonably fresh bootup, I have ~300M of memory used *INCLUDING* buffers and cache (126M without buffers/cache) - this is running X.org, wmii, Firefox, mutt, Pidgin, and having played a movie in mplayer, and having a reasonable amount of services running (the usual syslog/cron/net/etc. plus mpd). Even when I used KDE, I rarely saw my memory usage, excluding buffers/cache, rise above about 500M, with lots of heavy programs running - konqueror, kopete, kmail/kontact, several terminals, a game, amarok, etc...

*shrug* Just my personal experience though. I'm perfectly happy with my swap-less 2G RAM system, when running my current light environment, or even when i was running full KDE.
Top
wyvern5
Apprentice
Apprentice
Posts: 161
Joined: Sat Nov 11, 2006 4:39 am

  • Quote

Post by wyvern5 » Mon Jul 16, 2007 9:36 pm

Disk is cheap. Use swap.
Top
broken_chaos
Guru
Guru
Posts: 370
Joined: Wed Jan 18, 2006 7:47 am
Location: Ontario, Canada

  • Quote

Post by broken_chaos » Mon Jul 16, 2007 9:45 pm

wyvern5 wrote:Disk is cheap. Use swap.
The problem isn't a lack of disk space, almost ever. It's usually a matter of not wanting the power drain/slowdown on a laptop if anything hits swap. This can be mitigated with the vm.swappiness (not sure if I spelt that correct) sysctl parameter, but it's still a rather big drain to have constant disk access if you do have anything hit swap.
Top
wellwhoopdedooo
n00b
n00b
Posts: 69
Joined: Fri Mar 04, 2005 6:06 pm

  • Quote

Post by wellwhoopdedooo » Mon Jul 16, 2007 10:04 pm

broken_chaos wrote:
wyvern5 wrote:Disk is cheap. Use swap.
The problem isn't a lack of disk space, almost ever. It's usually a matter of not wanting the power drain/slowdown on a laptop if anything hits swap. This can be mitigated with the vm.swappiness (not sure if I spelt that correct) sysctl parameter, but it's still a rather big drain to have constant disk access if you do have anything hit swap.
It's better than having random processes get killed because you found a memory leak. I have my swappiness set to 5--nothing goes in there unless it's going to stay. Right now I have 800MB swap used, because something, I can't figure out what, but maybe X itself, has a memory leak. If I had no swap, my 768MB RAM would be eaten, and my system would be unstable. As it is, that stuff is just going to sit in swap and not hurt me until I decide to reboot, probably at the next kernel/glibc upgrade. I have plenty more swap too, so it's basically free protection from memory leaks.

Would be nice if more people used RAII though.
Top
jlh
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 145
Joined: Sun May 06, 2007 11:13 am
Location: Switzerland::Zürich

  • Quote

Post by jlh » Mon Jul 16, 2007 11:12 pm

wellwhoopdedooo wrote:It's better than having random processes get killed because you found a memory leak.
Firstly, this is not random; most of the time the right process gets killed (and if it does it wrong, you can teach it to do better). Secondly, that is a matter of opinion. Some people will indeed prefer have a leaking program be killed sooner than to have it first thrash on swap and then be killed, draining the laptop battery. But memory leaks aren't an argument here: A leak that eats 2GB of a swapless system will also eat up the 2GB additional swap, if you have it. Instead of being swapless because of that, fix the memory leaks and if you can't do that, find a way to limit memory consumption of a single process; I think ulimit can do that.

My comment from above was completely oriented on a desktop system and not a laptop, simply because I don't own one. Saving battery power is a good reason to be swapless, I think. I'd still prefer using swap and set the swapiness very low so that if memory is really required, processes can have it.
Top
wellwhoopdedooo
n00b
n00b
Posts: 69
Joined: Fri Mar 04, 2005 6:06 pm

  • Quote

Post by wellwhoopdedooo » Tue Jul 17, 2007 1:18 am

Hmm, I was always under the impression that it was simply random. I've heard it is, and it sure seems so from the few times I've run into it. Either way though, it gives you a chance to recover your way instead of whatever way the system figures out for you. I know I've started some process and gotten a switch or redirect wrong and had to kill it when it started thrashing, which is better than my X server dying and taking down 90% of my user processes with it. That's happened, and it sucks even if you don't have unsaved work, especially when you know you could have just hit CTRL-C if you were fast enough for it. My reflexes are faster than my disk can write 1.5GB... not so much for RAM :(
Top
jlh
Tux's lil' helper
Tux's lil' helper
User avatar
Posts: 145
Joined: Sun May 06, 2007 11:13 am
Location: Switzerland::Zürich

  • Quote

Post by jlh » Tue Jul 17, 2007 6:05 pm

wellwhoopdedooo wrote:Hmm, I was always under the impression that it was simply random
It calculates something like a 'badness' score for all processes, which I guess is somewhat proportional to the memory they use; and based on that it kills a process. This looks like more informations about the subject. I think it is or was a known problem that the OOM killer will kill the X server by mistake, because it appears to use lots of memory since depending on how you look at it, the entire graphic card memory is memory used by the X server. You can adjust things with the files /proc/<pid>/oom_*. But don't ask me how exactly, I've never done it.
Top
captwiggum
n00b
n00b
User avatar
Posts: 39
Joined: Fri Mar 10, 2006 3:59 pm
Location: Atlanta, Georgia, USA

Do you really need SWAP? No. No you do not.

  • Quote

Post by captwiggum » Thu Jul 26, 2007 1:23 am

No you do not NEED swap.

I have a 2GB notebook and have never setup swap and never needed it. I have a lot of apps open and running at once, and have never approached the limit of my 2GB RAM. I see a lot of swap lovers on this thread, and that's cool, but let me offer another perspective.

1. If you're using more the 2GB then something maybe wrong.
2. If you do use up 2GB, you may well use up the additional swap also.
3. If you use encrypted partitions, swap is a pain and a general security concern.
4. Many programs will reserve swap space if it exists, even it if it is not needed.
5. Its one more disk operation to slow things down, to setup, and admin.

To me, with modern machines, swap is just not needed, its a security concern, and a bottle neck.

Hope you enjoy a different perspective. I say to each his own. Gentoo 4evR!
Last edited by captwiggum on Thu Jul 26, 2007 6:23 pm, edited 1 time in total.
Top
i92guboj
Bodhisattva
Bodhisattva
User avatar
Posts: 10315
Joined: Tue Nov 30, 2004 8:17 pm
Location: Córdoba (Spain)

Re: Do you really need SWAP? No. No you do not.

  • Quote

Post by i92guboj » Thu Jul 26, 2007 2:22 am

captwiggum wrote:No you do not NEED swap.

I have a 2GB notebook and have never setup swap and never needed it. I have a lot of apps open and running at once, and have never approached the limit of my 2GB RAM. I see a lot of swap lovers on this thread, and that's cool, but let me offer another perspective.
I prefer to think that we are the ones that likes to prevent, better than to cure.
1. If you're using more the 2GB then something maybe wrong.
The kernel will not swap only when the ram is full. It will swap whenever it feels like swapping would improve the usage or physical ram.

2. If you do use up 2GB, you may well use up the additional swap also.
I don't understand that.
3. If you use encrypted partitions, swap is a pain and a general security concern.
True, a very particular case. By the way, if we speak about performance, the supposed performance hit that you say when you talk about the swap, is nothing at all compared to the performance hit you get with encryption. My personal opinion is that using a swap partition gives you no performance hit at all. That is, unless you fill your ram, in which case swapping is obligatory, and not something that the kernel does when iddle. But in that case, without a swap, you would get the greatest performance hit: some application (maybe with important unsaved data) will be killed.
4. Many programs will reserve swap space if it exists, even it if it is not needed.
I am no kernel guru, so, you might correct me if I am wrong. but, as far as I know, no program reserves swap. The memory administration is up to the kernel. A program just uses memory, but it doesn't need to know if that memory is into a ram stick, a swap device or a magic umbrella.
5. Its one more disk operation to slow things down, to setup, and admin.
It is not that easy, the same that "it is not that easy" to explain how the cache works, which is just the opposite of swapping (use physical ram to hold contents that should be read from a physical drive). If that categoric enunciation was true, believe, someone should have discovered in these last decades. And don't tell me that times have changed, cause, if it is true that memory sticks are bigger, it is also true that programs nowadays are much more memory hungry. Of course, if you use msdos in a core2 duo with 2 gb of ram, then you can assume you don't need swap. But that is another story.

Of course, this is just a respectful disagreement. Just some thoughts. I am by no means an expert in the subject.

Regards ;)
Top
Dralnu
Veteran
Veteran
User avatar
Posts: 1919
Joined: Wed May 24, 2006 5:33 pm

  • Quote

Post by Dralnu » Thu Jul 26, 2007 2:49 am

I'd throw in ~512M for swap just in case. You shouldn't need it, and if you don't ever use it, just merge it into another partition...
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
Top
no_hope
Guru
Guru
User avatar
Posts: 482
Joined: Mon Jun 23, 2003 8:50 pm

  • Quote

Post by no_hope » Thu Jul 26, 2007 4:11 pm

Having a decently-sized swap partition made my life easier a lot of time, though not as another level of memory hierarchy.

Having a few gigs in an unused partition can be really handy if you mess with your system a lot and like to experiment.

1GB boot partition with noauto also was a very good decision.
Top
FastTurtle
Guru
Guru
Posts: 547
Joined: Tue Sep 03, 2002 4:01 pm
Location: Flakey Shake & Bake Caliornia, USA

  • Quote

Post by FastTurtle » Thu Jul 26, 2007 7:24 pm

My experience w/o a swap partition extended over a 2 year period. System was an XP1800 with 1GB of main memory and to tell the truth, I decided to forgo a swap partition entirely. Never saw a need for it and the kernel is much better at killing offending processes then you or I ever could be and yes I had the kernel kill an app occaisionally when it started mis-behaving.

Now in regards to the battery life arguments for/against a swap partition on a laptop, they don't apply because the default configuration of the ext2/3 file system flushes all pending disk writes (cached buffers) every 5 seconds to disk. In otherwords, the disk never gets the chance to spin down so it can't save power.

You can change this setting but at significantly increased risk of system integrity by the system getting out of sync between cached buffers and the actual file system structure. For those who feel some swap is necessary and have over 1GB of memory, remember the 2.4 kernel could only use 256 Meg chunks and the 2.2 only needed 128 megs at the most so I'd suggest adding 128 megs for swap and setting it very low on the usage. This means it's then if ever needed but should never be touched.
AsRock Rack Rome8-2t
AMD Epyc 7282 CPU
192GB of ECC memory
Top
Dralnu
Veteran
Veteran
User avatar
Posts: 1919
Joined: Wed May 24, 2006 5:33 pm

  • Quote

Post by Dralnu » Thu Jul 26, 2007 8:58 pm

[stupid_question]How again do you set how much swap will be used? I don't remember seeing that mentioned anywhere...[/stupid_question]
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
Top
broken_chaos
Guru
Guru
Posts: 370
Joined: Wed Jan 18, 2006 7:47 am
Location: Ontario, Canada

  • Quote

Post by broken_chaos » Thu Jul 26, 2007 9:32 pm

Dralnu wrote:[stupid_question]How again do you set how much swap will be used? I don't remember seeing that mentioned anywhere...[/stupid_question]
By changing the size of the swap partition... There's no way to limit how much swap space is going to be used other than that. The sysctl property vm.swappiness is an integer (0-100) that controls *how easily* the kernel will "want" to swap things out vs. freeing cached memory, but there's no way that I know of to change how much space is allowed to be used, other than resizing the swap space itself.
Top
Dralnu
Veteran
Veteran
User avatar
Posts: 1919
Joined: Wed May 24, 2006 5:33 pm

  • Quote

Post by Dralnu » Fri Jul 27, 2007 4:26 am

broken_chaos wrote:
Dralnu wrote:[stupid_question]How again do you set how much swap will be used? I don't remember seeing that mentioned anywhere...[/stupid_question]
By changing the size of the swap partition... There's no way to limit how much swap space is going to be used other than that. The sysctl property vm.swappiness is an integer (0-100) that controls *how easily* the kernel will "want" to swap things out vs. freeing cached memory, but there's no way that I know of to change how much space is allowed to be used, other than resizing the swap space itself.
I wasn't refering to the partition size, but whether it would want to just free cached mem or use swap.
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
Top
madisonicus
Veteran
Veteran
User avatar
Posts: 1130
Joined: Wed Sep 20, 2006 9:31 pm

  • Quote

Post by madisonicus » Sun Sep 30, 2007 12:18 am

Dralnu wrote:
broken_chaos wrote:
Dralnu wrote:[stupid_question]How again do you set how much swap will be used? I don't remember seeing that mentioned anywhere...[/stupid_question]
By changing the size of the swap partition... There's no way to limit how much swap space is going to be used other than that. The sysctl property vm.swappiness is an integer (0-100) that controls *how easily* the kernel will "want" to swap things out vs. freeing cached memory, but there's no way that I know of to change how much space is allowed to be used, other than resizing the swap space itself.
I wasn't refering to the partition size, but whether it would want to just free cached mem or use swap.
Info on "swappiness" here.

HTH,
m
Please add [SOLVED] to your message title if you feel that your question has been answered.
------
Intel Q9300 Core2 Quad * Gigabyte GA-EP35C-DS3R
Samsung x360
AMD64 x2 4200+ * TF7050-M2 * HTPC
ZOTAC ION A-U Mini-ITX * HTPC
Top
Post Reply

24 posts • Page 1 of 1

Return to “Other Things Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic