LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-15-2008, 08:31 AM   #1
simonb1975uk
Member
 
Registered: Jan 2004
Location: In the county of Essex, UK
Posts: 72

Rep: Reputation: 15
swap file or swap space?


A question to the more enlightened than I. I know you can create swap space under Linux, I also know you can create a swap file. However in terms of performance is there an advantage to using swap space or a swap file, or is there no advantage at all? Just curious really.

Simon
 
Old 08-15-2008, 08:56 AM   #2
vharishankar
Senior Member
 
Registered: Dec 2003
Posts: 3,142
Blog Entries: 4

Rep: Reputation: 121Reputation: 121
Most modern desktop systems have so much physical memory that I hardly notice any swap usage anyway. I would guess the exclusive swap partition would be a better approach as it's a fixed location on the hard disk.
 
Old 08-15-2008, 09:00 AM   #3
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,401

Rep: Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119Reputation: 1119
It's really up to you. Swap space is used very little these days. If you're just running a single disk-drive it really makes very little difference how you configure it.

Linux is probably the only system left that commonly uses swap-partitions. Both Windows and OS/X use swap-files.

Most computers these days have so much RAM ("chips are cheap") that swapping doesn't happen much. It's not nearly as critical as it used to be.
 
Old 08-15-2008, 09:24 AM   #4
rahulk
Member
 
Registered: Mar 2006
Posts: 110

Rep: Reputation: 16
As qouted already by senior memebers in this thread. Swap space is not much used these days unless its a Oracle database box. If you want to really speed up the things, I would suggest you to use /dev/shm for your programs.. this can give you blitzering speed since shm is an interfacing shared memory segment device to RAM. Hence any transaction, like temporary file generation etc...on this tmpfs filesystem can greatly improve performance without affecting the CPU time at all. It also removes the I/O calls to hard-drive which in comparison to RAM is much slower.

Best Regards,
Rahul.
 
Old 08-15-2008, 10:30 AM   #5
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
If you are looking at doing hibernation kinds of things you'll want a swap partition intead of a swap file, otherwise 6 in one hand, half a dozen in the other.
 
Old 08-15-2008, 12:28 PM   #6
rob.rice
Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 792

Rep: Reputation: 114Reputation: 114
It's still best to have some swap

if for nothing else it gives you the option of using suspend to disk
(if it ever gets working right)

not only do newer systems have larger RAMs but they have larger HDDs
so it's not that much of a sacrifice to give up 2x the size of your
ram for swap partition (on the outside tracks of your HDD)

this is a case where it's better to have it and not need it
than it is to need it and not have it

it's also not easy to go back and get it if you didn't start out with it

Last edited by rob.rice; 08-15-2008 at 01:46 PM.
 
Old 08-15-2008, 01:24 PM   #7
jailbait
Guru
 
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,554

Rep: Reputation: 182Reputation: 182
Swap will run faster if it is contiguous. If you create a swap partition then it will be contiguous. If you create a swap file it might be fragmented. So I recommend that you use a swap partition, not a swap file.

---------------------
Steve Stites
 
Old 08-15-2008, 01:50 PM   #8
rob.rice
Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 792

Rep: Reputation: 114Reputation: 114
on the outside tracks of the hard drive
this is much faster than on the innermost tracks
witch is where most swap partitions end up being put
 
Old 08-15-2008, 02:01 PM   #9
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,245

Rep: Reputation: 121Reputation: 121
Quote:
Originally Posted by rob.rice View Post
on the outside tracks of the hard drive
this is much faster than on the innermost tracks
witch is where most swap partitions end up being put
I thought it was already established that swap is mostly used for suspend (if it ever gets working) these days. So, why would swap need to be on the faster portion? Seriously, if you're swapping, you probably need to spend a couple bucks on more memory. It's cheap and fast.

NOTE: Large commercial servers may have different swap system needs than home desktops/servers.
 
Old 08-15-2008, 02:18 PM   #10
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,107

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
If you need to use it much, would it be more important for it to be on outside tracks that are faster (and for it to be simple/contiguous as a partition), or for it to be near the files you are accessing when you need it, to cut down seek time? I don't know.

Obviously, a partition on a different hard drive than the files you would be accessing is even better. But normally that's not an option.

If you won't be accessing it much, wouldn't it be best to be a partition on the innermost tracks (highest logical numbers) to get it out of the way.

I never really understood the Linux "over commit" logic. But I expect sometimes Linux doesn't over commit enough. That may be an extra reason for a generous amount of swap space, even if it won't actually get used. Simple case: A big chunk of memory is allocated "copy on write". Linux requires some fraction of the total be available in either physical memory or swap space in order to permit the allocation. In fact (for my example) a much smaller fraction will actually get written and need physical space. With a big swap space, the operation succeeds and the swap space is never used. Without the big swap space the same operation fails.

I've seen that sort of failure (an operation needs a lot of swap space to avoid failing even though it never actually uses the swap space) fairly often in Windows, not Linux. But that may be because the things I've done in Windows are more likely (vs. the things I've done in Linux) to trigger that flaw, rather than just because the Linux need for swap space (as a consequence of imperfect memory management) isn't as stupid as Windows.
 
Old 08-15-2008, 02:30 PM   #11
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,245

Rep: Reputation: 121Reputation: 121
Here's something else to consider: http://kerneltrap.org/node/3000
 
Old 08-15-2008, 02:39 PM   #12
rob.rice
Member
 
Registered: Apr 2004
Distribution: slack what ever
Posts: 792

Rep: Reputation: 114Reputation: 114
Quote:
Originally Posted by Quakeboy02 View Post
I thought it was already established that swap is mostly used for suspend (if it ever gets working) these days. So, why would swap need to be on the faster portion? Seriously, if you're swapping, you probably need to spend a couple bucks on more memory. It's cheap and fast.

NOTE: Large commercial servers may have different swap system needs than home desktops/servers.
you would want the fastest suspend to disk and resume from hibernation that you can get
the out side tracks read and write much faster the data moves under the heads faster and the tracke are larger

hard drive controllers work on just one drive at a time so for another hard drive to help you would need anther and another controller

even with 2Gigs of ram doing silly things like running 2 or 3 X servers each with KDE at once will dip into swap

I some times do this showing off linux to windoze geeks
(at times like this the last thing I want is for the system to thrash around looking for swap space)

my laptop is maxed out on the amount of ram that can be plunged in
so pugging in more ram isn't always an option

Last edited by rob.rice; 08-15-2008 at 04:55 PM.
 
  


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
swap space (or) swap file yusufs Linux - Newbie 8 07-17-2008 02:02 AM
how much swap space is needed; how to increase swap space? johnpaulodonnell Linux - Newbie 5 03-23-2007 03:20 AM
Redistribute Swap file space to main partition stuartornum Suse/Novell 11 10-30-2006 03:49 PM
Need Help Increasing Swap by creating a swap file froggo Red Hat 3 06-13-2006 08:04 AM
How to unmount actual swap and mount a new(bigger) swap space? isaac Linux - Newbie 1 06-06-2004 01:23 AM


All times are GMT -5. The time now is 07:35 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration