[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Automatic allocation of swap

Osamu Aoki wrote:


On Sun, Aug 01, 2004 at 09:04:50PM +0800, John Summerfield wrote:
I have just installed another system, and took the time to try to familiarise myself with the partitioning tool.

I was running a 2.6 kernel, and the install kernel's date is Jul 29 06:24.

The install target was a Pentium II, 350 Mhz, 64 Mb RAM and 3.2 Gbytes of disk.

It seemed to me that the setup chosen for "multiuser" was entirely impractical. Unfortunately, I was more interested in testing other aspects, so I just wiped that one and tried some others.

One aspect of that configuration I do recall.

It allocate about 192 Mbytes of swap partition, right at the edge of the disk.

Hmm. put it to the edge may not be the best thing to do ... Does this have any real impact?

For sure. Think about the seek distances. Mostly, in drive specs you see 'minimum seek" and "average seek."

The latter is a bit vauge, but IBM (at least in the 70s) caclulates it over some benchmark workload: it's not the seek time for half the disk.

By spreading data over multiple paritions with great gobs of free space between small (after install) amounts of data, you're forcing longer seeks.

I have never thought swap partitions on single-disk systems are a good idea, and here is why.

1. Performance
If there is little swapping, then any perfoemance benefit is immaterial.

So do not complain swap is not at the center.
Then you also don't need any performance benefits of swap partitions over swap files.

If swapping is severe (the system is thrashing), there is no good alternative to more RAM. RAM is cheap.

That is different problem. Swap will not be used unless RAM is used up.

Indeed, but the system performance will become truly appalling before it should.

That aside, the position of the swap area (in the d-i configuraton as in most others) ensures the swap area is far from the data, ensuring that operations such a opening an OOo document will send the disk heads seeking far, back and forth, back and forth, back and forth, across much, maybe most, of the disk surface.

Then buy a RAM.  Optimization you get with swap location is small.

In between, of course, is inbetween: bad sometimes, not so bad at others.

In contrast, if I create a swap file, then it there is some prospect it will be near at least some of the data I need to read.

I do not understand...

Here is a hypothetical layout

Here, the swap parition is in the wrong location. If the system uses synchronous writes to /var (think logs, mail, I guess news) then the disk heads will often be somewhere in /var.

If the system has a moderate swapping load, then the heads will be travelling clear over /home, maybe twice for each read and write.

I don't know how Linux filesystems allocate space, but likely it's
a) Prefers one edge of the parition
b) Prefers to spread data over the partition

Some may prefer to fill holes, but in the initial state those holes do not exist.

If we reverse the order of swap and /home above, we have a better situration.

I prefer the use of a swap file. If there's half-a-gig of data in a ten-gig partition, the swap area is right there with the data, as best I can do i. Not somewhere probably far from the data.

There's also the problem of just where the major I/O activity will be. For tranditional servers, it will be in /var. For interactive workloads, /home is more probable. However, a peecee with 50 logged-in users running X applications is still a server! For such a workload, a swap file in /home might be better than one in /var or in its own partition.

Here is my desktop pc. It's performance sucks bunnies through capilliary tubes:
summer@Dolphin:~/d-i$ /sbin/swapon -s
Filename Type Size Used Priority
/var/swapfile                           file            524280  455604  -1
/var/swapfile2                          file            524280  69296   -2
summer@Dolphin:~/d-i$ df -lh
Filesystem            Size  Used Avail Use% Mounted on
/dev/hda3              29G   27G  639M  98% /
tmpfs                 189M     0  189M   0% /dev/shm
/dev/hda1              23M   21M  1.4M  94% /boot

Do you think performance would be improved by forcing the disk to seek to the edge of the disk for each access to swap?

I don't.

Two swap files on one disk might not be ideal, but for sure it was easy to do, and I didn't have to take the machine down to add more.

2 Flexibility.
The common Rule of Thumb (ROT) has the appropriate size of swap being twice the amount of RAM installed (not three times!).

I thought "at least 2 X RAM".  So 3 X is OK.  Besides, it is less than
10% of disk space.  Who cares lost space.  You can ajust it later if you

Most systems I use get bogged down well before they've used 2x. 3. is just plain silly. TheI could conceivably put 1 gig of RAM computer in the computer I'm using now, but I surely don't want to reformat the 30 Gbyte disk in it to create a 2 Gbyte partition.

My own experience is that, mostly, system performance is pretty terrible before it's used all the swap area. The sole counterexample I can think of is using rsync to do backups. rsync can use enormous amounts of virtual memory backing up whole disks, but its working set remains modest.

???  (Maybe you are talking bad swap logic of some 2.4 kernels.  But
this does not make us stop using swap.)

I said nothing about not using swap.

However, swap partitions are evil on most peecees. Use swap files by all means.

The stupidity of this ROT is illustrated when adding more RAM. If my system is working moderately well with xMbytes of RAM and I, noting that RAM is cheaper than formerly, decide to add 2x Mbytes of RAM, should I also treble the amount of swap? Of course not, I may well decide I have better uses for that disk space.

I do not think adding ram later has negative impact and I do not call
this setup stupid :)  ....

The ROT says reformat the hard disk to make  a bigger swap partition.

Take this:
ns:~# free
            total       used       free     shared    buffers     cached
Mem:        127008     124536       2472          0      11168      24256
-/+ buffers/cache:      89112      37896
Swap:       262136     118460     143676

Why should I not, if I have a stick of RAM to hand, put it in this box and turn swap off altogether>

Either way, the amount of swap is wrong, and recovering or enlarging the amount of swap in a swap partition is not a trivial undertaking.

I think it is trivial if you have empty unused diskspace.  (I am
comparing this to moving and resizing ext2 partition.)

You can do swapoff then you can change swap partition to elsewhere.

Remember I specifically said _one disk._

To change the swap parition sise likely requires backup, repartition, restore, and can take hours. OTOH swap file - minutes.

Finally, the point that I installed a 2.6 kernel is an important one. One of the changes I note in the new kernel is that there is no performance benefit to using swap partitions.

What?  Try running a program which leaks memory.   With swap, you will see
slower degradation, thus enhancing your chance to avoid bad crash

(I think you were annoyed some non-optimal swap usage in the previous kernels. That is different matter though.)

I recommend that, if there is one disk, a swap file be created rather than a swap partition.

Nay.  Does this something other distribution zstarted to do with some
reason. At least this was not normal thing.

I don't understand.

And, if /home is a separate partition, then it should be on that partition. That is where most I/O activity is likely to be on single-user systems.

Well I tend to partition


in this order... but I do not think this order is something absolute.
That's almost certainly bad. You probably don't spend much time reading program files and documentation in comparison with the time reading and writing variable data.

You're a software developer writing in C? Would you say, less than a second to read gcc then a minute or so for a compile? Sure, it depends, but the ratios will be somewhat like those.



-- spambait
1aaaaaaa@computerdatasafe.com.au  Z1aaaaaaa@computerdatasafe.com.au
Tourist pics http://portgeographe.environmentaldisasters.cds.merseine.nu/

Reply to: