Linux - NewbieThis 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
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.
Hi, i am going to install archlinux on my new laptop.
I have a simple question about swap choice:
waht is better, swap file or swap partition?
I think to use ext2 file system or, may be, reiserfs, also whether i think journaling is not so necessary on laptop.
Edit: Rereading what I wrote below, I realized it might imply I think there could be a big difference between swap file and partition. But whichever is better is not a lot better. The room for debate is in whether there is a small advantage to swap partition vs. the difference is completely insignificant.
Experts, who ought to know, say those are equal. I'm not convinced. A swap partition ought to be better than a swap file, but I haven't looked at the relevant source code to see if that is really true.
Another factor to consider is your plan for someday replacing this Linux install with a newer version and/or different distribution:
The way I have replaced Linux installs is to shrink the partition of the installed Linux enough to install the next one in unpartitioned space. Then boot back and forth between the two while copying files and settings and comparison testing that everything I depended on in the old install is working in the new. Finally delete the old partition and grow the new one.
That sequence is a bit faster and easier when the swap space is a separate partition usable by either Linux install, as compared to separate file inside the two partitions that are shrinking and growing in the above process.
Some Linux distros can do rolling updates across major version changes, in which case you don't need to worry about any of the above. But I haven't ever been able to use rolling updates across major version.
thanks johnsfine, about update/or reinstall new distro, for me, this is not a problem, usually, i use only one and update only packages that are my interest. I do not know how archlinux works and updates itself but i think to make this without remake partition and reinstall allthing.
About swap file or swap partition, for my experience, i have used them and i think there is not difference between them. A little problem can make the swap partition if you are intention to upgrade RAM and to change the swap space. If you use a file is more easy, more fast and more sure to adjust its size. I usually make it at the same (or double) size of RAM. If i increase RAM, must to increase swap size, too.
For me is more better swap file; if anyone want to change my opinion, he is welcome.
About file system, no more better that reiserfs i have used in my life. ext2 can be a good choice on laptop to reduce the continuous access on hd and preserve power, just to consider the main sense of journaling the consequences of the elettrical blackout (there is a battery to avoid it!)
I usually make it at the same (or double) size of RAM. If i increase RAM, must to increase swap size, too.
This is an ancient rule of thumb that has no worth nowadays. In my eyes it is even illogical, why should you need more swap space when you upgrade the RAM, so that it is more likely that you will NOT use swap. Of course it depends on the workload for your system, but I think that 1GB of swap is more than sufficient on a typical desktop system. You will only need the amount of physical RAM as swap space if you plan to use hibernation.
This is an ancient rule of thumb that has no worth nowadays. In my eyes it is even illogical, why should you need more swap space when you upgrade the RAM, so that it is more likely that you will NOT use swap. Of course it depends on the workload for your system, but I think that 1GB of swap is more than sufficient on a typical desktop system. You will only need the amount of physical RAM as swap space if you plan to use hibernation.
It is not so simple as you wrote. The kernel use the swap independently by ram size and by its workload. If it is true what you say, it is useless in most cases, example in a minimal desktop system with 512mb or 1gb of ram. Try to use any linux system without swap, and tell us about. The size of swap is also important and the use that make the kernel is dependent by its size. Usually is good think to make it at the double ram size; if your space are insufficient, you can make it at the same ram size.
The swap is important and essential such as it is important its size and from its size depend the utilization that the kernel make of it. The total memory (ram+swap) on a linux system must be properly balanced.
Try to use any linux system without swap, and tell us about.
Not a problem at all, already did that, works, many other people are doing it.
Quote:
The kernel use the swap independently by ram size and by its workload.
Not true. If the kernel runs out of physical memory because the workload demands more RAM than is there the kernel has to use swap, so the usage of swap is dependent on the amount of RAM and the workload.
Quote:
If it is true what you say, it is useless in most cases,
Actually it is. My fileserver (CLI only, so fairly minimal) has 1 GB of physical RAM and 1GB of swap, and is actually never using swap. I just put it there as for safety, because when I build the server I was not sure which services I will implement and how the workload would be.
Quote:
Usually is good think to make it at the double ram size; if your space are insufficient, you can make it at the same ram size.
Any proof for that claim? I don't see any logic in that. Why should I use a 16GB swap partition on my main system with 8GB of RAM? If I ever need that amount of swap then my system is clearly not proper designed to run its workload and will see severe performance impacts. Better to upgrade the RAM, then.
Quote:
The swap is important
I agree.
Quote:
and essential
I disagree. When swap would be essential the system wouldn't run without it. It definitely does.
Quote:
The total memory (ram+swap) on a linux system must be properly balanced.
I agree with Tobi. My system at home has 12GB of RAM and the swap goes untouched. I set it for 13GB based on the conventional wisdom that this is the thing to do but in retrospect it does feel like a waste of space (mine is a desktop system which I never sleep/hibernate). I have so much hdd space that it doesn't matter in the end but it is still a mild waste.
As Tobi already stated this 'conventional wisdom' was spawned at a time when 256MB would've been a lot or RAM.
if you are intention to upgrade RAM and to change the swap space. If you use a file is more easy, more fast and more sure to adjust its size. I usually make it at the same (or double) size of RAM. If i increase RAM, must to increase swap size, too.
As others already explained, the swap size should depend on the workload and not on the ram size. If you increase ram size without changing workload, that decreases the required swap size.
If you significantly increase workload (without an equal increase in ram size) then you need more swap. Adding swap to a live system is obviously easier by adding a swap file, rather than changing or adding a swap partition. If/When that is needed, the original choice of partition vs. file won't be relevant. You can have a swap partition now and add a swap file later and you will then be able to use the total of partition plus file.
Most Linux systems do not need any swap. Such systems can often make good use of a little swap, even though lacking that swap would not cause failures. Most systems, especially those with important unattended operations, ought to have a "large" safety margin of swap that is never expected to be used. But that still leaves "large" undefined and dependent only on workload and not on ram size.
For most Linux systems, regardless of ram size, 2GB of never used swap is a "large" safety margin.
You have heard (as one would expect) mostly from people whose Linux systems are or would be fine with 2GB or less swap. I'll describe what I think is a counter example:
This morning I was discussing swap size for a new Linux system with the IT guy in my office. The system has 12 cores and 32GB of ram. It will be used for several different activities that will run at disjoint times of day/week. Each of the larger activities might nearly fill ram when run. If we keep activities non overlapping in time as intended, we'll never use more than 50MB of swap, so swap space in GB would be always unused. But what if we mess up and accidentally overlap things that shouldn't. We then would much rather these things slow down rather than crash (note that is specific to our goals. In many servers slowing down that much would be as bad as crashing). That could pull in even more overlap (remember all this is mostly unattended) and suddenly we could be using over 32GB of swap. All that is quite unlikely, but possible. The system has a 1.5TB RAID, which is more than is really needed. Bottom line, 64GB swap looks like a massive waste, very likely to never get even half used. But 64GB more free disk space for files is also unlikely to make a difference. The insurance value of the absurd swap space is more significant than the waste.
I hope I've given you some idea of how much this kind of decision ought to depend on how you use the computer. What are the chances you'll need more swap? What is the harm done after conditions change to require more swap but before your opportunity to fix it?
i am sure as well as i have wrote. Some applications do not works well without swap, especially continuos resident in memory (even though they are small: example: torsmo, and others "small" demons and applications); usually a swap is essential. The rule that i wrote is right but up to 1 gb swap. My experience is especially with kernel 2.4, no often i have used 2.6.
Making always swap at the same or double ram size, never, (and i repeat, never) i had problems. In the other cases, with some application, yes.
However, i have made a question, no more i want to know, if it is better a swap file o swap partition.
Last edited by zemir; 08-18-2011 at 02:50 PM.
Reason: error tiping
From a software point of view with the 2.6 Linux kernel, swap files are just as fast as swap partitions. The kernel keeps a map of where the swap file exists, and accesses the disk directly, bypassing caching and filesystem overhead. Red Hat recommends using a swap partition. With a swap partition one can choose where on the disk it resides and place it where the disk throughput is highest. The administrative flexibility of swap files can outweigh the other advantages of swap partitions.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.