Linux swap partition

Using applications, configuring, problems
Message
Author
User avatar
RussA
Posts: 27
Joined: Fri 02 Dec 2005, 14:02
Location: New Jersey, USA

Linux swap partition

#1 Post by RussA »

No matter what they say it does. I was just wondering if there is a rule of thumb. Is there a min, max, fixed size, or is it proportional to ram.

Thanks,
Russ

JohnMc
Posts: 118
Joined: Fri 07 Apr 2006, 15:18

old rule

#2 Post by JohnMc »

When I was an young sys admin back in the 80's the general rule was that a swap file should be no less than 1/4th the size of the main ram size. But those were days when ram was very expensive and disk packs the same.

With PCs and commodity pricing for drives what's it matter? If I build a Puppy box for HD install I just build 1- 1gb partition for swap and let it be finished. Smallest HD I find around the house right now is a 10GB drive. Small triffle to pay to just not fret about it. :wink:

User avatar
RussA
Posts: 27
Joined: Fri 02 Dec 2005, 14:02
Location: New Jersey, USA

#3 Post by RussA »

Thanks John, I agree. I was just thinking from a performance perspective.

Russ

Sage
Posts: 5536
Joined: Tue 04 Oct 2005, 08:34
Location: GB

#4 Post by Sage »

Yes! Traditionally, 'doze uses a variable swap size, which it mixes with your regular files (where do they get these guys?!), but never more than twice the main RAM. All the major distros observe the same [2 x main] formula by default. From experiment, I have found that a maximum swap size equal to main memory is a good solution for Puppy provided:
a) not running excessively large apps or several large ones simultaneously
b) maximum of 256Mb swap for x86 single core cpu
c) for machines with very low memory, eg 48Mb, try to restrict swap space to one or 1.25x main, regardless. If apps won't run under these conditions, change the HW, eg add RAM, if possible. Even quite small swap space (<main) is worth installing on ancient kit with low resources.
Although we've had several detailed discussions about this subject previously (SEARCH), some correspondents are plain wrong, some lack practical experience and others provide theoretical background. What I say is based on solid practical experimentation. Overdo the swap space and you risk thrashing your HD to an early demise. You will have the pleasure of listening to this process.
Like everything else, there are exceptions, but sticking to the above is the best expedient unless one is very skilled in the art.
One interesting exception is to provide a (probably very old) small HD as swap only when running as a live CD. A 210Mb drive seems ideal and speeds things along nicely. Don't forget to format it. Even better would be to recycle an ex-laptop 2.5" unit of similar capacity - small, quiet, cool and modest power demand.

User avatar
RussA
Posts: 27
Joined: Fri 02 Dec 2005, 14:02
Location: New Jersey, USA

#5 Post by RussA »

Thanks Sage,
Just what I was looking for, I noticed the swap partition makes a big difference. I’m kind of the go to guy when friends and family need their pc’s fixed. A fresh Puppy boot disk sure cuts down on the tech support time and calls. :-)

Russ

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#6 Post by rarsa »

Sage is right on the money.

Swap is not meant to be used as RAM, but as "emergency" RAM. If you end up using it as much as RAM your computer will be so inefficient it will be practically useless.

I think that the rules of Swap size based on RAM size or HDD size are missleading. I think it's better to think of it based on, guess what: Swapping.

In my job as performance and capacity manager, one of the measurements we use as an indicator of the system Capacity is the ratio between Page input/Sec and RAM utilization. Optimally a system would have a high RAM utilization with minimal Page input/Sec. meaning that it has all the data it needs in real RAM and does not need to use swap at all.

If you have low memory (in relation to the apps you are using)

Even if you have multiple applications loaded If only use one application at a time, your ratio may be low as you would not be swapping too frequently. In that case It would be OK to have a larger Swap than memory as you'll have there the applications that you are not currently using and your RAM would be mostly used for the application you are using so here size matters.

If you are switching too frequently between applications, your ratio may be high as you would be swapping every time you switch to a different application. There your performance would be bad regardless of the size of the Swap partition, so size does not matter at all.

So the size of the Swap depends on how you use your computer. I guess that the only rule of thumb here is that you should use your computer according to its capacity.

Think of Swap as emergency RAM not as dynamically usable RAM. My favourite analogy is a work table (RAM) and drawers (Swap).

- If you are just writing one paper at a time, the size of the table does not matter, you can keep the rest of the papers on the drawers until you need them.

