

Swap is not mandatory. If you run out of memory I think Linux kills a few processes to make room for new ones. This is done by OOM killer: out-of-memory killer. So there should be no panic or lockup.Lupin_the_3rd wrote:I have a Santa Rosa notebook with 2.0 GB of ram. Do I really need to setup some swap? Is it mandatory to have swap partition/file or just best practice? What happens if I have no swap, and I run out of memory and try to start a new program, it gives an error?



The problem isn't a lack of disk space, almost ever. It's usually a matter of not wanting the power drain/slowdown on a laptop if anything hits swap. This can be mitigated with the vm.swappiness (not sure if I spelt that correct) sysctl parameter, but it's still a rather big drain to have constant disk access if you do have anything hit swap.wyvern5 wrote:Disk is cheap. Use swap.

It's better than having random processes get killed because you found a memory leak. I have my swappiness set to 5--nothing goes in there unless it's going to stay. Right now I have 800MB swap used, because something, I can't figure out what, but maybe X itself, has a memory leak. If I had no swap, my 768MB RAM would be eaten, and my system would be unstable. As it is, that stuff is just going to sit in swap and not hurt me until I decide to reboot, probably at the next kernel/glibc upgrade. I have plenty more swap too, so it's basically free protection from memory leaks.broken_chaos wrote:The problem isn't a lack of disk space, almost ever. It's usually a matter of not wanting the power drain/slowdown on a laptop if anything hits swap. This can be mitigated with the vm.swappiness (not sure if I spelt that correct) sysctl parameter, but it's still a rather big drain to have constant disk access if you do have anything hit swap.wyvern5 wrote:Disk is cheap. Use swap.
Firstly, this is not random; most of the time the right process gets killed (and if it does it wrong, you can teach it to do better). Secondly, that is a matter of opinion. Some people will indeed prefer have a leaking program be killed sooner than to have it first thrash on swap and then be killed, draining the laptop battery. But memory leaks aren't an argument here: A leak that eats 2GB of a swapless system will also eat up the 2GB additional swap, if you have it. Instead of being swapless because of that, fix the memory leaks and if you can't do that, find a way to limit memory consumption of a single process; I think ulimit can do that.wellwhoopdedooo wrote:It's better than having random processes get killed because you found a memory leak.

It calculates something like a 'badness' score for all processes, which I guess is somewhat proportional to the memory they use; and based on that it kills a process. This looks like more informations about the subject. I think it is or was a known problem that the OOM killer will kill the X server by mistake, because it appears to use lots of memory since depending on how you look at it, the entire graphic card memory is memory used by the X server. You can adjust things with the files /proc/<pid>/oom_*. But don't ask me how exactly, I've never done it.wellwhoopdedooo wrote:Hmm, I was always under the impression that it was simply random

I prefer to think that we are the ones that likes to prevent, better than to cure.captwiggum wrote:No you do not NEED swap.
I have a 2GB notebook and have never setup swap and never needed it. I have a lot of apps open and running at once, and have never approached the limit of my 2GB RAM. I see a lot of swap lovers on this thread, and that's cool, but let me offer another perspective.
The kernel will not swap only when the ram is full. It will swap whenever it feels like swapping would improve the usage or physical ram.1. If you're using more the 2GB then something maybe wrong.
I don't understand that.2. If you do use up 2GB, you may well use up the additional swap also.
True, a very particular case. By the way, if we speak about performance, the supposed performance hit that you say when you talk about the swap, is nothing at all compared to the performance hit you get with encryption. My personal opinion is that using a swap partition gives you no performance hit at all. That is, unless you fill your ram, in which case swapping is obligatory, and not something that the kernel does when iddle. But in that case, without a swap, you would get the greatest performance hit: some application (maybe with important unsaved data) will be killed.3. If you use encrypted partitions, swap is a pain and a general security concern.
I am no kernel guru, so, you might correct me if I am wrong. but, as far as I know, no program reserves swap. The memory administration is up to the kernel. A program just uses memory, but it doesn't need to know if that memory is into a ram stick, a swap device or a magic umbrella.4. Many programs will reserve swap space if it exists, even it if it is not needed.
It is not that easy, the same that "it is not that easy" to explain how the cache works, which is just the opposite of swapping (use physical ram to hold contents that should be read from a physical drive). If that categoric enunciation was true, believe, someone should have discovered in these last decades. And don't tell me that times have changed, cause, if it is true that memory sticks are bigger, it is also true that programs nowadays are much more memory hungry. Of course, if you use msdos in a core2 duo with 2 gb of ram, then you can assume you don't need swap. But that is another story.5. Its one more disk operation to slow things down, to setup, and admin.


By changing the size of the swap partition... There's no way to limit how much swap space is going to be used other than that. The sysctl property vm.swappiness is an integer (0-100) that controls *how easily* the kernel will "want" to swap things out vs. freeing cached memory, but there's no way that I know of to change how much space is allowed to be used, other than resizing the swap space itself.Dralnu wrote:[stupid_question]How again do you set how much swap will be used? I don't remember seeing that mentioned anywhere...[/stupid_question]
I wasn't refering to the partition size, but whether it would want to just free cached mem or use swap.broken_chaos wrote:By changing the size of the swap partition... There's no way to limit how much swap space is going to be used other than that. The sysctl property vm.swappiness is an integer (0-100) that controls *how easily* the kernel will "want" to swap things out vs. freeing cached memory, but there's no way that I know of to change how much space is allowed to be used, other than resizing the swap space itself.Dralnu wrote:[stupid_question]How again do you set how much swap will be used? I don't remember seeing that mentioned anywhere...[/stupid_question]

Info on "swappiness" here.Dralnu wrote:I wasn't refering to the partition size, but whether it would want to just free cached mem or use swap.broken_chaos wrote:By changing the size of the swap partition... There's no way to limit how much swap space is going to be used other than that. The sysctl property vm.swappiness is an integer (0-100) that controls *how easily* the kernel will "want" to swap things out vs. freeing cached memory, but there's no way that I know of to change how much space is allowed to be used, other than resizing the swap space itself.Dralnu wrote:[stupid_question]How again do you set how much swap will be used? I don't remember seeing that mentioned anywhere...[/stupid_question]