Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
"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. "
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.
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.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.