LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices

Reply
 
Search this Thread
Old 05-08-2008, 02:40 AM   #1
verndog
Member
 
Registered: Oct 2007
Posts: 107

Rep: Reputation: 18
swap file vs. swap partition


I ran across the idea of making a swap file in place of a swap partition.
Anyone have experience using swap file? Any pros or cons for either?

Here is some links on the subject:
SwapFile1

SwapFile2
 
Old 05-08-2008, 02:49 AM   #2
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
Been asked before:
http://www.linuxquestions.org/questi...s-file-461020/

No subjective difference. If you have two drives, you can get a performance increase by putting your swap partition on a different drive to root. In general, partitions are faster than files. However, 21st century computers are so fast anyway...

(if you care so much about speed - do without swap altogether and run at least 1024MiB RAM.)
 
Old 05-08-2008, 03:47 AM   #3
UndiFineD
LQ Newbie
 
Registered: Jun 2004
Location: Netherlands
Distribution: adistro
Posts: 24

Rep: Reputation: 0
And what about suspend to disk ?

It uses the swap to store all memory contents.

If you need swap, sure place it at the lowest possible sectors and on a separate harddisk.

if you just use it for suspend and minor swap actions a swap file somewhere on your disk might be fine.


what is the future for swap with solid-state disks ?

mostly suspend actions, memory is relatively cheap.
so new systems should have few reasons to swap.
 
Old 05-08-2008, 05:54 AM   #4
Simon Bridge
Guru
 
Registered: Oct 2003
Location: Waiheke NZ
Distribution: Ubuntu
Posts: 9,211

Rep: Reputation: 197Reputation: 197
Quote:
And what about suspend to disk ?
Yep - if you care more about hibernate than speed, you want swap. If you want both - enable swap = RAM size and set swappiness to zero.

Quote:
If you need swap, sure place it at the lowest possible sectors and on a separate harddisk.
After the first swap - it won't be noticable. Single-disk setups often put swap in it's own extended partition.

There is usually quite a lot of debate about how best to use swap. Truth is, on modern systems the fine tuning is not noticeable without special equipment.
 
Old 05-09-2008, 02:12 AM   #5
verndog
Member
 
Registered: Oct 2007
Posts: 107

Original Poster
Rep: Reputation: 18
The reason I even brought this subject up was so that I could have only one partition instead of several that Linux likes to have. Windows typically has only one partition and cloning or imaging a system is easy. I wanted to do the same. I have learned through my ignorance that I don't need to back up the swap partition , and that I can easily recreate it.

I know a lot of thinking is that one should have '/home' as a separate partition, but if I image regularly what's the difference?
 
Old 05-09-2008, 06:06 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,666
Blog Entries: 54

Rep: Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952Reputation: 2952
While some distributions or users may automagically go for a "/" plus swap layout there's good reasons for having multiple partitions. Most of them are discussed in partitioning threads and we've got quite a few for you to read.
 
Old 07-09-2012, 05:13 PM   #7
UndiFineD
LQ Newbie
 
Registered: Jun 2004
Location: Netherlands
Distribution: adistro
Posts: 24

Rep: Reputation: 0
This is a fun thread to return to after all this time.
I used to have a swap partition around in case needed.

nowadays you have several options

the swap partition still works and is stable

but the use of swap files has become more popular too

and then there are those that dismiss the use of swap altogether


I use a swapfile, because I like to be able to suspend / hybernate
but I do not just use 1 swapfile, no I have 10 each 1 GiB in size
/mnt/lvmdisk/swap is only accessible by root
and the lvmdisk is a striped set of 2 disks
here is a small portion of my /etc/fstab

/dev/volgroup/lvmdisk /mnt/lvmdisk ext4 defaults 1 2

