# Is going *without* a swap drive asking for trouble?

## Danuvius

I have an AMD Athlon XP 2400+ with 512 MB.  I don't think I've ever seen my memory be fully used (discounting "cached" stuff in memory), and the most I've ever seen my swap drive used is 20 MB - 100 MB.  (it is currently 1 GB)

Am I asking for trouble if I decide to do away with it altogether?

What is the first that could happen?

----------

## platojones

 *Quote:*   

> Am I asking for trouble if I decide to do away with it altogether? 

 

In short, yes you are.  You may not run into it today, but one day, right in the middle of an emerge, you'll just run out of memory and there will begin a mass-extinction of processes on your system.  It will be ugly.  Rule of thumb is swap = 2 x physical ram.  I stay with that.

----------

## rowbin hod

I dunno man.

I got a p133 with 64MB of ram, 128MB swap. It's bloody slow but never runs out of memory or anything like that, at least not in a way that would cause my emerges to fail, or something to break. So how would my main machine with 1GB of ram and no swap be any worse off than the crappy old one with 192MB including swap?

----------

## platojones

Well, there are differences of opinion here and I'm sure some others would say they've had no problems, but, a computer tends to use up as much memory as is available.  It seems to be just one of those rules of life that nobody ever talks about I guess.  The operative question here is 'what happens when I run out of memory'.  Well, things "start dying in a messy way" is what.  And you have no control over what dies and when.  I personally don't even want to risk it.  Others may differ.

I'll bet you aren't trying to run Xorg, Apache, a sendmail client, KDE at the same time on your box.  A smart move given the resources you've got.  On higher end machines, it's easier to forget that.

----------

## Gentree

 *Quote:*   

>   right in the middle of an emerge, you'll just run out of memory and there will begin a mass-extinction of processes on your system. It will be ugly. Rule of thumb is swap = 2 x physical ram. I stay with that.

 

so an emerge fails , big shit.  UUUGLEEE.

2 x RAM was the rule when RAM was 64M. That does not apply when you have 1G of RAM.

 *Quote:*   

>  a computer tends to use up as much memory as is available. It seems to be just one of those rules of life that nobody ever talks about I guess.

 wtf?  :Rolling Eyes: 

Any decent bit of software will show an error when a mem allocation fails if it does not it will probably segfault shortly after.

Unless you are doing something very demanding like video editting or huge graphics you are not likely to more than 512.

Try using 

```
free
```

to monitor your swap usage , its probably zero !

 :Wink: 

----------

## platojones

 *Quote:*   

> so an emerge fails , big shit. UUUGLEEE. 

 

Well, I'm convinced.  That looks like much more fun.  Like I said, some will have a different opinion.  Since 1GB now equals infinite memory, please disregard what I said earlier  :Very Happy: 

----------

## Danuvius

 *platojones wrote:*   

>  *Quote:*   so an emerge fails , big shit. UUUGLEEE.  
> 
> Well, I'm convinced.  That looks like much more fun.  Like I said, some will have a different opinion.  Since 1GB now equals infinite memory, please disregard what I said earlier 

 

"Flowery" language aside, platojones... I myself am thinking that your assumption about what happens when memory runs out seems incorrect.  Random processes wouldn't just start crashing--it is new ones that would fail.  Not so?

And while you are almost certainly correct that it would be a major emerge that is most likely to experience problems, I had compiled OpenOffice.org without problems on a 256 MB RAM system with 512 MB swap.  Yes, yes, I realise that 256 MB + 512 MB = 768 MB, which is 256 MB more than what I currently have.  But my point is that even massive emerges don't seem to have entirely stellar memory requirements.

Thoughts?

----------

## platojones

Well, that assumes that old processes wouldn't be requesting any memory.  Most 'old' processes, that do anything at all, constantly request and free memory.  Thus the 'random' factor I mentioned.  Notice the lack of 'flowery' language in my response BTW  :Wink:    Look, if you want to spare yourself 1 GB of precious, 'expensive' hard drive space, then by all means, get rid of your swap.  I think it's a mistake, but you asked for an opionion and I replied.  You money, your choice.

----------

## Danuvius

 *Gentree wrote:*   

