2

While developing some software, a program under test sometimes eats all the memory, then proceeds to yomp into the swap space and start thrashing the disk, leading to a predictable drop in responsiveness to the point that I generally switch to another terminal to log in and kill the process manually.

What I'd like is for this particular process to get killed before it starts eating swap space like there's no tomorrow. I found a github page in which killing processes with a watchdog is discussed (and indeed, done) - https://github.com/rfjakob/earlyoom - and I could alter that code a little to seek out and kill only this specific faulty program, but it would be nice if I could simply deny use of swap space to a nominated process and have it simply get killed. I suppose even more awkwardly, it's be fine for it to get a small amount of swap space in the normal course of things; it's only when it's on a quest to consume all the memory in the universe that it needs killing.

3

I don't think there is a way to limit swap space, unless you modify the program to only request non-swappable memory, which even if possible would probably be impractical.

However what you can and should do is limit the total amount of memory available to the process. You can use cgroups (the new-ish general way), ulimit (setrlimit, the traditional way), or the timeout tool.

  • Aha! That looks like an excellent link towards the kind of thing to do. Given it's under test, I can certainly have nothing else going on and give it a limit of almost (but not quite!) all the memory. Thanks very much; looks like a good way to achieve the effect I want. – Moschops May 7 '16 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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