From: Linus Torvalds (torvalds@klaava.Helsinki.FI)
Date: 02/03/93


From: torvalds@klaava.Helsinki.FI (Linus Torvalds)
Subject: Re: need help with swapspace
Date: 3 Feb 1993 13:10:25 GMT

In article <1993Feb2.153738.10782@cs.few.eur.nl> goossens@cs.few.eur.nl (Rogier Goossens) writes:
>jlowry@cih.hcuge.ch (LOWRY John (IG)) writes:
>> touch swapfile
>> mkswap /swapfile 4000
>> swpon /swapfile
> ^^ a
> When I did this, I got error messages when the swap was used
> (something like pages getting lost or so. I don't remember exactly.)
> I solved this by using a swapfile of 4Mb+4Kb (in this case).
> I.e. I first create a file with a size of 4Mb+4Kb, and then I do
> mkswap and swapon.

You did the right thing. The "mkswap" command will not do anything but
actually write the swap signature (and check for readability with the
'-c' flag) to the file: you need to create the file with the correct
length (and no holes) before running mkswap. Of course, when doing this
on a raw partition there are no problems: the space for the swap area
already exists.

Note that I *don't* want the swapping algorithms to expand the swapfile
while swapping as that is a way to certain doom if something goes wrong.
But the 'mkswap' program should probably be expanded to create the file
if it's a regular file - easy enough to do, so if somebody feels
adventurous..

Currently, the way to create a swapfile looks roughly like this:

        # dd if=/dev/zero of=swapfile bs=1024 count=NNN
        # mkswap swapfile NNN
        # sync

After which you can activate it by doing a "swapon swapfile" (and
probably putthing the command in your /etc/rc.local or in fstabs).

                Linus