> 
> 
> Unless you are doing something very demanding like video editting or huge graphics you are not likely to more than 512.
> 
> Try using 
> ...

 

It is zero most of the time.  When swap is actually used, it is because of stuff cached in memory.  That, as I understand, non-essential use of RAM.  And while having stuff cached in RAM may speed things up, I suspect that the use of the SWAP (which is on the same drive as /) slows things down.

Given the described circumstances: am I likely to win or loose performance by eliminating my swap drive?

Arguably I could just reduce swapiness--is that what I should do?

----------

## Danuvius

 *platojones wrote:*   

> Well, that assumes that old processes wouldn't be requesting any memory.  Most 'old' processes, that do anything at all, constantly request and free memory.  Thus the 'random' factor I mentioned.  Notice the lack of 'flowery' language in my response BTW    Look, if you want to spare yourself 1 GB of precious, 'expensive' hard drive space, then by all means, get rid of your swap.  I think it's a mistake, but you asked for an opionion and I replied.  You money, your choice.

 

Ah!  That makes sense.

I couldn't care less about the 1 GB space.  I have 80 GB, and though it isn't enough; 1 GB won't make any difference for me.

As I mentioned in my previous post (posted after yours) my desire is to reduce (or eliminate) usage of the swap drive simply because it is on the same drive as my /.  (that is "root.", not "slashdot"  :Wink: )  I suspect its use negates whatever advantage stuff cached in memory provides.

----------

## platojones

The VM subsystem on linux, and most *nix systems is pretty smart about when to swap and when to cache.  I would try playing with the 'vm.swappiness' sysctl to tune this a bit to get that better.  This has been debated in the *nix community for decades.  The default is pretty darn good.  Shutting down swap (and thus the advantages of a modern VM operating system) should probably be the last on the list.

----------

## platojones

Also, just to clarify a little better.  By 'smart' I mean that typically, processes that do the least in a given cpu slice are the ones that get swapped first.  So the assumption that swap negates the effects of cache doesn't necessarily follow.  Cache provides a fairly powerful performance advantage.  Swapping a process that has used hardly any of it's CPU slice will still put cacheing well ahead.

----------

## platojones

The more I read that post from Gentree, the more questions I have:

 *Quote:*   

> 
> 
> Any decent bit of software will show an error when a mem allocation fails if it does not it will probably segfault shortly after.
> 
> 

 

And the positive aspect of that is what?  What if it's something critical like init?  Who needs that, just reboot right?

 *Quote:*   

> 
> 
> Unless you are doing something very demanding like video editting or huge graphics you are not likely to more than 512.
> 
> 

 