- If you are preparing your taxes youbetter have a large table or you will be wasting time taking the papers in and out of the drawers.

So size your Swap according to the usage and plan the usage according to the amount of RAM.

How to know if you are over taxing your computer? play by ear. literally. If you hear your HDD trashing constantly that means that your computer is constantly swapping. If you don't hear your HDD trashing constantly but every now and then you run out of memory, then increase the size of the Swap.

Or as Sage sugested, be generous with the Swap size and if you hear your HDD trashing constantly then either change your usage patterns (don't switch frequently between apps) or increase RAM.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

User avatar
Yaverot
Posts: 94
Joined: Thu 22 Dec 2005, 03:23
Contact:

#7 Post by Yaverot »

Thank you Sage, the "right amount of swap" is a hard question to find good answers to, Windows or Linux. I have (someplace) a couple articles that basically say "You have to determine the correct amount of swap space, since it depends on what you do with your system how much RAM etc." With part 2 being "Here are the tools, how to use them & how to run the tests". They're for 9x era Windows.

It seams weird to me that the rule is "twice your RAM" in most cases. Isn't the point of buying more RAM so that you aren't using as much swap (swap being incredably slow in comparison to RAM). At some point you may be more demanding on your system and then need to increase swap/buy more RAM. But how often do you get "out of RAM" warnings? How much more often do you get "out of drive space"?

I can think of three times I've had to deal with a RAM limit:
1. attempting to load a mouse & netcard driver under DOS & use a program that wanted 620k of conventional RAM (ie ignoring everything above 640k, like that 2nd MB).
2. recently I was building gcc in a virtual machine. because I forgot the swapon command and I set the machine up with little ram.
3. Bootable CDs (puppy, gnewsense, freenas) that aren't always clear on how much ram they need to boot. Some are easier to find that info than others.

So having real numbers (with reasons) is a great help.
There is a yellow one that won't accept the black one
That won't accept the red one that won't accept the white one
And different strokes for different folks

User avatar
WhoDo
Posts: 4428
Joined: Wed 12 Jul 2006, 01:58
Location: Lake Macquarie NSW Australia

#8 Post by WhoDo »

I'm with Sage and rarsa on this, but I'd like to make a couple of small but important points:
  • 1. Puppy is designed to load and run on older, ram-challenged PC's so swap IS an issue that can't always be avoided by simply adding RAM - of course the latter is the better choice, wherever possible.
    2. For Puppy, 1x or 2x RAM is acceptable; usually 1x above 128Mb and 2x below that but never more than a maximum of 256Mb - Puppy is highly unlikely to use any more than that amount. If it does, get more RAM or a new PC or both.
    3. Big swap partitions are a waste of space and may be injurious to the health of an older drive.
    4,. For the average user, if you have 512Mb RAM or more your swap partition is superfluous in Puppy, and most other distros. It simply won't ever be used so why waste the space?
Hope that helps.

PaulBx1
Posts: 2312
Joined: Sat 17 Jun 2006, 03:11
Location: Wyoming, USA

#9 Post by PaulBx1 »

One final point: if you are thinking about using an encrypted pup_save, the only current workable solution (see the encryption threads) does not encrypt swap, which means anything you want to keep private may end up in cleartext on your swap partition. This is a gaping security hole. :)

Solution is to turn swap off entirely. This obviously pushes people in the direction of adding more ram...

Some day we may have an encryption solution that includes swap, but it will probably be a while.

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#10 Post by rcrsn51 »

Here is some data to confirm Sage's point. On a machine with 128 MB of memory and no swap partition, Puppy automatically created a 100 MB swapfile. When I ran the 'free' command, about half of the swap memory would be in use, but there was never a lot of hard drive thrashing. I then added another stick of memory for a total of 256 MB. Now the swap memory is rarely used at all, even with several applications open. For the average user, Puppy seems to be pretty good at determining its swap memory needs.

JohnMc
Posts: 118
Joined: Fri 07 Apr 2006, 15:18

OT

#11 Post by JohnMc »

In our environment here @ work we had 250,000 pc's all running some version of Windows. Practically all of them are ghosted. We have toyed with the idea that switching to some version of linux as the costs for Vista are too steep. Looking at the variety of ways we use all this compute power the concensus was a 1Gb swap. It will end up being a goldilocks kind of story with maybe 25% of the machines being mismatched.

But our bigger problem from a corporate perspective is the labor. It costs too much to tweak each machine. So if we do this we will clone them to a base and only tweak critical machines based on exceptions.

At a personal level, I use a corporate laptop with puppy (CD/usb setup). It's got 1Gb of memory in it. In puppy mode? It runs like a solid state machine and the HD never spins it seems. In WinDoz mode? I can hear the hard drive spin as needed. Which is often.

Would I be able to get management to go to puppy? Probably not. :cry:

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

Re: OT

#12 Post by rarsa »

JohnMc wrote:Would I be able to get management to go to puppy? Probably not. :cry:
Would it be even advisable? absolutelly not. Is it desirable? I don't think so.

As much as I like Puppy for what I do, it is not a "one size fits all".

(I know that John knows but for the rest ...) Corporations require enterprise wide management applications such as directory services, remote ghosting, sw/hw inventory discovery, SMS push, different network protocols, etc.

For the people that complain that the "big distros" are too bloated, It may just be that they are on the "one size fits all" mentality. SE linux and firewalls and directory services are a must in some environments, rarelly they are required at home.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

CatmanDru
Posts: 90
Joined: Thu 07 Sep 2006, 21:35
Location: OR, USA

#13 Post by CatmanDru »

Thanx for the very good, detailed and informative discussion/info on swap partition size. I would like to bring up a few ideas so others can give feedback. Please bear in mind these are for users who dont mind a little, or a lot of, complexity. Also please remember that I, and others, use 'old' computers and squeezing more efficiency is worth a bit of effort.

1. One is the idea of using a few 'small' multiple swap partitions spread accross the disc surface. A regular poster mentioned that in some situations (uses of computers) this results in better performance. I think the situation involved small, frequent swaps combined with frequent access to non-swap partitions and maybe non-sequential data. One general point was to reduce the time & physical space the HD heads needed to move to get to a swap partition thereby increasing performance. a) What would the use conditions be that would make small, multiple swaps advantageous? b) How advantageous would this setup be?

2. What do people think of the idea of having 2 swap partitions for different needs and just mounting/unmounting as needed. The 'default' swap for most common use is/would be autoloaded if it is the first on the drive*. The second swap, or both, could be mounted when appropriate for the computer's less common uses or 'styles of use'. For example a bare-minimum size swap to decrease drive access/thrash (and increase performance?). Another swap could be mounted to make a larger total swap space when running excessively large apps or several large ones simultaneously.

Im interested in part because on this machine when setting up the hard drive i was reading conflicting information about swap size and was having trouble deciding but I just wanted to set it up so i made 2 swap partitions (200 & 300) which i figured i could play/experiment with and later modify into less swap(s) or swap and an additional OS partition. It seemed less problematic to start large and later shrink than to start small and later resize partitions :shock: to make more swap space.

*personal experience.
Last edited by CatmanDru on Tue 30 Jan 2007, 21:21, edited 2 times in total.

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#14 Post by rarsa »

I'd say that if in your environment you are worried by swap performance, then Puppy is probably not the distro for you.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

User avatar
Gn2
Posts: 943
Joined: Mon 16 Oct 2006, 05:33
Location: virtual - Veni vidi, nihil est adpulerit

#15 Post by Gn2 »

I strongly concur with Rarsa's assessment:

A = Taylor size to proven need

B - Be just as cognizant of placement of all partitions, Esp Swap (drive head movement - seek, read/write In/out times)

C- Be aware that for temp use -swap files may be created, deleted
as need arises.

D - Strongly advise (for those with proven need only)
Use TMPFS & set niceness factor !

E - Use of a larger ( than required) Swap partition will NOT cause hard drive thrashing !

That ONLY occurs if physcial RAM is insufficient and tasks are VERY memory intensive.

In summation:
Use of tmpfs dynamically sizes space needs > pages in/out only portions, upon load demand from user syscall interupts.

Puppy is NOT a recommended plalform for those user requirements.
Puppy would not be a suitable match for many other .... just as relevant considerations under those circumstances.
> It doesn't (default include) other utilities, equally as important
to tasking involved.

Frequently that scenario will involve EVMS, quotas and shared resources - &/or remote administration, team Mgt.
Example : I habitually create three 2GIG swap partitions, toggle on/off as need arises

However, my physical RAM is large enough -& tested under abnormally LARGE simultaneous copy loads -
And while concurrently backgrounding (man nice) compiling of large Apps - the CPU often hits sustained 98% load factors - swap still not used.

= Puppy is ill suited platform for non-common usage.

