LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware
User Name
Password
Linux - Hardware This forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?

Notices


Reply
  Search this Thread
Old 12-14-2004, 10:34 AM   #1
Mojojo
Member
 
Registered: May 2003
Location: Philadelphia/PA
Distribution: Arch
Posts: 452

Rep: Reputation: 35
Swap partition


Ok can anyone tell me what the hell a swap partition is. Is it a waste of hard drive space or what. As long as I have been using linux I have wondered why I have to set u a swap partition. It doesn't seem to use it anyway does this mean I could just make a 100mb swap. And things would be alright. I'm sure I'll probably get some sh*t for this question but I had to ask. My swap is 800mb on a 100mb harddrive which I can live with for now.
 
Old 12-14-2004, 12:33 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,994

Rep: Reputation: 76
I'd check that; your swap is 8 times larger than your hard disk.

Basically, a swap partition is place where your kernel can store infrequently-used data from RAM onto your hard disk. The main reason for this is to increase the effective size of your RAM by 800Mb so that you can run more memory-intensive programs.

In doing this, it can free up more RAM for use as a hardware cache (2.6 series kernels do both read and write caching on all mounted block devices unless they use the sync option), which speeds up disk access as well. Search for the term “swappiness” for more information on this.

There's normally no significant performance penalty to using swap space, as swapping and unswapping can be done by DMA while a different process is running. Hard disks are also a lot cheaper than RAM per unit space, so it's a more economic way of setting up your system.

Linux will run fine without a swap partition; you'll just run out of memory much more easily. Also, all modern OSes use some form of swapping (Windows uses a swap file; Linux can too if you feel so inclined, although a swap partition is marginally cheaper).

Hope that helps explain it,

—Robert J. Lee
 
Old 12-14-2004, 01:15 PM   #3
Zuggy
Member
 
Registered: Mar 2004
Location: Pocatello, Idaho, USA
Distribution: Ubuntu
Posts: 256

Rep: Reputation: 30
Quote:
Originally posted by rjlee
There's normally no significant performance penalty to using swap space, as swapping and unswapping can be done by DMA while a different process is running. Hard disks are also a lot cheaper than RAM per unit space, so it's a more economic way of setting up your system.

Linux will run fine without a swap partition; you'll just run out of memory much more easily. Also, all modern OSes use some form of swapping (Windows uses a swap file; Linux can too if you feel so inclined, although a swap partition is marginally cheaper).

Hope that helps explain it,

—Robert J. Lee
A couple corrections and clarification

If your machine only has a 800MB, chances are your going to need a SWAP partition. I forgot to put one on my vector laptop the first time I installed it and it crashed whenever I ran a program.

There is a performance hit to using a SWAP space. Actual RAM is much faster. That's why in Windows or Linux or any OS for that matter, you see a perfomance boost by adding RAM. If SWAP was the same speed as RAM you'd only have to have enough RAM for the Hard Drive to initialize and you'd have enough to run even the bloat of Windows XP (or some of the bigger Linux distros).

A SWAP partition is an essential part of any OS. I once heard, to run windows XP without Swap, you need atleast 2.5 GB RAM. I can't imagine that linux is much different. So a general rule of thumb for swap partitions is that it should equal double your RAM. 32mb ram=64 mb swap, 64mb ram=128 mb swap. It goes on like this until you reach 2 Gigbytes of SWAP. I think anything bigger then a 2 Gig swap partition can't be used under Linux.
 
Old 12-14-2004, 01:24 PM   #4
nycace36
Member
 
Registered: Feb 2004
Location: SFBayArea, CA
Distribution: Debian-based, Slackware 10x+
Posts: 185

Rep: Reputation: 22
Follow-up question:

Quote:
There's normally no significant performance penalty to using swap space, as swapping and unswapping can be done by DMA while a different process is running.
How about the "need" for a swap partition on a file server serving 20-30 users, e.g. a RAID'ed system of 400-600GB SCSI hdd's with 2GB+ RAM ?? Having any "swappiness" from RAM through the SCSI controller to hdd array just adds to the local bottleneck on top of the system board's CPU+FSbus+LAN throughput!!
 
Old 12-14-2004, 02:23 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 24,998

Rep: Reputation: 5683Reputation: 5683Reputation: 5683Reputation: 5683Reputation: 5683Reputation: 5683Reputation: 5683Reputation: 5683Reputation: 5683Reputation: 5683Reputation: 5683
swap is the same as virtual memory in windows. It swaps out data and applications from RAM to hard drive. How much swap will depend on the applications and what you use the PC for. With most systems these days having lots of RAM the 2x rule is obsolete. For the average user 512MB is more then enough IMO. linux memory management is much better then windows. Look at the output of the free command. You will see that most of your memory is used for buffers and cache.
 
Old 12-14-2004, 02:50 PM   #6
J.W.
LQ Veteran
 
Registered: Mar 2003
Location: Boise, ID
Distribution: Mint
Posts: 6,642

Rep: Reputation: 87
Opinions on whether or not you need swap are pretty much similar to opinions on how a hard drive should be partitioned but here's my view:

In Linux, swap was important when having 64Mg of RAM was leading edge. These days, on a modern PC with, say, at least 512Mg of RAM, I would say swap is basically a legacy holdover without any real functional value.

Note that the only time swap even comes into play is if your apps push RAM beyond its capacity, and the system is forced to write out memory pages to disk. With tiny amounts of RAM, that was not uncommon, but with significant amounts of RAM, it's far less likely, and may not even happen at all. I would recommend that you take a look at how much swap space your system is currently using and make any future allocation decisions based on it. (My bet would be that you aren't using it, or worst case the usage is minimal.)