Ok, no video editing or graphics for you then.  Back to windows, which does have a VM (lousy but it's there).

 *Quote:*   

> 
> 
> Try using
> 
> Code:
> ...

 

Yep, that'll work right up to the point your system goes down.

Thanks for the 'lernin' Gentree, I've been 'Schooled'.

----------

## dark_glaive

I have 1GB of RAM and 30 Megs of swap. The only time I've even came close to filling it all up was when UT2k4 wasn't correctly shutting down and wasn't deallocating memory. My swap usage is always at 48 kilobytes, because of btlaunchmanycurses, but portage never causes any swap usage.

----------

## platojones

dark_glaive:

Since you expressed an opinion here, have you turned off your swap?  If not, please do, and share your experiences.

----------

## Gentree

since you recommend 2 x RAM ie 2G of swap in his case I think you can effectively regard 30M as pretty close to swapoff -a 

Try using 

Code: 

free 

to monitor your swap usage , its probably zero !

 *Quote:*   

> Yep, that'll work right up to the point your system goes down. 
> 
> Thanks for the 'lernin' Gentree, I've been 'Schooled'.

 

No you haven't .

Pls read before you rant. 

I suggested using free to monitor swap usage. ie keep the swap as it is and see if it's needed. I fail to see how that will take his system down.

Also I think it fair to assume that system components like init can be expected to run on even a minimal system without falling apart at the seams.

I never suggested 1G was infinite either , but it's siginifiacantly more than 64M +128 swap. Linux can run quite sucessfully on that sort of kit without falling apart when if needs more memory.

What do you imagine happens when the swap runs out? That's not infinite either.

The original post was asking for advice , you are hiding behind "opinions" now because some of what you posted does not stand up. Post accurate advice from what you know. Inaccurate advice is unhelpful at best.

Getting hot under the collar and flaming is a defensive reaction. Sorry if questioning the accuracy of what you posted makes you feel threatened. Or do you feel you are wise beyond question?

On the other hand , if you took the time to read what others post you may actually learn something. Several posters seem to differ with what you say. They may all be wrong, who knows. 

Anyway I find their posts add to my knowlege. We are here to learn.

 :Cool: 

----------

## ferg

 *Gentree wrote:*   

> 
> 
> Anyway I find their posts add to my knowlege. We are here to learn.
> 
> 

 

Just to add to the confusion/knowledge  :Smile: . I've always thought that the VM system tries to "swap out" libraries that have not been used for a while, so keeping them in memory, but not using up valuable ram.  For example try using a desktop session that you have not used for quite some time (>days). The disk will thrash as it tries to load all the libraries back from swap into physical memory. Same with using a application that you've not used for a while. So therefore having swap will help make application load quicker and be more responsive. 

This is what I've always thought, not what I know!   :Smile: 

also just to add to the data, I've got plenty of ram, yet my swap always seems to be in use.

```
ferg@scotgate2> /opt$  free -m

             total       used       free     shared    buffers     cached

Mem:          2025       1971         53          0        112        458

-/+ buffers/cache:       1401        624

Swap:         1941        323       1617
```

This is a pure workstation, and currently I'm not running any major processes.

Of course I reckon 2Gb of disc is a farily small resource in these days of 200gb drives.....!  :Smile: 

Cheers

Ferg

----------

## widremann

On my laptop, which has Fedora Core, not Gentoo, I have turned off swap.  I have only 384 MB of memory, but I almost never use more than a half.  Most of the time, usage sits between 100 and 140 MB (with KDE, music players, internet, email client, gaim, konsole all running at the same time).  Even when I compile it never goes above 200 MB.  Of course, I had a different reason for turning off swap and that's because I didn't want the harddrive being accessed all the time when I was on battery and also in general.  Obviously, if I was going to do something intensive, I could just turn on swap again.  And that goes for everyone else.  You can always quickly create a temporary swapfile and turn on swapping again if you know you are going to do something heavy.

----------

## gärtner

I have a laptop with 512MB and don't use swap, because the harddisk is so slow. I just encounter trouble with emerging sth. big while working with eclipse. Now about : *Quote:*   

>  I've always thought that the VM system tries to "swap out" libraries that have not been used for a while, so keeping them in memory, but not using up valuable ram

 

This would not make any sense, because the library is on the disk anyway. So the buffer cache is used to do this. If there's not enough memory the buffers get deallocated and if needed again are read from harddisk. What is swapped is parts of the heap (an maybe the stack, i don't know). So if all your programs dynamic data get bigger than your real memory, you have a problem.

What can happen without swap is some sort of trashing. So if you're low on memory and drop some libraries out of memory, but shortly after it gets needed again and another library is dropped which by itself is needed again shortly after you're working mostly on top of your hard disk speed which is really slow.

So my opinion: if you have a fast harddisk or work with a lot of big programs in parallel, turn swap on, else try to turn it off.

/Gärtner

----------

## sotha_sil

 *Danuvius wrote:*   

> I have an AMD Athlon XP 2400+ with 512 MB.  I don't think I've ever seen my memory be fully used (discounting "cached" stuff in memory), and the most I've ever seen my swap drive used is 20 MB - 100 MB.  (it is currently 1 GB)
> 
> Am I asking for trouble if I decide to do away with it altogether?
> 
> What is the first that could happen?

 

This is a question that I have wondered about as well.   :Smile: 

When I first started gentoo, I ran without swap.  I compiled the entire operating system, x-windows, etc., without swap.  I have 512 meg of ram.

Later on I added swap, but only because one specific program sometimes needs it.

----------

## Gentree

The only case where I can remember having memory probs (ie lack of) was using vuescan to scan a negative at rediculous resolutions , c. 5600 dpi. It was fine a lower res.

It got half way though and hung. A more recent version no longer does this.

This was clearly badly written memory management but nothing catastrophic happened to my system. The process hung and I had to kill it.

Linux has a reputation for being stable, it can generally handle a sortage of memory in a sensible way.

Compiling seems to have moderate heap requirments even on large packages. Probably because of the very modular way most code is written . 

rosegarden may be and execption if anyone wants to try. I found it loaded my system a lot more that emerge kde-libs

So to the basic qu. "what will I see first" , I would expect to see handling very large images in gimp to slow down or fail to open. And probably games would suffer but that's really not my thang, so I cant advise.

If you have >=1GB of RAM , try to use it all and report back  :Wink: 

 :Cool: 

----------

## jdgill0

I didn't see mention of using a swap file in place of a swap partition.  You can use a swap file in Linux.  I tried it out once way back with a 2.4.x kernel.  I really couldn't tell a difference back then.  With a swap file at least you could grow/shrink it to meet your demands -- not sure you can have a dynamically sized swap file, but you can manipulate its size without having to mess with disk partitions.  I do believe a swap file is not as good "performance" wise as a swap partition, but then if you are doing a heavy load that is requiring a lot of swapping into and out of swap space you are already suffering greatly.  I certainly don't think 1G of swap space is needed -- with the possible exception of a server that could come under a heavy load at any time and having a huge amount of swap space could save it from crashing, in which case a swap partition is likely preferrable.  Desktop users should be able to see they are in trouble ram/swap wise and stop adding to the amount of swap being used -- i.e. a large swap is not really necessary. (IMHO)

----------

## fcgreg

 *Gentree wrote:*   

>  *Quote:*   Yep, that'll work right up to the point your system goes down. 
> 
> Thanks for the 'lernin' Gentree, I've been 'Schooled'. 
> 
> No you haven't .
> ...

 

platojones read it just fine.  So did I, and I came to the exact same conclusion.  Your post was arrogant, short, and accusing of the opinion that platojones was offering.

Now that he has fairly eloquently incised your poor attitude, your tone turns passive-aggresive and even more condescending.

Please, stick to the facts and technical opinions of the post at hand, and check the attitude at the door.

----------

## pacde

This is a funny debate.

How much swap should you have? well the answer to that is as much as you need. I actually had this question on a final exam while in University. The truth is if you use your system for doing video editing, TiVO in the background and running a vanilla version of GIMP (or one that is set to use a lot of memory) and then start to render a highly subdivided blender scene with multiple shading and raytracing, you will probably want some swap - even with a G of RAM. If on the other hand, you use your computer for web surfing and keeping your little daily diary or whatever you do, your going to be OK without very much swap especially if you have more than 256 M. 

My real question is what is it costing you to have a bit of swap? I mean really, you cant afford 256 M of disk space in this day and age?

----------

## madmango

I've always had at least some swap, even though I have 1.5GB of RAM. I figure that it's always good to have at least SOME, as I have had one instance where I've used all my RAM. 

Back when I never did use swap, My system ended up running out of memory once, and it ground to a halt. Maybe I'm stupid or misinformed or something, but I always thought the kernel picked tasks to kill on an OOM condition (out of memory). In fact, if I remember correctly, there was a love-sources option in the kernel for selecting tasks to kill on an OOM back in the day.

But swap has its other uses. Software suspend, for example. Currently, I have 2048MB of swap, but that's only because I have a swap partition on each of my hard drives. If the kernel can, it tries to do a raid0 type-thing if you have swap across multiple devices. Mount with pri=0 in the options column.

----------

## ShadowFlyP

 *madmango wrote:*   

> ...Back when I never did use swap, My system ended up running out of memory once, and it ground to a halt. Maybe I'm stupid or misinformed or something, but I always thought the kernel picked tasks to kill on an OOM condition (out of memory). In fact, if I remember correctly, there was a love-sources option in the kernel for selecting tasks to kill on an OOM back in the day...

 

There are things that happen on an OOM condition.  First, the kernel goes through a number of loops trying to free up "unused" memory.  I forget what actually happens in this stage, but if I remember right, there are pages that the kernel doesn't return immediately after a release for speed optimization reasons.  Also, the kernel can release mmap'd pages (memory mapped files.  Remember, libraries are mmap'd, so the read-only sections of libraries can be 'swapped' out).  This mmap'd library thrashing is what probably slowed your system way way down.  Finally, if the kernel decides it cannot free enough memory, it kills the most "un-nice" process.  The niceness quality of a process is based on priority (realtime processes get bonus), user (root gets a niceness bonus), memory usage, and processor usage (heavy processor usage is a big minus in niceness).  I believe you are right about being able to configure which process gets killed on certain kernel versions.  I remember seeing the alternate policy as being "kill the process requesting memory", but by default on most of your machines it is "kill the most un-nice process", which will probably be X.  So... for you that said "oh well, I'll just have an emerge die"... think again!

----------

## m0p

I have 1GB of RAM and 2GB of swap. No problems yet. Although, I do have 100% usage, and 60% of it is cache. I still never seem to use up swap.

----------

## canal

 *Gentree wrote:*   

>  *Quote:*     right in the middle of an emerge, you'll just run out of memory and there will begin a mass-extinction of processes on your system. It will be ugly. Rule of thumb is swap = 2 x physical ram. I stay with that. 
> 
> so an emerge fails , big shit.  UUUGLEEE.
> 
> 

 

Let's compare two systems: first one has 512MB of RAM and 512MB of swap, second one has 1GB of RAM and no swap. You started some huge process (runaway java program, 10'000 apache servers, etc). First system will slowdown, then invoke OOM-killer, then will resume normal operations. Second system will trash like a mad for 15 minutes, then may be kill something or may be deadlock totally. Why so ? There are no systems without swap. None at all. Why ? mmap. All executable files and all libraries are mmaped to memory - this is kinda like swap. But it's inferior swap: you can not move data to it, only code. This means: when you have serious OOM sitiation you have zero data on disk and zero code in RAM. Result ? BZSHWRRZZZZZRRRRRRRRR (this is sound of heavily abused HDD), system slows to the crawl, near 100% of time is spend in wait state then may be, just may be OOM killer is actiavted.

 *Gentree wrote:*   

> 
> 
> 2 x RAM was the rule when RAM was 64M. That does not apply when you have 1G of RAM.
> 
> 

 

You still need something.

 *Gentree wrote:*   

> 
> 
> Any decent bit of software will show an error when a mem allocation fails if it does not it will probably segfault shortly after.
> 
> 

 

"shortly after" == 15min to few hours is you have no swap and using kernel 2.4. Kernel 2.6 is somewhat better in this regard but not by much.

 *Gentree wrote:*   

> 
> 
> Try using 
> 
> ```
> ...

 

Of course it's zero - that's not the point. Swap is needed not just to extend physical memory. It's life jacket for kernel as well!

 *Gentree wrote:*   

> since you recommend 2 x RAM ie 2G of swap in his case I think you can effectively regard 30M as pretty close to swapoff -a 
> 
> 

 

Nope. System with 30MB of swap is much better then system without swap. And only marginally worse then system with 2GB swap  :Smile:  See above.

----------

## proxyroot

i have one partition, 

no boot

no swap

just /

1 gig or ram, havn't had a problem yet, been running it now for almost 3 months....

i use my gentoo install for almost everything..

im a web developer & general programmer so i have alot of memory hungry apps..

```

bash-2.05b# free

             total       used       free     shared    buffers     cached

Mem:       1022760     914056     108704          0      56136     582384

-/+ buffers/cache:     275536     747224

Swap:            0          0          0

