LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Swap Folder? (https://www.linuxquestions.org/questions/linux-newbie-8/swap-folder-916548/)

citi 12-01-2011 07:51 AM

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)?

acid_kewpie 12-01-2011 07:58 AM

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.

citi 12-01-2011 12:03 PM

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.

acid_kewpie 12-01-2011 12:05 PM

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.

TobiSGD 12-01-2011 02:48 PM

Quote:

Originally Posted by acid_kewpie (Post 4539326)
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.

jefro 12-01-2011 04:07 PM

"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.

David the H. 12-01-2011 04:24 PM

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.

TobiSGD 12-01-2011 05:07 PM

Quote:

Originally Posted by David the H. (Post 4539552)
...

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.

acid_kewpie 12-01-2011 05:20 PM

Quote:

Originally Posted by TobiSGD (Post 4539456)
Have a look here, the kernel won't use the file-system for a swap-file.

Oh right, makes a lot of sense. Ta.

David the H. 12-01-2011 06:30 PM

Quote:

Originally Posted by TobiSGD (Post 4539586)
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?

TobiSGD 12-01-2011 10:43 PM

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.

citi 12-02-2011 03:43 AM

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.:)

acid_kewpie 12-02-2011 05:02 AM

there is *STILL* no such thing as a swap folder.

citi 12-02-2011 05:13 AM

Swap file, my bad.


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