From: cummings@hammer.Prime.COM (Kevin Cummings)
Subject: Re: Needed: a guide to setting up swap space.
Keywords: linux, swap, setup, installation, mkswap, swapon
Organization: Prime Computer R&D
Date: Mon, 13 Apr 1992 18:52:15 GMT

In article <4rvjxcp@lynx.unm.edu>, caadams@leo.unm.edu (Clifford A Adams) writes:
> 	I recently installed Linux on my HD (/dev/hda1 mostly
> following I Reid's instructions), and things seem to be running OK.  I
> have 4 meg of ram (2.7meg reported free after buffers, etc), which is
> enough for most activities.  However, I'd like to add a few meg of
> swap space (especially since I like to use the full GNU Emacs while
> simultaneously compiling with GCC. :-)  I have about 200k of various
> FAQs and guides, but none of them explicitly say much about how to set
> up swap space.  I don't think I've been successful so far in figuring
> it out...

It was pretty easy for me.  First off there are two ways to set up
swap space.  You can create a swap file in your file system and page to it, or
you can set aside a disk partition, and page to that.  I choose the latter.

Step 1)	Using pfdisk, I made the disk partition.  It was a little difficult
	finding the right fdisk to figure out the exact device name to use,
	but a little common sense came through in the end.  For me /dev/hda1
	is my primary DOS partition, and /dev/hda2 is my extended DOS partition.
	Using pfdisk, I set up partitions 3 and 4 and labeled them as
	type Linux/Minix file-system, and Linux-swap partitions.  The latter
	wasn't really necessary, I could have labeled it as anything.
	So, I have LINUX root on /dev/hda3, and LINUX swap on /dev/hda4.
	(If you already have LINUX on your hard drive, you only have to setup
	your swap partition.  I just happened to do both at the same time.)

Step 2)	I ran "mkswap -c /dev/hda4 xxxx" where xxxx is the amount of space
	reported by fdisk as being available on the device.  The -c
	tells mkswap to check the media for bad spots (unrecoverable errors).
	You don't want to page onto one of those!

Step 3)	After the partition is ready for swapping, I turned it on via
	"swapon /dev/hda4" to see if there would be any problems and ran that
	way for a while.

Step 4)	To make the swap area appear permanently in my system, I modifed /etc/rc
	to do the swapon for me during system boot.

The prcedure for a file system swap file is similar to the above, except that the
swap device being used by the mkswap and swapon commands is a file instead of
a device.  Create a file big enough to hold the amount of swap space you want,
and use that pathname in place of /dev/hdax in the above sequence.

> 	Here are my problems (using 0.95c+ boot floppy and a mostly
> 0.95a root on /dev/hda1):
> 
> 	* "mkswap" was on my 0.95a rootdisk.  There seems to be a
> newer version (later file date) at tsx-11 under the binaries tree
> (the later one is bigger).  What are the differences, and which should
> I use?  For the rest of my experiments 

I don't know, I used the one on my root disk without problems.

> 	* Looking at "mkswap" I noticed a "-c" option--what does it
> do?  Early on I thought that "-c" meant "create", and that otherwise
> mkswap would set up and use the swapfile.  At the moment it seems like
> you use swapon to set up a swap file--at the first reading it seemed
> like swapon was only for swap partitions...

Like I said above, the -c causes a media check for bad spots.

mkswap configures the disk for swapping.  (Like mkfs configures a disk
to be used as a file system.)  swappon is the command which actually
tells the OS to use the new swap space.

> 	* I made a file "/dev/swapfile" using emacs to create a file
> of 1K spaces, then using cat to make 4K/16K/64K/256K/1meg files, and finally
> the 6 meg /dev/swapfile.  I didn't know if it would need a little more
> space for tables or whatever so I added another 256K as extra.
> 		* Is there a better way to create the swapfile?

Under SUNOS, they have a mkfile command.  I haven't seen one for LINUX yet.

> 		* Do I need to have more space than the #blocks I tell mkswap?

Nope, but if you have more space than you've configured with mkswap, it'll never
get used.

> 	* I noticed that the mkswap blocks are 1K--this should
> probably be noted since its different than the filesystem blocks...

So swapping swaps 1K bytes at a time.  That is a memory page size.

> 	* Is there any way to tell how much swap space you are using or
> have left?

Under SUNOS I do a "pstst -T".  I haven't seen a LINUX command yet to tell me
how much is actually in use.  And seeing as gcc-1.4 didn't know when my disk
was full (other that getting unexpected EOF error messages during compiliation),
I wouldn't be surprised if LINUX doesn't detect "out of swap space" cleanly either.
For now, I hope that 4MB of memory and 9MB of swap space is enough to not run out of
until we get something that tells us swap usage.

> ...What I'd really like to see is a guide something like Reid's guide
> to installation for setting up swap space--one that would cover both
> swapfiles and swap partitions.  (Perhaps it could be added as an
> appendix to the guide?).  Just a list of the commands and what they do
> would be nice however...
> 
> 	Finally, my first impression of Linux is: "zippy".  Its been a
> long time since I've had the kind of quick response Linux gives, even
> when I worked on "unloaded" machines (where I'm the only user, the load
> avg is 0.00, etc...).  Even when running GNU emacs the response is
> excellent (on my 40mhz 386 w/64K cache).  It may seem like a
> small difference between the seeming immediate Linux response and the
> more typical 2/3-1 second reaction time, but it feels nice...  (Its also
> nice not to wait for overloaded NFS fileservers, and being able to
> mess with the kernal is a plus. :-)

Yeah, ain't it great?

=================================================================
Kevin J. Cummings                       Prime Computer Inc.
20 Briarwood Road                       500 Old Connecticut Path
Framingham, Mass.                       Framingham, Mass.

Work:  cummings@primerd.Prime.COM
Home:  cummings@kjc386.framingham.ma.us

Std. Disclaimer: "Mr. McKittrick, after careful consideration,
		  I've come to the conclusion that your new
		  defense system SUCKS..."   --  War Games
=================================================================
Xref: sparky comp.os.linux:205 alt.os.linux:2303