Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a swap partition /dev/sda1. It is 2GB in size and i only want to use it for hibernating. My system has 4GB of RAM. When I am low on RAM the kernel starts swapping and I can't even switch to a tty to kill the application. I only want swap to be used for hibernating, not on OOM condition. So I want OOM killer to kill some applications, not to swap all the time. I have set vm.swappiness=0 but it doesn't help. Any solutions?

share|improve this question
    
I don't have a solution, but wanted to comment on the vm.swappiness=0 setting. vm.swappiness=0 means that the kernel will wait as long as it dares before starting to swap. It will not stop the swapping completely. –  Mogget Nov 3 '13 at 17:14
    
I have possible method how to do this - keep the swap umounted and when i need to hibernate quickly mount it. The question is how to make it work with KDE hibernate button. –  Nazar554 Nov 3 '13 at 19:20
    
Turning off swap isn't going to help the underlying problem you will have when you run out of ram. That said, your system going unresponsive when swapping may indicate a hard drive issue as well. Might be worth running some hardware checks. –  Journeyman Geek Nov 3 '13 at 23:48
add comment

1 Answer 1

up vote 0 down vote accepted

Here are a couple of things you could try, although the solutions are not directly what you asked for.

As I said in the comments, setting vm.swappiness=0 will only make the kernel wait as long as it can before using the swap, not turn it completely off. I have no proof of this but I think that by setting vm.swappiness=0 you are making your problem worse.

The reason I believe that this is the case is that when something happens that force the kernel to start swapping, it will probably have to swap everything really fast, something it is unable to do because of the speed which a hard drive work at. If you let the kernel choose when to swap, it will start swapping data that is used less at an earlier time, and not have to move a lot of data from RAM to swap at once when things get rough. In general this will increase the kernel efficiency.

You could also make a script which will use swapon and swapoff to activate either a swap partition or swap file generated for this specific reason when triggering hibernation. Most window managers can be customized to execute scripts when different part of it is activated like for example the hibernation button. How to do this is dependant on which window manager you use.

A third option is to let the swap be active all the time and instead decrease the amount of RAM that can be used before the OOM manager is activated and start killing processes. This is possible to do, but I have no idea how to do it.

Finally, considering how much RAM cost these days, increasing the amount of RAM in your computer is also a viable option if you have not maxed it out already.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.