Ask Slashdot: Linux and Swap Optimization? 176
I found a nameless submission in the
submission box that asks a fairly good
question:
"I'm installing Linux for the first time on Intel
hardware (I've installed Linux for PPC and BSD for Intel
and 68K) but I am confused on how the swap partition
should be handled for optimum performance. The Linux
Installation Guide says I should have my swap at least as
big as my RAM and that the swap partition should not be
bigger than 127MB. Also a "rule of thumb" answer I got
from my BSD using friends is that my swap should be twice
the size of my RAM. Since I have 128MB of RAM should I
have two swap partitions? Also how will swap drive
performance affect system performance? Would a Fast SCSI
(20MB/s) swap drive be any different than a Wide SCSI
(40MB/s) swap drive? There seems to be little information
on how to 'tune' Linux swap for machines with 100+ MB RAM."
Speed thrills (farce pest) (Score:1)
Amount of swap: Disk speed counts here as well. If you have fast disks, swapping does not degrade your performance as much as with slower drives. In any case, if you find that you need 128 MB of swap normally, your real problem is that you don't have enough RAM. Get more. In practice, 64 MB swap should be plenty, but it depends on what the machine does. Even with too much RAM, it will swap out a small amount. This is OK. If you are swapping IN (and out) a lot, you need more RAM.
If you have two controllers and two disks, go with two 32MB swap areas; if they are greatly different speeds, you may want to give them different priorities, experiment. If you have one controller, use one 64MB swap area. If you're really paranoid about it, add another 64MB swap area on another disk; that much disk space is an insignificant fraction these days.
hmm... (Score:1)
MemTotal: 156332 kB
MemFree: 102704 kB
MemShared: 13100 kB
Buffers: 20896 kB
Cached: 17636 kB
SwapTotal: 34236 kB
SwapFree: 28972 kB
my swap is around 1/4 the total RAM and my machine has never been able to fill it up. When i copy 8GB from one drive to another the RAM often fills with HUGE buffers but the swap seems to remain constant. My advice : use 127 MB of swap if you have it, but you shouldnt need it. normally try for a swap partition which is 1/4 the total RAM size if you have 128+ megs of RAM.
Re:Speed thrills (farce pest) (Score:1)
by the way, the fastest ultra66 IDE disks I saw couldn't do more than 15MB/sec. considering the huge performance hits 2 devices on one IDE channel, why does ultra66 exist (or ultra33 for that matter)? marketing hype?
just my $0.02...
Dave
Re:Speed thrills (farce pest) (Score:1)
SCSI on the other hand is designed for high speed and efficieny. Also 80 MB/s SCSI is not the fastest, SCSI 160 gives (not entirely surprisingly ) 160 MB/s. Given that the fastest SCSI disks can perform at 40 MB/s SUSTAINED you need only 4 of these in a RAID 0 to saturate the bus. At that point you have already saturated the 132 MB/s PCI bus in its normal configuration (32 bits, 33 MHz). Check the Multi Disk HOWTO for discussions on busses and speeds.
Swap Drive(s)and SCSI Performance, Swap Priorities (Score:2)
There are a few things to keep in mind.
The first and foremost is that no single hard drive can transfer more than about 10meg per second (at least when I last researched it a few months ago, I haven't heard of anything faster than 10k rpm drives so I think it's still accurate).
So, if using one hard drive the difference between the 20 MB/s and the wide 40 MB/s would make absolutely no difference - the 20 MB/s would never be exceeded.
That figure (20 MB/s or 40 MB/s) is the capacity of the SCSI bus. SO, if you put three drives in the box, then the possible total transfer rate of 30 MB/s _would_ make start kickin' in.
So don't waste your money on a Wide controller or Wide drives (40 MB/s) unless you plan to eventually have more than two drives on that controller.
As far as swap priorities go, use the same priority for multiple swap partions on different drives and different priorities for multiple swap partitions on the same drive.
For a single swap partition on each of different drives the idea is that with the same priority the kernel is supposed to automatically "stripe" the usage of the partitions (i.e. use all the drives at the same time and make the total transfer rate higher).
For mutiple swap partitions on the same drive the idea is to have different priorities to different partitions so that it is "guaranteed" not to try to write to the parititions at the same time (since on the same drive it would slow things down overall since the drive can not write to multiple areas of the drive simultaneously).
For multiple swap partitions on multiple drives you combine the above two. The first swap partition on each of the multiple drives should be given a priority. The second swap partition on each of the multiple drives should be given another priority.
(And yes if you want more than 128MB of swap space you need to create multiple partitions each of size 128MB or below.)
Lastly, the rule of thumb "swap >= twice the amount of physical RAM" assumes you'll swap and came about in the golden days when RAM was minimal and expensive.
If you don't expect to actually be using all of the 128MB you might not even need swap partition(s) at all.
Good luck,
strcat!
"One World, One Web, One Program" - Microsoft Promotional Ad
"Ein Volk, Ein Reich, Ein Fuhrer" - Adolf Hitler
It depends (Score:2)
Basically, if you're liberal, you'll want to figure out how much memory you'll use at peak, multiply that by 1.5 to be safe, and make sure swap is at least that. More swap never hurts performance, so if you don't care about money, you may as well have an arbitrarily large amount.
For a (minor) performance benefit, you'll want swap to be the size of the total memory you use at peak, instead of having memory+swap be that size. Linux has fairly aggressive memory management; during idle cycles, it often writes out a copy of a page before it runs out of memory. It keeps a copy in memory and remembers if it's 'dirty.' That way, if it suddenly needs more memory, it can dump those pages from memory instantly without needing to write them out.
Likewise, if you accidentally allocate too little, you're also not too badly off. Like Windows, Linux supports swap files. Unlike Windows, you can add swap files dynamically as the system is running. Should you ever run out, you just make a swap file, and you're fine.
If you're conservative, or on a lower-end system, figure out how much memory you'll use at peak, and go with that as a total for memory+swap. Add/increase swap files as you need more.
Why use swap partitions instead of swap files at all? They're a bit faster than swap files.
Personally, I have 64mb RAM, 64mb swap, and I've never run out, but I only do e-mail, zephyr and light browsing locally. If you do more, you may want as much as 256mb total. If you do 3d rendering, animation, or work with large graphics, then you probably know how much more you need.
- pmitros
Re:Tune to linux-perf (Score:2)
Majordomo@www.klinik.uni-mainz.de
subscribe linux-perf
Application dependent (Score:3)
is really very dependent on the intended
use of the machine. I administer machines
being used as multi-user systems by physicists.
Unfortunately, this means that occasionally, and
quite unpredictably, I may have a user launch
a REALLY big job(~350+ MB). Or I may have
several launch moderately big jobs(10 users x
~50 MB). Needless to say the result would
not be pretty if I followed many of the
recommendations here.
What is far more useful than a simple recipe
would be some reasonable explanation for
new users of WHAT swap does, how it works
under linux, what user memory footprints tend to
be like, and bringing it all together to give
some notion of what your swap + memory needs
are.
For example, typical light users in my
environments can be expected to be running
netscape (footprint ~20MB), ghostview (~3MB),
and some other stray programs (~5 MB). So
my safe estimate on light usage is a 40MB
memory footprint per user. It's not
unusual for my more heavily used machines
to have 20 such users going at a time, so
I need to support a ram + swap in the 1 Gig
range. All of this is based upon a cursory
examination of the UltraSparcs I deal with.
What would be helpful would be for someone in the
linux community to start putting together
some carefully researched information
about program and user memory footprints.
Re:Swap Files and Linux... (Score:1)
You partition the second drive to have a 128 meg swap partition and point the kernel at it in
Lets say you have 64 megs o' swap on the second partition of hda yer
/dev/hda2 swap swap defaults 0 0
like so.
If yer second drive has a 128meg swap on partition 2 youd change
/dev/hdb2 swap swap defaults 0 0
You could also just add an entry for the second swap partition then do
#swapoff
#swapon
and that would give you 64+128=192meg
Re:Linux and Swap Optimization? (Score:1)
http://www.klomp.org/mod_roaming/ [klomp.org]
-- Does Rain Man use the Autistic License for his software?
A bit more about how swap works (Score:1)
Swap on soft RAID (Score:1)
Re:USE SWAP FILE (Score:1)
Re:Swap Files and Linux... (Score:1)
Re:I don't know much... (Score:1)
And, if you have only 2 drives and 4GB of memory, I suggest you spend a little cash on another drive.
_damnit_
Rules of thumb. (Score:1)
Of course, the problem with rules of thumb is that not all thumbs are the same.
Ideally, you don't want any swap space at all. In practice you have to look at how much virtual space your applications need, and then decide how much of that space you can afford to represent with real RAM.
If you need a peak value of 256 megabytes of memory to do what you want, and you have 64 megabytes of RAM, then you will obviously need 192 megabytes of swap space. If what you are doing won't run well unless all 256 megabytes are real RAM, then you will have to get 256 megabytes of ral RAM, in which case you then won't need any swap at all (but you can always have swap for the hell of it for for emergencies).
Whether or not it's efficient to meet needs with a large amount of swap depends on the locality of memory references within the applications you are going to be running. Some applications simply won't run well if you don't have actual RAM, others might. Applications that have a small access pattern, but large memory usage (because, for instance, they have nasty memory leaks
So there is no one-size-fits-all rule of thumb; you have to consider the nature of the application. First estimate the memory usage, trying to err on the side of too high rather than too low. Then based on the application type, determine how much swap is sufferable. Perhaps as little as one fourth of the total requirement needs to be physical RAM. Or maybe the whole thing has to be RAM.
Also, simply set a low cutoff limit based on the RAM market. For example, these days, you might want to assume that there will be 128 megs of real RAM no matter what and proceed from there.
Re:End of disk? (Score:1)
128MB is just fine (Score:3)
Think about it: What would you do with more than 128MB swap space? Swapping at all is very bad; swapping a couple hundred megs is pretty catastrophic!
On low-end machines, a 128MB swap would be 2x or 4x the size of your RAM. That's plenty of extra room for X, Emacs, whatever bloated thing you're running.
On medium-end machines, a 128MB swap might be double your RAM, and...well, why not?
On high-end machines and servers, you don't want to ever swap. Disk is just too slow. However, the algorithms in the kernel are kinda tuned on the assumption that you have at least a bit of swap space. The buffer cache, for example, might not shrink fast enough when you need the RAM for some fast-growing process. So stick a small swap (like 128MB) on the machine to keep some balance in the algorithms, but hope you don't have to use it too much.
Do you see a pattern? Just go with 128MB. It should be just fine.
Re:placement (wrong reason for correct placement) (Score:1)
Each sector (the individual pieces of pizza from the above illustration) is able to contain the SAME number of bits of info, NO MATTER WHERE IT IS ON THE DISK. This is done to make the rate of reading and writing from/to the disks a constant no matter where on the physical platter you are.
There IS a reason that putting the swap partition on the outter most sector increased performance...
Because sectors are almost allways numbered starting on the outermost tracks of a partition, if you have only 2 partitions then you can optimize the swap performance. The first partition would be swap (note this if for smaller disks, where the
This will not be all that effective however, if you have multiple partions that are all accessed frequently. If you have
The assumption that rotational velocity has anything to do with it is wrong; the placement of the swap partion is correct for basic partitioning scheams.
Re:There are many beginnings... (Score:1)
snippet begins------------------------
The variable density of the data storage on platters makes the rotational velocity moot. On the outermost tracks, data is less dense than on the inner tracks. The image of the subdivision of a platter into sectors is a pizza cut perfectly into slices, and then concentric circles are cut through the slices.
Each sector (the individual pieces of pizza from the above illustration) is able to contain the SAME number of bits of info, NO MATTER WHERE IT IS ON THE DISK. This is done to make the rate of reading and writing from/to the disks a constant no matter where on the physical platter you are.
--------------------end snippet
WindowMaker vs. KDE flame bait... (Score:1)
My swap partition on a box with 128Mb RAM is a mere 32Mb and I've yet to see more than 2Mb swapped. So why waste the disk space?
Yet with KDE, I regularly swapped up to 48Mb and beyond.
Ok, so it's not NT (which bloody swaps even when no apps are loaded!) but why the huge differences? Is WindowMaker really that light?
I bed to differ... (Score:1)
The largest I've had my swap file is a 128Mb partition and with WindowMaker, I've never seen it use more swap than with 32Mb.
You could well be right but in julesLand, it doesn't seem to be working that way!
There are many beginnings... (Score:1)
<tim><
Re:There are many beginnings... (Score:1)
Each effective side (ES, let's call it) has a beginning and an end. As you say, data is written from the outside in. But you have 4 different beginnings and endings with 4 ES's, each of 250 megs. So I can either put the swap at the first cylindar, or at the 250st megabyte boundary, or the 500th meg boundary, or at the 750th meg boundary. You'd have to do some calculations to figure out exactly which cylander this is at (since most disks aren't exactly 1 gig in size) but I think it'd be the same.
I have no technical background in this area, so forgive me if I'm missing something totally obvious. Let me know if I'm wrong.
As for why benchmarks show that reading/writing at the beginning of the disk is faster, it's because it *is*. But that's b/c we're comparing reading/writing at the beginning of the disk to anywhere else on the disk So of course, the second way is slower. However, I think that there exists more than one fast location on the disk--at the beginning of each ES.
<tim><
Re:Put on different disk (Score:2)
ive heard of people getting up to 10% system higher system performance with this method
Swap performance. (Score:1)
If you are going in to swap then use about twice the amount of swap as you have memory and spread the partitions across as many disks/channels as you can.
Re:making swap 2x Physical memory... (Score:1)
The more swap the better! (Score:5)
With Linux kernels previous to (I believe) 2.0.36 you must make each swap partition no larger than 128M, though you may have an arbitrary number of swap partitions or files (and yes, Linux can use swap files in the filesystem instead of individual partitions, but at a performance penalty).
Older 2.0.x, 1.2.x, and 1.0.x kernels must use individual 128MB swap partitions or files (actually, I seem to recall that 1.0.x kernels didn't support swap files, only partitions), but don't know if the larger swap partition support is limited to 2.2.x kernels or the later 2.0.36/37 kernels.
Now for why I like lots of swap: You don't have to use it, but when you need it you REALLY need it! Your VM space is only as large as core and swap. Yes, I know the kernel can address anywhere within the 4GB boundary, but the total number of usable pages is limited to your physical RAM plus swap space! This is important to consider if you ever want to run lots of processes which sleep until asynchronous I/O events wake them up. If you want to start lots of processes and let them go off to sleep, having plenty of VM space makes sense. The machine will only thrash if there's memory contention among processes in a run state, so it's safe (and desirable) to let sleeping processes page out to swap while the machine uses physical core for running code.
Also: consider the possibility of a small application using huge datasets. I run into this at work all the time. We have clustered machines each with 1/2GB of RAM and 1GB of swap. As long as each process only keeps dirty pages of the dataset in core, one can have multiple program instances crunching through different datasets even though together they're exceeding total physical core. Since these programs are stepping linearly through the data, instead of randomly seeking different pages like in a program doing long jumps, this can actually work well. Memory contention occurs not when you exceed total physical ram, but when running processes request pages that have been flushed to disk!
If you're careful and selective about how you use the extra swap space you can wildly exceed physical core without significant performance loss. Food for thought.
Re:The more swap the better! (Score:2)
1. to swap out all the inactive daemons, etc when a user process(es) comes close to using all of
physical RAM. This can use up to 30M or s of swap on a typical system,
2. for large stopped jobs (or interactive jobs waiting for input) -- it is sometimes nice to be able to have thee or four processes as large as physical RAM, even if only one of them can execute sensibly
3. For the very rare user with a LOT of time and a problem that won;t fit in physical memory
and no we can't buy more memory -- it won't fit.
I don't know much... (Score:1)
For maximum performance out of your swap space, you probably want it closer to the beginning of the disk. Of course, if you don't do much swapping to disk then filesystem performance may be more important to you, so in that case the swap partition should go closer to the end of the disk.
You probably won't really notice a difference either way, though.
Re:you want swap (Score:1)
And memory gets even more important with a multiuser-system. My personal "internet-connected" computer eg has 48mb ram, 128MB swap, 30 users and needs around 70mb swap after one week or so even without X. (ok, squid, qwsv and up to 20 screen-session eat quite a lot
Linuxperf website (Score:2)
http://www.nl.linux.org/linuxperf/ [linux.org].
If you want to help with the site, subscribe to the linuxperf@nl.linux.org mailing list by sending a message to Majordomo@nl.linux.org [mailto] with "subscribe linuxperf" in the body of the message.
Finally an answer... (Score:1)
Note: The linux folks out there need to adjust what they think is a reasonable machine, and provide some guidelines for us who like max things out in a box. I can see the swap guidelines applying to people putting Linux on discarded Pentiums, 486's and non-G3 powerMacs... but there needs to be some guidelines for those of us who buy/acquire/build machines that have wicked fast CPUs, normal Hard Drives (even though they may be of capacities barely heard of a few years ago) and enough money to buy decent amount of RAM (Esp with 128 MB DIMMs going for around $100 a pop, it's easy to get large amounts in a desktop machine).
So basically, after reading all the posts, the concensus is: Use 128 MB no matter how much RAM you have if you're using a single user machine, and don't really worry about it (assuming the use of an old kernel that only allows a 128 MB swap file), or the same size as your RAM if you're using a newer kernel.
On server level machines, or machines that are to be used as servers, you need to do a little more analysis based on how the machine will be used.
Anyone want to verify this?
Put the swap at the beginning of the drive (Score:2)
Tune to linux-perf (Score:4)
To subscribe, send email to majordomo@www.klinik.uni-mainz.de and put "subscribe linux-perf" (without the quotes) in the message body.
Re:WindowMaker vs. KDE flame bait... (Score:1)
My observations... (Score:1)
Sincerely,
Nelson Rush
Re:Faster swap at front of drive (Score:1)
The real answer is that it's manufacturer dependant. The SCSI/IDE command set doesn't specify when I seek where the head will wind up physically. Right now I have queries in with both Seagate and Quantum over this issue because I'll be tuning a new server in the next few days.
--
Multiple swap partitions. (Score:1)
Assign the same pririty to each partition on a diffrent disk....
ie:
3 disks with 6 partitions...
the first partition on each disk at priority 1 then the second on each disk at 2...
Hop this helps!
"There is no spoon" - Neo, The Matrix
"SPOOOOOOOOON!" - The Tick, The Tick
It depends... (Score:1)
There is plenty of reasons for going above 128MB swap. I have (well, the department here has, but I take care of them) a cluster of dual-PII:s with 256MB physical memory and 1GB swap each. I have seen many programs here eating around 600-700 MB of memory, the top notation was a Matlab script using close to 1 GB of memory. Yes, the script was carefully written to avoid thrashing. On the other hand, I have also seen programs using "only" about 400 MB that thrashed like h*ll.
Yes, we're about to buy 1 GB of memory per machine, we really need it. Problem is that with these fscking PC:s you can't have more than 1 GB. We don't really want to buy a Sun Enterprise or an Alpha, since we're trying to move to all PC:s, so I guess we'll have to wait for the Xeon machines to become common.
Our department is into research in coding theory and cryptography among other things, and the simulations for this kind of stuff are huge. One of our professors want to run a program which needs 4 GB of memory and 20 GB swap, and so far we haven't found any machine which can manage that.
Put on different disk (Score:1)
USE PLENTY OF SWAP!! (Score:1)
In all seriousness my rule of them is:
Twice the amount of RAM or 256M whichever
is smaller.
My primary workstation has 256M of RAM and 256M of swap and I have actually allocated all of my RAM and half of my swap before. They occasions this happens are rare, but imagine if I didn't have the swap there!
I used to run Linux on a P90 with 16M of RAM and 32M of swap and I can rember programs crashing because of running out of memory. I don't ever want to deal with that again.
If possible use a high speed drive, but the most signifgant factor is haveing plenty of RAM. I will never build a box again with less than 64M and anything for development use will have a good 128M if not 256M.
-Alan
Re:Tune to linux-perf (Score:2)
--
Re:Swap Files and Linux... (Score:3)
So if I'm running a 2.2.x kernel and a 64Mb swap partition, and say I wanted to make it 128Mb on the second drive, what would I need to do to change it?
make a new partition on the new drive (use fdisk or whatever), make that drive type 82 (correct me if I'm wrong but the correct type for linux swap anyway), format that drive (mkswap?) and swapon it (or put the appropriate entry in /etc/fstab).
there you go. easy peasy
Re:Swap Files and Linux... (Score:1)
you want swap (Score:1)
End of disk? (Score:1)
Re:I don't know much... (Score:1)
I had problems with Solaris 2.6 where I couldn't assign a priority to the swap areas. Compounding the fact is that Solaris has a 2GB max swap size per parition. This makes it difficult to have 2x physical RAM as swap on a system that has 4GB of memory and only 2 disks!
Oiy!
James
Same here. (was:Re:USE PLENTY OF SWAP!!) (Score:1)
Swap Files and Linux... (Score:4)
You asked three seperate questions, so I think I'll answer them in order:
First off, the 127MB limit was for the older 2.0 series of kernels. The new 2.2 series (and dists based on them) has a much higher limit (I can't remember exactly what is it, but it's ALOT bigger (maybe like 1GB or more)). So, you can make a single swap partition of 256MB or so. If you are using a 2.0-based dist, you should make multiple partitions, each no bigger than 127MB.
IIRC, linux is like the newer Solaris 2, IRIX, and HPUX systems in that swap space is added to physical RAM to come up with the Total Virtual Memory allotable on the system. Under older BSD4.2-based systems (I don't know about current Free/Net/OpenBSD stuff), swap space equal to physical RAM was used to "shadow" the physical memory (and improve swap performance), and thus your Total Virtual Memory was equal to the amount of swap space you had.
For Linux 2.2, the rule of 2x physical memory is perhaps a bit overkill. I prefer the Solaris guidelines: you should have at least 128MB of total swap+physical for a typical end-user system, with 256MB for a developer/power user, and 512MB for someone using high-end graphics (the X-server gets big) or doing serious work. The point here is: swap space is slow. You should have enough swap space to hold applications that you aren't currently using, but huge amounts aren't useful (unless you have an application that likes to map large amounts of Virtual Memory, but doesn't actually use it). For most of us, I think no more than 256MB of swap is best.
Swap being slow, putting your swap drive on the fastest possible disk is a good way to enhance performance. In your case, the performance characteristics of the drive are more important than the interface. Thus, a new drive (6.5ms / 10,000RPM) with a FastSCSI interface is preferable to using an older drive (perhaps 9ms/7200RPM) with WideSCSI. Striping swap is also a good idea, though you should use drives of similar speed.
Also, note that linux can swap to a file, as well as to a raw partition. However, swapping to a partition is faster, and preferable.
-Erik
Re:USE PLENTY OF SWAP!! (Score:1)
Yes, Netscape is the only app I use that seems to take memory and not give it back. Eventually I have to shutdown Netscape (or wait for it to crash) and then re-launch it...
When swap space is in need the machine definitely begins to crawl.
Re:WindowMaker vs. KDE flame bait... (Score:1)
Re:The more swap the better! (Score:1)
SWAP (Score:1)
Re:I don't know much... (Score:1)
Re:This should be an FAQ (Score:2)
It only used 60MB with all this running and doing a full kernel compile with -j on my SMP box. (load up to 35, yikes). I did get some "gcc: vfork: Resource temporarily unavailable" messages during the make -k modules, but I had plenty of swap left so it must have been processes or something. Had to limit the concurent jobs to get it to go.
I'd say, tentatively, that if you have 256MB RAM you probably don't need more than 128MB unless you're doing some serious number crunching. And, you'll probably run into other issues also. I've got two 127MB partitions on separate SCSI channels just to be sure...
Size your total Virtual Memory, NOT swap space! (Score:3)
All the guidelines for sizing your swap space based on your RAM size are misleading. On some old Unix systems (SunOS 4, I think), physical memory HAD to fit in swap (to do a core dump) and you usually wanted some extra. I think this is the origin of the "double the RAM size" recommendation for swap space. Under Linux (and I think Solaris and many other systems), the swap space is used for overflow for whatever doesn't fit in physical RAM. Your total Virtual Memory (VM) is the sum of your physical RAM and all the swap areas.
The best way to size your swap space is to decide how much total VM you want, then subtract your physical RAM. If you have 64 Meg of RAM, and you feel that's enough VM, nothing says you need to create a swap partition. If you want a gigabyte of VM, add enough swap to make up the difference. It all depends on what you want to do with the computer, and how much disk space you're willing to allocate.
Forget about RAM-to-swap ratios and just focus on total VM. Consider that an old Linux system with 16 Meg of RAM and 32 Meg of swap (double the RAM) had 48 Meg of total VM. Such a machine has less total VM than a newer machine with 64 Meg of RAM and no swap. Your limits will be determined by your total VM, not the ratio.
Ideally, you'd have enough RAM for your total VM needs and no swap -- it's the fastest. Realistically, you'll want far more than average occasionally, so it's best to have at least some swap. Since disk space keeps getting cheaper, allocating a few hundred megabytes doesn't usually hurt much...
another add_on question (Score:1)
I'm building a small server here and all i want is reliability not speed. So how would it look like having a swap file on a raid5 partition?
Re:I don't know much... (Score:1)
Swap Schmapp.... (Score:1)
Guess what? I've run out of memory once in the last two years. Once. That was when I was trying to use SNiFF+ to parse the 2.2 kernel...
I'm not advising you to use as little swap as I am. It's probably too little, especially considering the way app requirements are shooting up all around these days. However, if you're setting up a workstation here, fuggeddabout the multiple F/W LVD SuperSCSI VII Widgetco hardrives and just set yourself up a nice, comfy 64MB partition anywhere on the drive you want. I'm betting it doesn't get used 99% of the time anyway.
Servers, on the other hand, are a different story...:)
Re:The more swap the better! (Score:1)
> I'm one who believes in investing as much disk to swap
> as you can afford. 2xRAM is my minimal swap space.
I've got a AIX boxes with two- to eight-gig of real memory. There's no way I could justify putting in 16-gig of swap space. Nor would I ever need 16-gig of swap space. My applications would come to a grinding halt if ever that much memory was swapped-out. Even on 10k rpm SSA drives, it takes a long time to write 16 gig of data.
While your argument has merit, encouraging folks to have at least twice as much swap as physical RAM all willy-nilly is irresponsible. Disk space may be cheap now days but it certainly ain't free. (I wish it were; so many MP3s, so little disk space.)
Folks need to examine what their RAM is used for and what their swap will be used for. In my case, I'm running Oracle. Most of the RAM is used for Oracle to cache data and not for the application itself. In my case, under 340 meg of RAM is actually a candidate for swap and thus I've set aside 512 meg for swapping. And I don't think that has ever been touched.
As the amount of memory in computers expands, old rules (swap must equal RAM; swap must be 2x RAM, etc.) need to fall aside to common sense.
Matt
Re:I don't need no steenkin' swapspace (Score:1)
Re:I don't need no steenkin' swapspace (Score:1)
Remember: Free memory is wasted memory!
0.5gb ram and 64mb of swap (Score:1)
MemFree: 4308 kB
MemShared: 24236 kB
Buffers: 11744 kB
Cached: 384104 kB
SwapTotal: 64492 kB
SwapFree: 48736 kB
I would have posted 'free' output, but it didn't fit right. Anyway, I have on the average, 110mb ram used on this 512mb machine. Usually about 8 xterms open with 10000 lines scroll back (not that much memory actually), netscape with a 30mb memory cache (no disk), still goes just fine.
I usually don't see swap until a few days of uptime and to be quite frank, I don't know why it would touch swap with this much ram (usually 400mb left over before buffers/cache)
--
Re:Swap Files and Linux... (Score:2)
1. if you have multiple swap partitions and explicitly set the same priority in your fstab, the kernel will stripe the VM amongst these partitions, increasing performance quite a bit. You should _not_ make a softRAID array of your swap partitions.
2. "Swap space is slow so put your swapspace on your fastest disk" is true, but could be misleading: the slow thing in harddrives is the seek time, not the transfer tiem. So you should put the swapspace on your least used drives in general (unless there is so much difference between seek times from the fastest and the least-used that it makes sence--ymmv).
Also, you could have a cron job that checks for the amount of free swapspace, and adds|removes
swap files as necessary. As in, say you have 128MB of RAM (as you do). You create a 256MB swap partition, and [if your free swap drops below 32MB you create a new 64MB swapfile (with a lower priority than your swap partition--that's the default), and if your free swap grows beyond 112MB you remove the last swapfile] (cron the []). It works, and it could save your day sometime...
Re:Application dependent (Score:1)
--
Poor man's supercomputer: 64-node Beowulf using white box commodity PC's, Node 65 with 19" monitor, 3x24-port switches, wiring, total cost, less than $50k. Less racks and that monster power/cooling requirement. Think about it.
Re:Obsolete 128 Mbyte limit (Score:1)
"It is roughly
2GB on i386, PPC, m68k, ARM,
1GB on sparc,
512MB on mips,
128GB on alpha
and 3TB on sparc64."
It also mentions that the kernel grabs two bytes of memory per page of swap, with the result that you might end up using 2Mb of physical for a 2Gb swap file.
Questions re partition selection. (Score:1)
Is it ok to use a logical partition?
Should you use a partition allocated near the middle of your drive?
Re:I don't know much... (Score:1)
There is no clearly defined beginning to a disk. However, location wise on the disk's surface, it would make more sense to have the swap on the tracks closest to the centre of the disk, however, IDE disks use a variable track density and so this philosophy is actually incorrect. Therefore, in conclusion, it makes no different where on the disk the swap goes (as long as it is ofcourse a contguous allocation
just thought I'd point that out.
I can see the advantage to having swap partitions on different disks, but what about adjusting the system buffers. The kernel uses a lot of buffering on my PII (128 Mb RAM) - perhaps there is a way to fine tune the way in which RAM is used also?
-- "Don't try to be a great man, just be a man."
-- Star Trek, First Contact
Re:Wrong again (Score:1)
This should be an FAQ (Score:1)
Anyway, it depends on how much memory you have in your machine and what you plan do run on it. Here's my rule of thumb. For 8 MB up to 64 MB RAM, make a swap partition twice the size of the RAM. For larger RAM, just make swap 127 MB, since it's the limit for a single partition. If you have more than that amount of RAM, 127 MB swap is still fine - remember, you've got lots of RAM.
(One person's opinion was just go ahead and start off with 127 MB swap no matter how much RAM you have because it's too hard to increase the size after it's been created. I wish I had heard this before I configured my machine.)
However, if you really need to have several LARGE programs running at the same time (Netscape and StarOffice and KDE and... a few other big things) then you need more RAM than 64 MB (try 192 for starters). If you really need all that swap, adding more is only going to slow things down more, even if it's on another disk - after all, a drive is slower than RAM...
Still, I'd like to know myself what rules of thumb there are for large memory machines (256 MB and higher). I can't imagine the rules for swap in small RAM machines continues to hold.
Re:Put swap as last partition (Score:1)
The same applies to a hard disk (not CD-roms, most of them do have a variable spin). A hard disk spins at a fixed rate of speed. There are the same number of sectors on each track, therefore it will take the same amount of time to read a sector on the inner track as on the outer track.
This being said, there could still be some performance improvements on locating the swap file/partition at different areas of the disk. For example, placing it as close as possible to the most-often accessed data would certainly reduce the time it takes the head to seek to the appropriate track.
A good rule of thumb is to place a swap file on the most used partition of the least used hard disk (assuming a file and not a partition). For a swap partition, place it as close as possible to the most used partition on the least used hard disk.
I don't know how the ext2 filesystem allocates space, so I can't state whether the swap partition should be close to the outer edge of the ext2 filesystem or the inner edge. Perhaps someone who knows could respond.
Jonathan Bayer
I don't need no steenkin' swapspace (Score:2)
Oh course, if I were running a server, I'd keep the 128MB, just in case. But I don't. Next time I reinstall Linux, I'm reducing the swap to 32MB (just in case...).
Solaris and Swap (Score:1)
Re:There are many beginnings... (Score:3)
It writes in parallel. That, plus higher media densities, plus higher rotational speeds == faster disks.
Put your swap on the lowest numbered cylenders that you can if you want the fastest swap. I have yet to hear of a modern drive whose cylenders are not marked starting from the outside of the disk working into the center. There are two reasons the outside of the disk is faster.
1. Rotational Speed -- More media passes the heads in one rotaion on the outside tracks. The media density is constant accross each platter, so the amount of disk real estate passing under the heads at any position is relative to the heads' distance crom the center of the spindle. If you think of each track as a line, then the length of each track is 2 * the_distance_from_center * PI.
All this means the disk's maximum throughput is realized when readin/writing to the outermost tracks.
2. Relative position -- It is obvious that the majority of the data on the disk resides near the outside edge of the disk. Also it is obvious that an equal sized partition will will take up more physical cylenders if it is positioned toward the center of the disk. More physical cylenders = more average distance for the heads to travel when seeking from one block to another when reading/writing non-contiguous blocks.
This means that the lowest average seek times for a given partition will be realized if that partion is located at the outer edge of the disk.
If you think that position doesn't make a difference, I have bonnie (a disk benchmarking program) data to back my words up. On some drives, the difference can be huge. That is why the Mindcraft benchmark, where they had both OSes on the same drives, was such a joke as far as disk IO was concerned. Can you guess which OS was on the outside of the disks (first cylenders)? (I'll give you a hint, it is not the OS that allows you to put its / partition at any location on the disk. Another hint, the OS's name starts with an 'N')
Two more things that others have said, and I would like to reiterate and add to. Put swap on multiple disks, even if there is a disparity in disk speed from one to another, and even if you only want 32MB of swap. And SET THE SWAP PRIORITIES TO AN EQUAL NUMBER BETWEEN SWAP PARTITIONS ON SEPERATE DRIVES! Some folks seem to think Linux does RAID0 for swap automaticly, but it does not. You must set the priorities or swap will be written in a serialized manner. (i.e. -- Filling up one partition before starting to fill the next.)
And finally, no matter how much RAM you have, have at least a little swap. Why? Every inactive process Linux swaps out makes more room for disk cache and buffers. On a box with 512MB that you are using as a workstation, 32MB of swap is probably fine. Linux has a real memory management system, don't tie its hands by not giving at least a little swap.
And that is my sermon for the day.
-Paul
Re:SWAP (Score:1)
Put swap as last partition (Score:2)
LL
Adding Swap: 104416k swap-space (priority 2120) (Score:1)
Adding Swap: 104416k swap-space (priority 2120)
This started when I went to a kernel level higher than 2.0.0. When I was at 2.0.0 and lower, I get a swap priority of -1.
Any idea why this might be happening?
My /etc/fstab swap partition is defined as such...
Thanks!
david
Re:Swap Files and Linux... (Score:2)
And now a follow-up question:
Can you/how do you make changes to your swap setup after your system is already installed?
I think I went with the "recommended" 2x RAM size way back when my machine only had 32Mb and one HD. Now I have 128Mb and I've upgraded my primary drive and have the old one set up as a slave for temp space for CD burning.
So if I'm running a 2.2.x kernel and a 64Mb swap partition, and say I wanted to make it 128Mb on the second drive, what would I need to do to change it?
Re:>1 is the best way to go. (Score:1)
-Bigdaddy
"You can't get a blue screen on a monochrome monitor!"
Re:Second Post!! (Score:1)
First reply to the first reply to the second post!
Re:Put the swap at the beginning of the drive (Score:1)
So minimazing seek time (like, putting swap in the middle of the disk - but it really depends on your partition configurations and access) will yield much better speed improvements (esp. when disk is busy, as it almost always is when you start swapping)
much things affect this, as RAID stripping for example, so YMMV.
Re:Size your total Virtual Memory, NOT swap space! (Score:1)
>1 is the best way to go. (Score:3)
You don't necessarily need 2x the size of your physical ram in swap - this is a throwback from the days when RAM was very expensive. 1x the amount of ram is perfectly fine, especially if this is going to be a single user machine - lots of swap is only useful when you either have a lot of users that are idle (i.e. stay logged in when they aren't there) or programs that take up more memory than you can afford.
I've also heard of ideas like putting small swap partitions inbetween normal partitions, so that the disk heads don't have to move as much. Anyone have luck with a setup like that?
Also, AFAIK the 127MB limit is a kernel 2.0.X an older requirement - 2.2.X supports bigger swap partitions.
Re:There are many beginnings... (Score:1)
That's 'cause of centrifugal force, right?
Re:Swap Files and Linux... (Score:1)
1. if you got more than one drive, spread them across as many drives as possible
2. partition your hard drives so that the swap partition is either on the outer tracks (faster data transfer) or in the middle (possibly faster access time?)
3. use fast hard drives if possible (7200 / 10K RPM)
4. buy more RAM - (ram is MUCH faster than a hard drive) ram prices are about half of what they were a year ago, and it may still be going down.
Swap before RAM is filled (Score:1)
You can tune this by echoing 3 numbers to
I like to set these numbers big to force swapping out sleeping processes and leave plenty free RAM to speed up starting netscape or emacs, whatever.
Solaris 2.x - Tmpfs for swap space? (Score:1)
Memory is cheap, and disks are slow (Score:1)
That said, I agree with the other poster that swap space can be useful for long-term idle programs. And a decent sized swap area is cheap insurance against some program taking up a lot more VM than you expect - I've occasionally run out of VM (thanx, Netscape!) and it is not pretty. But your active applications should never hit the swap disk.
Of course, this assumes that you're using a recent motherboard and additional memory is available. I still occasionally use a 386 maxed out with 20 MB of RAM. In that case I do have a very large swap partition (when compared to the amount of RAM) and accept the performance hit.
Re:Memory is cheap, and disks are slow (Score:2)
My point addresses the vast majority of SOHO users who either have a single user, or at most a family or small department. They should be hitting swap infrequently, if ever.
Faster swap at front of drive (Score:1)
out of swap partitions at the lower cylinders
of the hard drive. More so with the larger
drives coming out these days.
Can anyone confirm these rumor/theory?
making swap 2x Physical memory... (Score:2)
Another issue comes from how the swap is accessed. Some Unices, such as Solaris, automatically alternate between their various swap partitions, resulting in distributing I/O over all the swap devices. It is my understanding that Linux uses them linearly by filling one, then the next. I have not tested this, however. If this is the case it reduces the performance penalty of putting more than one swap partition on a single physical drive.
As a general rule, I configure a swap partition (or several
Linux and Swap Optimization? (Score:3)
That was one of my first concerns when I first installed Linux as well. I tried it first without a swap partition (Caldera 1.1 mentioned that a swap partition "might be necessary with a low amount of RAM"), since I figured I would be OK without it, and the resulting machine wouldn't run. I had to repartition and reinstall a few times to get it right. Good pratice. :)
My current Linux machine has 192 M of RAM, and I've gotten away with using one single swap partition of the max size (127 M). I've never had a memory problem, and I have a tendency to run a lot of server stuff (for example, an LDAP server, a mod_perl copy of Apache for development, a mod_roaming copy of Apache to host my department's Netscape profiles, MySQL, and several other custom services), not to mention the many programs I use in the foreground at any given time (several copies of Netscape, several xterms (some running Emacs!), same-gnome, Gnumeric, etc).
With 128 M of RAM, you probably won't use a swap partition too much, so one should be sufficient. A swap partition is really most essential on low RAM machines (16 M or less) running X or serving a lot of users.
I say put it as the only partition on a fast disk (maybe a small dedicated SCSI drive... you must a few old ones lying around).
darren
Re:I don't need no steenkin' swapspace (Score:1)
I've got 2xPII400 and 256M, with 246 now allocated:
MemTotal: 257788 kB
MemFree: 4872 kB
MemShared: 61856 kB
Buffers: 41004 kB
Cached: 122304 kB
SwapTotal: 120480 kB
SwapFree: 120480 kB
I'm a little miffed at how much memory is hogged for buff/cache, since I'll start swapping out apps I'm using, in favor of the cache. Although, it seems to behave a little better if I let the swap go to 2/3 megs, then swapoff/swapon. What I'd like to see is a tunable parameter that allows me to say don't swap until X amount of memory is allocated to apps, instead of cacheing very large files that I'll only open once.
Re:I don't need no steenkin' swapspace (Score:1)
Sure, but is it worth the performance? I specifically bought a bunch of RAM so that this machine would be fast. I'll probably get at least another 256 for this machine, just to boost performance. Besides, I'd rather use the 17G for DEVO mp3s
Linux swapsizes.. (Score:2)
I myself used to have a "small" swap too, and linux almost never swapped more than 2MB. Then I increased it to be 160MB (I have 80MB memory), and even as we speak Linux has swapped out 26MB. This is because Linux behaves differently if it has lot's of space to swap on or if it hasn't. If Linux hasn't got a space to swap on and the memory becomes full, it simply throws some unused stuff "out". If it has enough swap space, it swaps in the same situation. And since when the stuff is again required it's faster to load it from the swap than from the disk (yes, I know, the swap is located on the disk too) this is the preferred method.
--
Swap files and magical numbers (Score:1)
I really don't understand the 2x multiplier. Um, if I have 500 MB of RAM, that means that I need 1 G swap!!?? Right! The more RAM you have, the LESS swap you should need. Should be something like:
swap =
or
swap = N +
Striping is cool...you can do that with swap under NT too...heh, NT even gives you one big stripe of useless data down the middle of your partition for "recovery". That's what I call New Technology...
Re:I haven't had much need for extra swap. (Score:2)
You can limit how many processes can be run, how much memory can be used (total I think).
-xk
Re:Put on different disk (Score:2)
Partitions:
/boot
SWAP
... others
... this way your kernel files are always in the first 1024 cylinders but your swap is at the fastest part of older disks (newer disks use scattering to make all reads and writes the same speed).
If you use two disks, and assuming the load on both is about the same, set the priorities to be equal in
/dev/hda2 swap swap defaults,pri=1 0 0
/dev/hdc2 swap swap defaults,pri=1 0 0
This way the Linux kernel automatically uses both partitions simultaneously for faster reads and writes. If your hard drive isn't doing anything else, you'll get twice the speed out of this.
Again, with 128M of ram, you only need 128M of swap, even for most mid-level server apps. If you want to run Slashdot on your PC, you might need more
... leave some unpartitioned space in the middle of your drive to add swap to later if you need to
killin' da' swap (was:Re:another add_on question) (Score:2)
Linux: dd if=/dev/zero of=/dev/hda1
almost all of the swapped processes died with strange signals but the systep keep running on
Linux with swapfile: rm -f
the file is no more here but the disk space is not freed 'till next reboot. system works fine...
HP/UX: lvreduce -L 1
biiiig mistake - system dumps regs and dies