/mnt/lvmdisk/swap/swap0 none swap sw 0 3
/mnt/lvmdisk/swap/swap1 none swap sw 0 3
/mnt/lvmdisk/swap/swap2 none swap sw 0 3
/mnt/lvmdisk/swap/swap3 none swap sw 0 3
/mnt/lvmdisk/swap/swap4 none swap sw 0 3
/mnt/lvmdisk/swap/swap5 none swap sw 0 3
/mnt/lvmdisk/swap/swap6 none swap sw 0 3
/mnt/lvmdisk/swap/swap7 none swap sw 0 3
/mnt/lvmdisk/swap/swap8 none swap sw 0 3
/mnt/lvmdisk/swap/swap9 none swap sw 0 3


now I am not fully certain whether swap is up before suspend resumes
as I have not used that yet, but the logic is
having your swap files spread among 2 striped disks
should give some performance increase

As for those that turn off swap altogether
it gives the kernel lesser to do if the memory is full,
crash the program using the most.
which most often is the browser or some other memory hungry application.
 
Old 07-09-2012, 05:32 PM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,648
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
Quote:
Originally Posted by UndiFineD View Post
having your swap files spread among 2 striped disks
should give some performance increase
I don't know for sure with swap-files, but with swap partitions you will not get better performance with putting them on striped disks, for a simple reason. If you put two swap partitions on two non-striped disks the kernel will automatically handle them as a swap-RAID.
 
Old 07-09-2012, 05:43 PM   #9
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 3,541

Rep: Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804
Seeing as this thread is bumped and relevant I'll ask here:
If I set l a swap file on my root partition for hibernate (assuming my hardware will do it) how do I stop this from ever being used apart from for hibernating?
 
Old 07-09-2012, 05:53 PM   #10
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,648
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
Hibernating with a swap file is currently not supported, as far as I know. But even if it would be supported, what would be the point in not permitting the system to use that file for swapping?
 
Old 07-09-2012, 05:59 PM   #11
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 3,541

Rep: Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804
So I'd need a swap partition to hibernate?
I wouldn't want it to be used becuase of the admitedly small extra wear on an SSD. I've 6GB of RAM currently and even when not all of it is used I see some swapping, will the same algorithms mean I get swapping using 16GB of RAM? I've choices of where to put swap but since I won't use it I thought the SSD would give me a quicker wake, as long as hibernate works anyhow.

Last edited by 273; 07-09-2012 at 06:00 PM. Reason: typos on this glass
 
Old 07-09-2012, 06:08 PM   #12
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,648
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
The last time I searched information about that topic a partition was needed for hibernation, yes. But if you really don't want it to be used for swapping just don't add it to your fstab.

If you have a somewhat recent SSD the amount of wear that will be caused by a little swapping is next to zero. And yes, even on my 16GB workstation I see small amounts of swapping without using up the RAM, usually a few MB, nothing to worry about at all.
 
Old 07-09-2012, 06:19 PM   #13
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 3,541

Rep: Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804
Thanks Tobi, and I've seen your posts elsewhere about swap also.
I think I'll attempt to put my swap partition on whichever data drive I can spare space on. The SSD is too expensive, for now, to waste space on swap. This is all assuming that resume even works on my setup.
My conclusion though is that Linux swap is a pain now -- if your running install could just check for space, write a file and then hibernate it would be better.
 
Old 07-09-2012, 06:30 PM   #14
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Hanover, Germany
Distribution: Main: Gentoo Others: What fits the task
Posts: 15,648
Blog Entries: 2

Rep: Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095Reputation: 4095
I didn't put my swap on my SSD either, for space reasons. The 120GB on that disk are already separated between Windows and Slackware, so I didn't want to put a 16GB partition on it that is mainly used for hibernating only.
 
Old 07-09-2012, 06:41 PM   #15
273
Senior Member
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 3,541

Rep: Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804Reputation: 804
Considering I use hibernating to restore a current seeion, rather than try to boot quicker, thanks I know what to do.
 
  


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 & Boot Partition Resize surfer2k3 Linux - Newbie 4 07-17-2008 08:50 PM
Using swap and page file on same partition jgtg32a Linux - Desktop 1 10-25-2007 04:28 PM
Can the swap file partition be shared? benerivo Linux - Newbie 3 01-04-2007 11:20 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:01 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration