# mkswap --> truncating swap

## sheepdog

This question was posted to the install forum but no one responded and I still have the problem.  Please advise:

Upon installing Gentoo 1.4, since I have 3 G of memory I made a 6 G partition for swap. However, upon doing "mkswap /dev/hdc7" I receive the reply "truncating swap area to 2097144". Is this right? Can I not have a 6 G swap? Should my swap be smaller than my RAM? Thanks. 

-- Michael

----------

## n0n

There is a limit on swap space sizes, it looks like it might be ca. 2GB or so right now.  For more information, you can take a look at the source to util-linux, inside disk-utils/mkswap.c.  A bit that seemed relevant (didn't bother to replicate the math they're doing there):

```
/* 32bit kernels have a second limitation of 2GB, sparc64 is limited by

   the size of virtual address space allocation for vmalloc */
```

And then:

```
/* man page now says:

The maximum useful size of a swap area now depends on the architecture.

It is roughly 2GB on i386, PPC, m68k, ARM, 1GB on sparc, 512MB on mips,

128GB on alpha and 3TB on sparc64.

*/
```

So I'm guessing it's 2GB.  One easy solution is to just have multiple swap partitions, each of them 2GB.  I believe that the current limit is 16 swap spaces, so you've got a lot of room to play around with.

As for how much swap you should have, I've always done 2.5x physical memory, personally.  So if I had 3GB memory, I'd probably bite the bullet and do a whole 7.5GB of swap.  However, I started doing this at a time when memory was a bit more scarce than it is now.  When your box could only be expected to have maybe 32MB of memory, and you still had to run X, you could expect to be going out to swap quite a bit.  Nowadays, my 2.5x rule might be a tad antiquated, because memory comes very cheap nowadays.  I've got 512MB memory on my desktop machine, and I only very rarely go out to swap.  Are you actually running something that'll eat up all that memory?

----------

## sheepdog

Thank you for your very interesting discussion.  I am running a particular application, built in-house, that currently uses up 1 G of RAM and does _not_ run at all if it has to swap.  Thus the 3 G of RAM.  My intention is to have enough memory so no swapping will occur, exactly because the application runs so poorly if swapped.  I finely did get replies in the install forum and 2 contributors said that with that much RAM I did not need swap at all, which I found curious.  Surely, I thought, if one ran out of RAM what would the operating system do without swap?  Seems like it would be stuck.  But they were so certain I figured Linux must have some trick to dealing with the situation.  Not so?

-- Michael

----------

## n0n

If physical memory is exhausted, and no swap is available, then as far as I know, Bad Things will happen.  Memory allocation calls will fail, and if the program whose memory allocation call failed knows how to deal with it, it'll die gracefully, otherwise it'll probably segfault or do other nasty things.  In general, things will just get really dicey until memory or swap is freed up.  Typically you're not going to have lasting damage or anything, but while memory's been exhaused, your machine will be having definite Issues.

The one thing UNIX systems typically don't do terribly well with is resource starvation.

So do you *need* swap if you've got 3GB?  Hopefully not; generally you never want to be going out to swap if you can help it, and if your program's taking up 1GB, then I'd certainly hope that everything else combined isn't taking up more than another 2.  Personally, I'd put at least 3GB of swap out there, and for my own box I'd probably end up doing 6GB (7.5, using my 2.5x metric, seems a bit too obsessive, even for me).  :)

----------