Furthermore, keep in mind that anytime your system is using swap space, performance will be negatively impacted -- access times within RAM are measured in nanoseconds, while access times from a hard drive are measured in milliseconds. In other words, the less swap is used, the better. From a theoretical standpoint, I agree the descriptions of swap already posted are accurate, but at least in my experience, in actual practice swap is seldom used so long as the machine is equipped with a respectable amount of RAM.

My suggestion would be that if you've got at least 512Mg of RAM, create a small (256Mg max) swap space just to play it safe, but allocating more is probably going to end up being a waste of disk space. While the "swap = twice RAM" rule was necessary and important in the past, I consider it much less relevant today than in the past.

As I've indicated, different people have different views on swap, and people may agree to disagree, but the best recommendation I think would be to monitor your own swap usage during periods where your users are heavily loading the system. If you see virtually all your swap space in use, you'll know you need it, but if you instead see that the swap is pretty much untouched, you'll know that you don't really need it. If you've got 2G of RAM, my bet would be on the latter.

As usual, the above is just my view of things, others may disagree -- J.W.
 
Old 12-14-2004, 03:27 PM   #7
nycace36
Member
 
Registered: Feb 2004
Location: SFBayArea, CA
Distribution: Debian-based, Slackware 10x+
Posts: 185

Rep: Reputation: 22
Hmmm... ibiblio hosting of tldp seems to be down now (http://www.tldp.org), so cannot check reply info pieces on swap partitions through tldp's FAQs and HOWTOs.

Did see another LQ thread at http://www.linuxquestions.org/questi...eSD+Linux+swap
here addressing the multi-use of the same swap partition between Linux w/ FreeBSD.
 
Old 12-14-2004, 05:49 PM   #8
Electro
LQ Guru
 
Registered: Jan 2002
Posts: 6,042

Rep: Reputation: Disabled
If you need more swap, you can always create it later with a file. If you need swap to write and read faster, state the swap partition same priority and make sure the swap partition are on two or more seperate drives. Below is what I have
Code:
/dev/hde1       swap    swap    pri=5   0       0
/dev/hdg1       swap    swap    pri=5   0       0
/dev/hda5       swap    swap    pri=4   0       0
The Linux kernel will array the swap partitions to turn them into a RAID 0 device. Now swap can write and read 30 to 60 MB/sec instead of 15 to 30 MB/sec. Also the last swap partition is there just in case two partitions got corrupted or does not mount successfully.

Swap puts a huge penalty, so plan wisely. If you do not think swap has a huge penalty, try placing the swap partition on the end of the drive. You will experience what I mean.
 
Old 01-20-2005, 03:04 PM   #9
ManDude
LQ Newbie
 
Registered: Jan 2005
Posts: 1

Rep: Reputation: 0
Swap file add for slack10

A friend of mine helped me out when I was having issues with Slack10 crashing 'cause it was running out of RAM.

I hadn't set a swap partitian or file and really didn't want to go back and reinstall the whole system. So this is what I did to add a swap file and it help out a lot. No more filling up memory and crashing of the box.
---

* Create a 1GB swap file with dd if=/dev/zero of=swapfile bs=1024 count=1M.
* Creating a new swap partition requires use of fdisk, but this should be used with care on disks already in use.
* Use /sbin/mkswap -c swapfile to "format" the new swap file. Similarly for a new swap partition.
* Set swap file ownership and permissions chown root.root swapfile; chmod 0600 swapfile.
* Add each new swap space entry to /etc/fstab. Eg. swapfile swap swap defaults 0 0.
* Enable the new swapspace(s) with /sbin/swapon -a.
---

This worked very well for me. I hope this info can help soem of you if you need to add swap with wiping the box or taking a risk of screwing things up in a mistake with 'fdisk'.

Also, my friend said that this site is good for helping deal with swap space on Linux.
http://dev.panopticsearch.com/swapfile-notes.html

Enjoy!
 
Old 01-20-2005, 03:23 PM   #10
Mojojo
Member
 
Registered: May 2003
Location: Philadelphia/PA
Distribution: Arch
Posts: 452

Original Poster
Rep: Reputation: 35
I should note that I currently use 1mb of swap with a 3.0ghz box, 512mb of memory and 100gb hardrive. My swap is 800mb. I'm not having any problems with this setup. My swap is sandwiched between a / and home partition. But even under extrem load I never touch more than 1mb of swap.So would this mean next time I setup a hardrive instead of 800mb I could survive on say 5mb?
 
Old 01-20-2005, 06:12 PM   #11
J.W.
LQ Veteran
 
Registered: Mar 2003
Location: Boise, ID
Distribution: Mint
Posts: 6,642

Rep: Reputation: 87
Almost certainly Yes. If you actively monitor your actual swap usage and you determine that even under the heaviest loads in never goes above "X" amount, then there's no real benefit to creating a space bigger than that (because it quite simply will not be used)

Personally, these days I'd suggest always going with a 256Mg swap partition regardless of the amount of RAM you have. That's large enough to be helpful in the rare event that swap is actually needed, but it's small enough to not affect the amount of usable storage capacity on a modern hard drive.

This is strictly my 2 cents; as I mentioned previously decisions about swap are much like decisions on partitioning schemes - each person is likely to have his/her own ideas about what is best -- J.W.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Do I NEED a swap partition priller Linux - Newbie 4 06-02-2004 11:23 AM
Newbie Installing Debian3 on m68k w/250M Partition Needs help creating swap partition AppleMac Linux - Newbie 2 11-01-2002 09:45 AM
Should I be using a SWAP partition? Gene126 Linux - General 3 08-14-2002 10:03 PM
swap.partition anoop_chandran Linux - General 3 12-28-2001 10:48 AM
Swap partition Thomas_Delrue Linux - Newbie 3 07-12-2001 09:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Hardware

All times are GMT -5. The time now is 08:42 AM.

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