```

all good hear, it has only freaked ooout once, x restarted by itself... 

i can live with that, anything important should be done in the command prompt anyway

----------

## fcgreg

 *proxyroot wrote:*   

> ...  all good hear [sic], it has only freaked ooout once, x restarted by itself... 
> 
> i can live with that, anything important should be done in the command prompt anyway

 

Wow.  Is it really THAT worth it to you to save a few hundred MB of your hard drive by not having a small swap partition?  Wouldn't the extra stability be worth such a small price?

Oh well.  To each his own, I guess.

----------

## Q-collective

I have 1G pc3200 on ram, I have 512M on swap, I never use it.

Well, not correct there, while compiling kdelibs and kdebase I tend to use about 1M of it  :Laughing: 

----------

## tsunam

Well I'll say on my laptop i have no swap...I've never risen above 40% ram use...currently i'm at 22%

and as far as room...well

/dev/hda5             393M  353M   40M  90% /

udev                  252M  2.6M  249M   2% /dev

/dev/hda1              33G   23G  9.7G  71% /mnt/windows

/dev/hda2             1.9G  1.2G  744M  62% /home

/dev/hda6             3.3G  2.9G  452M  87% /usr

/dev/hda7             393M  340M   53M  87% /opt

/dev/hda8             1.5G   87M  1.4G   7% /var

/dev/hda9              16G   13G  3.2G  81% /anime

none                  252M     0  252M   0% /dev/shm

and that was after resizing to give /anime(and audio) more room..fairly high quality ogg's take up some room, good thing i'm not a audiophile ~_~

I'd probably be able to skim off about a gig for the swap if i really wanted to..but then i'd be causing something else to not have room so...

----------

## SwooshingRob

 *canal wrote:*   

> ...

 

I totally agree. Running a system without a swap area is probably alright 99% of the time. The question you should ask yourself is whether you want a system that works 100% or not?

 *Gentree wrote:*   

> 
> 
> Any decent bit of software will show an error when a mem allocation fails if it does not it will probably segfault shortly after.
> 
> 

 

You are wrong.

Linux uses an over-allocator. What that means is that malloc will always return an address even if there is no more physical memory available. When the address is accessed the MMU will kick in and make sure that address is mapped to physical memory. If there is no more physical memory and no swap area the kernel will kill the process asking for more physical memory, which isn't necessarily the one that consumed all the memory. By using a swap area, unused ( and leaked) memory will be swapped out, thus increasing the likelihood of the system not crashing.

(It is possible to limit the amount of memory available for any given process, so checking the return malloc is still a very good idea. Or to put it another way - By not checking the return value of malloc you prove to the world that you are a very lousy programmer.)

For all dual-booters - If you are worried about disk space you can always reuse Windows swapfile as a swap area in Linux. That way you don't have to worry about wasting a few hundred MB of your 200GB drive just to get a more stable system. Surely you don't run Windows without a swapfile?

----------

## BitJam

This is a funny thread.   There seems to be two camps of people: those who have never needed swap, and those who have.

Reminds me of an old Unix joke.  There are two kinds of people: those who never have had a disk crash, and those who make backups.

I am firmly in the "swap is good" camp.  No amount of anecdotal evidence is going to convince me to not make backups, or convince me to not wear a seat belt, nor will it convince me to stop using swap.

----------

## Circlotron

 *platojones wrote:*   

>  Rule of thumb is swap = 2 x physical ram.  I stay with that.

 

I have a different approach. I try and set up a system with less RAM to have *more* swap. I figure a 1GB ram doesn't need 2GB of swap, and 64 MB swap is a raw deal for 32MB RAM according to the 2x physical RAM formula.

----------

## c4

 *Danuvius wrote:*   

> Am I asking for trouble if I decide to do away with it altogether?
> 
> What is the first that could happen?

 

I think it's been coved already, but in my opinion the swap memory is more of a reserv storage. When needed, the system should shovel out stuff to the swap to free space in ram for more effective use (like when resorces / space are needed for compiling, rendering and such ). If there isn't any swap at all, well than whatever heavy process is running would have less resources and thus operate with degraded preformance. In this scenario having enough swap memory may improve the overall speed and stability of the system. On the other hand, few people may need to use the swap space for normal everyday writing in OO, listening to mp3s and browsing the web.

What happens when the swap is gone all together? I use vmware for running different CAD systems on my Linux desktop. Because of memory leeks in X and/or vmware this occurs from time to time:

```
Jun 27 21:43:23 amd64 oom-killer: gfp_mask=0xd0

Jun 27 21:43:23 amd64 DMA per-cpu:

Jun 27 21:43:23 amd64 cpu 0 hot: low 2, high 6, batch 1

Jun 27 21:43:23 amd64 cpu 0 cold: low 0, high 2, batch 1

Jun 27 21:43:23 amd64 Normal per-cpu:

Jun 27 21:43:23 amd64 cpu 0 hot: low 62, high 186, batch 31

Jun 27 21:43:23 amd64 cpu 0 cold: low 0, high 62, batch 31

