There is a huge problem in Linux in this case if you approach to the out-of-memory condition - you will notice that whole your system becomes totally unresponsive because it starts a lot of swapping. Even your mouse cursor may become so 'slow' that you can't start a terminal and kill an offending memory eater process manually. This is because of huge number of disk operations.
To avoid this situation, I personally usually completely disable swap, so the Linux kernel is always responsive and in worst case the out of memory (OOM) killer will kill some process. The logic of which process is killed by OOM depends on the kernel version.
So answer is no - don't enable dynamic swap allocation. You will face machine hangs.
It's easy to try it out with program that just constantly allocates some memory in a loop. Save this program to a text file, memeater.c
:
#include <stdlib.h>
int main() {
for (;;) {char* mem=malloc(4096); mem[0]=1;};
}
Then compile it:
$ gcc memeater.c -o memeater
and run:
$ ./memeater
Try it with swap, without swap, and with your dynamic swap allocation.
Also, keep in mind that in most cases this OOM condition happens because a bug in software (memory leak) or you did something wrong like 'load this 10 GB file in editor' or 'run too many graphical file resizes in parallel' and do the conclusion: Do you need swap or not?