Linux - HardwareThis forum is for Hardware issues.
Having trouble installing a piece of hardware? Want to know if that peripheral is compatible with Linux?
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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).
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.
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!!
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.
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.
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.
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
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.
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'.
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?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.