LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 08-18-2011, 04:41 AM   #1
zemir
LQ Newbie
 
Registered: Jul 2011
Location: Calabria, ITALY
Distribution: debian squeeze
Posts: 24

Rep: Reputation: Disabled
swap file or swap partition? What is better?


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.
 
Old 08-18-2011, 05:12 AM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,832

Rep: Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820Reputation: 1820
Did you bother to search the swap question ?. Have a look at the bottom of this page for similar thread - there will be plenty.

Use a modern filesystem - neither of those qualify. Why do you think journalling is "not so necessary on laptop" ?
 
1 members found this post helpful.
Old 08-18-2011, 08:26 AM   #3
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by zemir View Post
waht is better, swap file or swap partition?
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.

Last edited by johnsfine; 08-18-2011 at 09:58 AM.
 
1 members found this post helpful.
Old 08-18-2011, 09:41 AM   #4
theKbStockpiler
Member
 
Registered: Sep 2009
Location: Central New York
Distribution: Fedora14,Scientific 6.1?, Mandriva 2010 ;GO MAGEIA!!!Next up Gentoo
Posts: 838

Rep: Reputation: 51
If given the choice a partition is preferred.

Some how a partition is faster. If you have to use a file I doubt you will notice the difference though.
 
1 members found this post helpful.
Old 08-18-2011, 10:05 AM   #5
zemir
LQ Newbie
 
Registered: Jul 2011
Location: Calabria, ITALY
Distribution: debian squeeze
Posts: 24

Original Poster
Rep: Reputation: Disabled
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!)
 
Old 08-18-2011, 10:13 AM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
Quote:
Originally Posted by zemir View Post
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.
 
Old 08-18-2011, 11:04 AM   #7
zemir
LQ Newbie
 
Registered: Jul 2011
Location: Calabria, ITALY
Distribution: debian squeeze
Posts: 24

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TobiSGD View Post
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.
 
Old 08-18-2011, 11:14 AM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
Quote:
Originally Posted by zemir View Post
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.
Again, any proof for that?

Last edited by TobiSGD; 08-18-2011 at 11:19 AM.
 
Old 08-18-2011, 12:09 PM   #9
gleemer
LQ Newbie
 
Registered: Aug 2011
Posts: 3

Rep: Reputation: Disabled
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.
 
Old 08-18-2011, 01:11 PM   #10
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181Reputation: 1181
Quote:
Originally Posted by zemir View Post
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?

Last edited by johnsfine; 08-18-2011 at 01:36 PM.
 
Old 08-18-2011, 01:23 PM   #11
PrinceCruise
Member
 
Registered: Aug 2009
Location: /Universe/Earth/India/Pune
Distribution: Slackware64 -Current
Posts: 889

Rep: Reputation: 182Reputation: 182
Quote:
Originally Posted by zemir View Post
example in a minimal desktop system with 512mb or 1gb of ram. Try to use any linux system without swap, and tell us about.
Were you sure before writing so quickly?

There is no problem whatsoever using your Linux box without swap. Done that, doing that. Now what?
 
Old 08-18-2011, 03:25 PM   #12
zemir
LQ Newbie
 
Registered: Jul 2011
Location: Calabria, ITALY
Distribution: debian squeeze
Posts: 24

Original Poster
Rep: Reputation: Disabled
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 03:50 PM. Reason: error tiping
 
Old 08-18-2011, 03:45 PM   #13
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
Quote:
Originally Posted by zemir View Post
However, i have made a question, no more i want to know, if it is better a swap file o swap partition.
Quote from the http://en.wikipedia.org/wiki/Paging#LinuxWikipedia article about Linux paging:
Quote:
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.
 
1 members found this post helpful.
Old 08-18-2011, 04:03 PM   #14
PrinceCruise
Member
 
Registered: Aug 2009
Location: /Universe/Earth/India/Pune
Distribution: Slackware64 -Current
Posts: 889

Rep: Reputation: 182Reputation: 182
Okay, answer to the question is swap partition is considered better. reason mentioned above by gurus
 
Old 08-18-2011, 04:09 PM   #15
zemir
LQ Newbie
 
Registered: Jul 2011
Location: Calabria, ITALY
Distribution: debian squeeze
Posts: 24

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TobiSGD View Post
Quote from the http://en.wikipedia.org/wiki/Paging#LinuxWikipedia article about Linux paging:
Thanks TobiSGD, you are great! This feature of the new (for me) 2.6 kernel is very good........Thanks again!
 
  


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
swap file vs. swap partition verndog Ubuntu 16 07-09-2012 09:49 PM
Can swap file or a swap partition be mounted and read? Mr-Bisquit Linux - General 3 06-08-2009 03:16 PM
Hard Drive Partition Management - Mandriva Double Partition with Swap File partition moshebagelfresser Linux - Hardware 2 05-23-2008 11:46 AM
Swap Partition vs File Philips Linux - General 12 07-04-2006 10:00 PM
Need Help Increasing Swap by creating a swap file froggo Red Hat 3 06-13-2006 09:04 AM


All times are GMT -5. The time now is 03:07 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration