Please read this:

What follows (my reasoning - not Callum's) is not much more that "hand
waving" arguments for various rules of thumb for swap partition
allocation.  The best way to evaluate swap partition location is by
duplicating actual production loads on various swap/filesystem partition
maps and seeing experimentally which is best for a particular mix of
applications.

Ken Fuchs wrote:

>> You could start with 256MB swap space and add swap partitions as needed.
>> However, keep in mind that modern hard drives have about twice the
>> performance on the outer cylinders than the inner cylinders, so try to
>> position swap space near the beginning of the drive for better swapping
>> performance.  Swap should also be close to often used filesystems.  Best
>> yet, is put swap on its own drive.

Callum Lerwick wrote:

>Not really a good idea for the vast majority of systems these days,
>which tend have plenty of RAM for the load upon them and thus swap
>rarely. Think about it, once you're swapping, you've already lost the
>game of performance, so why waste the speedy outer cylinders on swap?
>Its going to be better for overall system performance to use the outer
>cylinders for your filesystem, and use the slow inner cylinders for
>swap.

I respectfully disagree with the suggestion to locate swap space at the
end of a drive.  Swap space is generally a small percentage of total
disk space when using 9GB or larger drives (4GB drives are the smallest
I would use on almost any system).  512MB of swap space is large enough
for the vast majority of systems.  Placing swap at the beginning
(BEGIN-SWAP) of a 9GB drive versus the end (END-SWAP) of it means about
twice as much swap performance.

            +--+--------------------------------------------------+
BEGIN-SWAP  |SS|           PARTITIONED FILESYSTEM SPACE           |
            +--+--------------------------------------------------+

            +--------------------------------------------------+--+
  END-SWAP  |           PARTITIONED FILESYSTEM SPACE           |SS|
            +--------------------------------------------------+--+

In both BEGIN-SWAP and END-SWAP, the performance of the central 8.0 GB
of the 9GB drive can be considered a constant and the performance of the
remaining 512MB of filesystem is the differentiating factor.  This 512MB
of filesystem space at the beginning of END-SWAP is of course twice that
of the 512MB of filesystem space at the end of BEGIN-SWAP.  Thus, using
END-SWAP as the comparison standard (performance factor = 1), the
relative filesystem performance of the PARTITIONED FILESYSTEM SPACE of
BEGIN-SWAP is 8 GB * 1 + 0.5 GB * 0.5 / 8.5 GB = 0.97.

Thus, the BEGIN-SWAP positioning provides 512MB of swap space that is 2
times as fast as END-SWAP and BEGIN-SWAP positioning provides 8.5 GB of
filesystem space that is 0.97 times as fast as END-SWAP.

My conclusion: If swap is not ever going to be used, don't allocate any
swap partitions.  If swap is allocated as in the BEGIN-SWAP drive map,
the swap's 2x performance versus END-SWAP will delay disk trashing due
to swapping.  Note that it makes sense to put the most often used
filesystems near the beginning of the drive (since the outer cylinders
perform better than the inner).  Now, for a second reason, swap at the
beginning of the drive is better because the actuator moves across fewer
cylinders between the swap partition and the highly used filesystem
partitions near the beginning of the drive.

The above analysis assumes that if swap is needed its performance is
more critical to overall system performance than any filesystem.  If
this is not the case, then clearly Callum's suggestion of placing swap
at the end of the drive has merit (assuming swap performance is less
important than the performance of all filesystems).

However, for best swap and filesystem performance, given only one drive
to use, it may be best to place a small swap partition between every
filesystem partition.  This allows the kernel to select a swap partition
on swap out based on "actuator position" and perhaps other factors.

Without doubt, a much better location for swap is a high performance
drive dedicated exclusively for swap (which was already suggested above).
Thus, swap and filesystems would have their own dedicated disk.  There
are of course more complicated multiple disk arrangements such as RAID
that provide even better performance, but they are not generally used on
single user workstation.  Even, a simple, dual drive system with both
swap and filesystem partitions on both drives can be easily arranged to
outperform one disk dedicated to swap and another dedicated to
filesystems.  

>On the typical 512mb+ RAM desktop systems these days, even with as
>bloaty as GNOME/KDE can be, you're not going to be swapping enough to
>warrant wasting your outer cylinders on swap.

That may be true, depending on application load.  However, the more RAM
a system has the less swap it needs.  Even a 512MB swap at the beginning
of a 9GB drive degrades filesystem performance on the rest of the drive
by only 3%.  If 512MB is too big, use 256MB (2% filesystem degradation)
or 128MB (1% filesystem degradation) swap at the beginning of the drive
or make smaller swap partition throughout the entire drive.  If there is
so much RAM that swap would never be used don't allocate swap space at
all or reallocate swap space for filesystem use.

Filesystem degradation is 3% due to placing 512MB swap at the beginning
of a 9GB drive versus placing swap at the end.  This seems to be a small
price to pay for swap that is twice as fast.  Even if that 2x speed swap
is not needed, the penalty is only 3%.  This penalty will not even
affect system performance unless the system is already close to being
I/O bound.  Most often, desktop systems are "user" bound (waiting for
user mouse and keyboard input).  In any case, the warm fuzzy feeling of
having 2x swap in case one needs it, probably out weights the 3%
penalty hit to filesystem performance for the vast majority of users.

>If your system really is swapping hard enough to warrant putting swap on
>the outer cylinders, meaning a vast majority of your disk IO bandwidth
>on a given disk is dominated by swapping traffic, you really ought to be
>buying more RAM anyway. Its so cheap after all! <note: some sarcasm>

Yes, if your disk(s) are trashing, you need more RAM or a higher
performing arrangement of swap and filesystem partitions.  Remember
that Disk I/O bandwidth due to swapping will be reduced by half by using
the outer disk cylinders versus the inner disk cylinders, assuming that
the outer cylinders perform twice as fast as the inner cylinders which
is very often true (or close to the truth depending on the actual disk
drive used).

------

Finally, since swap space is a part of the virtual memory system it
would be generally best to use the fastest partition on a disk drive to
help emulate memory.  There should be a good reason to not use the
fastest partition on a disk drive such as distributing swap space
throughout the entire disk when all filesystems are utilized about the
same amount and the actuator could be anywhere at any given moment
rather than near the often used swap and filesystems at the beginning of
the drive.

Alternatively, if actuator position becomes a dominant factor, swap (or
some of it) in the middle of the drive may be better than all swap at
the beginning or end.

Anyone who has read this far into this message deserves an award of some
sort and may have enough energy left to search for research on this
subject and report it to the list.  Perhaps, we might all learn
something more in the process and be subjected to fewer ramblings such
as the one I've just written above.

Sincerely,

Ken Fuchs <kfuchs at winternet.com>

_______________________________________________
TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
http://www.mn-linux.org tclug-list at mn-linux.org
https://mailman.real-time.com/mailman/listinfo/tclug-list