LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 12-01-2011, 07:51 AM   #1
citi
Member
 
Registered: Jan 2011
Location: Lithonia, GA
Distribution: Ubuntu,Fedora,puppy,CentOS
Posts: 36

Rep: Reputation: 6
Swap Folder?


Quote:
Originally posted by TobiSGD
For swap you can use a file instead of a partition
How do you create a swap folder? And why would you(other than to save partition space)?
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 12-01-2011, 07:58 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you don't create a folder, where does is say that?? you can make a swap file by creating a block file (i.e. from dd) on an existing file system and using mkswap on that as opposed to a partition.

Not sure what you mean by "partition space" here, you won't save any space, you just use it elsewhere. Personally I've made them in the past when I've needed more swap but not been able to allocate real disk. You can also make an LVM volume a swap device too, amongst many other things.
 
Old 12-01-2011, 12:03 PM   #3
citi
Member
 
Registered: Jan 2011
Location: Lithonia, GA
Distribution: Ubuntu,Fedora,puppy,CentOS
Posts: 36

Original Poster
Rep: Reputation: 6
Quote:
Not sure what you mean by "partition space"
For a lack of a better or right word to call it. From what I understand, you can only create 4 Primary partitions, or 3 Primary and 1 Extended Partition. Does making swap a folder allow for an extra Primary partition.
 
Old 12-01-2011, 12:05 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
again, swap is never a folder.

you can make however many logical partitions you want under an extended partition, so that's not an issue, no. Generally you wouldn't want to go through a filesystem to get swap on to a disk, so you would avoid it.
 
1 members found this post helpful.
Old 12-01-2011, 02:48 PM   #5
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by acid_kewpie View Post
Generally you wouldn't want to go through a filesystem to get swap on to a disk, so you would avoid it.
Have a look here, the kernel won't use the file-system for a swap-file.
 
1 members found this post helpful.
Old 12-01-2011, 04:07 PM   #6
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,978

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
"Note that I said swap spaces and not just swap device or swap partition. Linux allows you to create a swap file. Like any other file, a swap file exists on your filesystem and takes up space. The advantage is that you can add a swap file at any time, provide you have the space on the hard disk. You don't need to to repartition your hard disk or even reboot. "

From here. http://www.linux-tutorial.info/modul...ent&pageid=218

There may be other reasons that may have to do with managing partitions or hardware limits but that would be more rare.
 
1 members found this post helpful.
Old 12-01-2011, 04:24 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
First of all, let's get our terms straight. A "folder" is a (virtual) container for "files". But actually *nix prefers the term "directory" instead. "Folder" is the Dos/Windows word for it.

"swap" is not a file, or directory. It's a filesystem. It's essentially virtual RAM; hard disk space that can be used as a RAM substitute. It's mostly there for times when you don't have enough physical RAM memory to handle your requirements, but also for things like storing the current running image when suspending your session.

There are two options for creating a swap filesystem:

1) You can set up a dedicated partition for it. This option is better for performance, as the swap filesystem can be accessed directly by the kernel. But of course it's also a permanent allocation, as the disk space can't be made available for any other use.

2) Create a swap file. This is an image file of a swap filesystem sitting inside another file system. The advantage here is that you can create and delete swap files as needed, in any number and size. The disadvantage is that the kernel has to access it through the I/O of the containing partition, meaning it's not as efficient performance-wise.

Whichever solution you choose, or both, is up to you.


Note that the disk partition limits really have nothing to do with swap, which is just another kind of filesystem you can place on a partition. As you seem to understand, a disk with DOS-style partition allocation can only have 4 primary partitions. If you need more, then you can specify one of these partitions to be an "extended" partition, and then create a larger number of "logical" partitions inside of that. The Linux libata driver can currently handle up to 15 partitions on a drive, so for most people this is not a serious limitation.

But if you really need all of your partition space for other things, then yes, using a swap file means you don't have to dedicate a partition for it.
 
4 members found this post helpful.
Old 12-01-2011, 05:07 PM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Quote:
Originally Posted by David the H. View Post
...

This option is better for performance, as the swap filesystem can be accessed directly by the kernel. But of course it's also a permanent allocation, as the disk space can't be made available for any other use.

2) Create a swap file. This is an image file of a swap filesystem sitting inside another file system. The advantage here is that you can create and delete swap files as needed, in any number and size. The disadvantage is that the kernel has to access it through the I/O of the containing partition, meaning it's not as efficient performance-wise.
As already stated above (post #5), the kernel will directly access swap files (if it is a 2.6 or newer kernel), not through the I/O of the partitions filesystem, so there should be no performance decrease when using swap files.
 
2 members found this post helpful.
Old 12-01-2011, 05:20 PM   #9
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Quote:
Originally Posted by TobiSGD View Post
Have a look here, the kernel won't use the file-system for a swap-file.
Oh right, makes a lot of sense. Ta.
 
Old 12-01-2011, 06:30 PM   #10
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
Quote:
Originally Posted by TobiSGD View Post
As already stated above (post #5), the kernel will directly access swap files (if it is a 2.6 or newer kernel), not through the I/O of the partitions filesystem, so there should be no performance decrease when using swap files.
Yeah, but I could only clearly know that if I'd bothered to follow the link.

Seriously, thanks for the info. So are there any real disadvantages to using swap files now?

Last edited by David the H.; 12-01-2011 at 06:31 PM.
 
Old 12-01-2011, 10:43 PM   #11
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Actually, i can't think of any, except may be if you create a swap file on a heavy fragmented drive. But since I always use a partition, just because I am used to it, I simply lack experience here.
 
Old 12-02-2011, 03:43 AM   #12
citi
Member
 
Registered: Jan 2011
Location: Lithonia, GA
Distribution: Ubuntu,Fedora,puppy,CentOS
Posts: 36

Original Poster
Rep: Reputation: 6
Thanks Guys, I originally post the question to find out if there was an advantage/disadvantage in creating a swap folder, over the usual swap partition.
Tobi mentioned it in another post, I'd never heard of a swap folder b4 then.

Last edited by citi; 12-02-2011 at 03:52 AM.
 
Old 12-02-2011, 05:02 AM   #13
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
there is *STILL* no such thing as a swap folder.
 
Old 12-02-2011, 05:13 AM   #14
citi
Member
 
Registered: Jan 2011
Location: Lithonia, GA
Distribution: Ubuntu,Fedora,puppy,CentOS
Posts: 36

Original Poster
Rep: Reputation: 6
Swap file, my bad.
 
  


Reply



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
How to swap out (to swap area) page frames a process use? entertainyou Linux - Kernel 3 03-23-2011 09:52 PM
Gparted says swap has 5 Gb, grep SwapTotal /proc/meminfo says swap has 800 Mb rickrandall Red Hat 3 02-24-2010 12:09 PM
SWAP - having trouble with swap auto mounting at boot lostdj Linux - General 2 08-05-2008 12:47 PM
Squid swap folder creation problem selvamporko Linux - Software 1 06-22-2005 08:56 PM
How to unmount actual swap and mount a new(bigger) swap space? isaac Linux - Newbie 1 06-06-2004 01:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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