Jun 27 21:43:23 amd64 HighMem per-cpu: empty

Jun 27 21:43:23 amd64 

Jun 27 21:43:23 amd64 Free pages:        5940kB (0kB HighMem)

Jun 27 21:43:23 amd64 Active:45962 inactive:59910 dirty:0 writeback:0 unstable:0 free:1485 slab:7206 mapped:44691 pagetables:1078

Jun 27 21:43:23 amd64 DMA free:2068kB min:88kB low:108kB high:132kB active:5008kB inactive:3220kB present:16384kB pages_scanned:8670 all_unreclaimable? yes

Jun 27 21:43:23 amd64 lowmem_reserve[]: 0 495 495

Jun 27 21:43:23 amd64 Normal free:3872kB min:2804kB low:3504kB high:4204kB active:178840kB inactive:236420kB present:507 840kB pages_scanned:502501 all_unreclaimable? yes

Jun 27 21:43:23 amd64 lowmem_reserve[]: 0 0 0

Jun 27 21:43:23 amd64 HighMem free:0kB min:128kB low:160kB high:192kB active:0kB inactive:0kB present:0kB pages_scanned: 0 all_unreclaimable? no

Jun 27 21:43:23 amd64 lowmem_reserve[]: 0 0 0

Jun 27 21:43:23 amd64 DMA: 1*4kB 0*8kB 1*16kB 0*32kB 0*64kB 0*128kB 0*256kB 0*512kB 0*1024kB 1*2048kB 0*4096kB = 2068kB

Jun 27 21:43:23 amd64 Normal: 274*4kB 17*8kB 9*16kB 12*32kB 3*64kB 1*128kB 1*256kB 1*512kB 1*1024kB 0*2048kB 0*4096kB = 3872kB

Jun 27 21:43:23 amd64 HighMem: empty

Jun 27 21:43:23 amd64 Swap cache: add 519298, delete 510863, find 141337/192751, race 0+0

Jun 27 21:43:23 amd64 Free swap  = 255752kB

Jun 27 21:43:23 amd64 Total swap = 506036kB

Jun 27 21:43:23 amd64 Out of Memory: Killed process 26497 (vmware-vmx).

```

So when my ram and swap where exhausted, vmware was shut down. I would imagine that running a system without swap would need to close such applications more frequently, though your milage may vary.

----------

## ttuttle

Let me try to straighten out exactly when, how, and why the kernel swaps.

First, it's not particular about what it swaps.  Libraries, programs, code, data--as long as it's in userspace, it's free game.  Second, it swaps for two reasons.  The first reason is the most important one, which is that when the kernel runs out of physical RAM, it starts shoveling the least-accessed memory pages into swap to free up space.  It's usually pretty clever about this, and will only "thrash" if you really are accessing more physical RAM than you have.  (For example, if you're running Tomcat in the background, a bit of a memory hog, it may be swapped out if it's not that busy, and it won't be swapped back in until necessary.)  The second reason is for performance reasons--this is where the vm.swappiness sysctl comes in.  Under normal usage, Linux fills up almost all of the free RAM with a cache of recently-accessed files on disks.  If physical RAM isn't full, and a process tries to allocate more memory, the kernel can choose between 1) erasing some disk cache and 2) swapping out something else.  If there are processes that haven't touched their memory in a while, it will sometimes choose to swap them out because the performance benefit gained from the extra disk cache is greater than the performance hit required to swap them back in if and when they are accessed again.  I have a laptop with 512 MB ram and 1024 MB swap, and even though my RAM usage hovers between 150 and 300 MB most of the time, there's always a few MB of swap used.

So... swap doesn't negate the effect of disk cache, it complements it.  Disk cache puts more frequently used files into RAM for faster access, and swap put less frequently used RAM onto disk to free the RAM for better stuff.  So yeah, you should have some swap.  Once you get past about 256 or 512 MB RAM, the "swap = 2 x RAM" rule becomes a little much... I'd probably say that for 512 MB and up, you could get away with 1 x RAM.  Frankly, I'd say that, unless you're planning to really need like 2GB total memory, you can just use 512 MB for anything above 1 GB.  Just try a large amount with a swapfile to see how much your system will use if allowed, and then pick a slightly larger number.

----------