User avatar
rarsa
Posts: 3053
Joined: Sun 29 May 2005, 20:30
Location: Kitchener, Ontario, Canada
Contact:

#16 Post by rarsa »

Gn2 wrote:That ONLY occurs if physcial RAM is insufficient and tasks are VERY memory intensive.
Gn2 is also right.

Maybe you heard something else and you wrongly interpreted the other way arround

Regarding the size of the partition:
If you NEED a large swap partition you'll most likelly experience a lot of trashing.

that is different than

If you HAVE a large swap ...

Regarding the multiple swap partitions

Maybe you heard that if you have multiple swap partitions in DIFFERENT HDDs you may get better swap performance.

If you create multiple swap partitions, the situation can only degrade as fragmented files take longer to retrieve than files that are in a continious space.
[url]http://rarsa.blogspot.com[/url] Covering my eclectic thoughts
[url]http://www.kwlug.org/blog/48[/url] Covering my Linux How-to

User avatar
Gn2
Posts: 943
Joined: Mon 16 Oct 2006, 05:33
Location: virtual - Veni vidi, nihil est adpulerit

#17 Post by Gn2 »

Puppy is NOT generic use of Linux - the strengths also limit how it may be used

Care to Sizing of Swap partition/s makes (temporary storage) fragmentation (non-contiguous sectors) highly unlikely

Careful partition considerations at O/System install time, of placement of any sub folders in dedicated optional partitions
ESP if for Swap - even on same drive - will enhance seek & execute load times.

Locating a swap partition on drive other than root file system frees CPU time slices = the thread forks, true multi-tasks.

USE of tmpfs is explained HERE
Please refer also to Maximising Swappage > & use of niceness options.

Prioritizing (see man/info nice) swap usage in conjunction w/tmpfs goes far to enhance system responce
These benefits may be - depending on use and Cfg of platform - little noticed or critical.

Placing /tmp in RAM (Puppy) is very unwise.- there is already limitations due to pivotal mounting & unionfs.

= Puppy may be modified - :wink: but then is NOT Puppy !

ndujoe1
Posts: 851
Joined: Mon 05 Dec 2005, 01:06

Linux Swap and OpenOffice .sfs puppy 2.15CE

#18 Post by ndujoe1 »

After reading the postings on the Linux swap partition issue I must confess that I am thoroughly confused.

When I installed the Open Office .sfs file in Puppy LInux 2.15CE setup with a live CD a personal file size of 1 GB. 256 MB of ram. The Open office application got to the boot up screen but nothing happened thereafter.

MU suggested in a posting that I install a swap partition and then Open Office will operate properly.

I was going to use the 2 x ram that I saw elsewhere but now I am not sure and don't want to complicate things or compromise my hard drive life. It is a 40 GB hard drive.

Any guidance at this point. Thanks.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#19 Post by Flash »

Don't worry about it. With 256 MB of RAM, Puppy won't need to use the swap memory much, if ever. Just make a 256 MB swap partition and see what happens. If you make it bigger, the worst that will happen is that most of it will never be used, and you will have effectively lost that much capacity of the hard disk drive. Still, better to have too much (swap) memory than not enough. :)

Sage
Posts: 5536
Joined: Tue 04 Oct 2005, 08:34
Location: GB

#20 Post by Sage »

Careful reading of the foregoing suggest that you start with a single swap partition of 256Mb. If you see/hear lots of disk thrashing, you could try increasing the swap to 512Mb, but, since RAM is so incredibly cheap, adding another 256Mb of RAM would give better results overall, unless you have the SiS735 chipset which doesn't like two sticks of SDRAM and sometimes ditto DDRAM.
Notwithstanding, Puppy is a bad choice for really big apps like OOoo - it was never intended to be other than a compact distro (cf. Gn2 above). Fedora7, out last week would be an excellent choice if you don't want fancy 3D graphics, otherwise MEPIS or PCLinuxOS are well liked. If you want the bees knees in graphics use a distro that has no connection with the restrictive laws of the USA.
By-the-by, this Forum needs Gn2 around to spice up the discourse and lend a little culture to events as well as erudition. Come in Gn2.

WARNING: This comment " Still, better to have too much (swap) memory than not enough. :)" sneaked in whilst I was penning a considered reply. It is not only wrong, a total misunderstanding of all the preceding discussion, but I hope anyone following it will use the County Court to extract the cost of a new HD from the perpetrator.

Post Reply