Linked by David Adams on Thu 20th Nov 2008 04:19 UTC
General Unix Linux and other Unix-like operating systems use the term "swap" to describe both the act of moving memory pages between RAM and disk. It is common to use a whole partition of a hard disk for swapping. However, with the 2.6 Linux kernel, swap files are just as fast as swap partitions. Now, many admins (both Windows and Linux/UNIX) follow an old rule of thumb that your swap partition should be twice the size of your main system RAM. Let us say I’ve 32GB RAM, should I set swap space to 64 GB? Is 64 GB of swap space really required? How big should your Linux / UNIX swap space be?
Thread beginning with comment 337859
To read all comments associated with this story, please click here.
Just use a growing swap file instead
by jokkel on Thu 20th Nov 2008 12:47 UTC
jokkel
Member since:
2008-07-07

I just don't get why Linux still uses a swap partition, which has exactly no benefits over a swap file. Except if they are on different drives. Yes I know you can use a swap file with Linux, but no distro has this as default setup.

Mac OS and Windows use swap files, which are transparent to the user and the programs. Just let the OS care about the size of the swap file and let me worry about my job. The OS can just start with the size of the RAM or half of it and increase the file size when neccessarry.

Reply Score: 5

siride Member since:
2006-01-02

It's because a SWAP partition doesn't require interaction with the VFS. Reads and writes and allocations can be done more directly. If you use a SWAP file, then you have filesystem overhead. In the older days, I suppose this was considered too slow to get good performance. I doubt it's a problem today, but people are slow to change.

Perhaps you should run some SWAP benchmarks and see if a SWAP file is considerably slower. I won't do it because I don't really care ;) .

Reply Parent Score: 2

MattPie Member since:
2006-04-18

It's because a SWAP partition doesn't require interaction with the VFS.

Also, swap files that grow fragment over time, which makes the disk head jump around looking for blocks that should be contiguous. Granted, having a swap file on a separate part of the disk isn't much better, but the performance will be constant, not degrading over time.

Reply Parent Score: 2

sbergman27 Member since:
2005-07-24

Swap really belongs in the middle of the disk. Not way out at the beginning or end of the disk, where it's furthest from the filesystem wrt seek time. I should note that reduction of seek time is likely to outweigh any factors of raw throughput performance at various places on the drive. In my experience, swap seldom streams. It seeks.

Reply Parent Score: 2

UltraZelda64 Member since:
2006-12-05

Mac OS and Windows use swap files, which are transparent to the user and the programs. Just let the OS care about the size of the swap file and let me worry about my job. The OS can just start with the size of the RAM or half of it and increase the file size when neccessarry.

Windows does that, and it's really good at pissing me off. Not much is more annoying than doing something slightly unusual in terms of memory use, then the OS thinks, "oh, it looks like you might need more swap" and causes the hard drive to grind away for a while, producing fragments in the swap file in the process.

Would it be so hard for the OS to just ASK? There's a chance that maybe, just maybe, I didn't *want* my swap space to be increased for [insert-stupid-action-here]. Maybe it wouldn't be so bad if Windows wasn't so stupid when determining the default minimum size for swap file, but as it is it's a major annoyance and was always the first thing I changed when reinstalling the OS.

In Windows, I just set the both the minimum/maximum size to 768MB or so so it didn't resize, and it worked fine.

In Linux, I make a 512MB or 768MB swap partition (depending on distribution and whether repartitioning is feasible or not), and if I absolutely *need* more I create and/or activate a 256-512MB swap file. I also make sure my swap partition is on a drive with my /home partition, separate from my system drive, but often create the swap file in / (which is, of course on the system drive).

This all on a machine with only 256 megs of RAM.

Reply Parent Score: 2