Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to protect against GHC7 compiled programs taking all memory?

When playing with various algorithms in Haskell it often happens to me that I create a program with a memory leak, as it often happens with lazy evaluation. The program taking all the memory isn't really fun, I often have difficulty killing it if I realize it too late.

When using GHC6 I simply had export GHCRTS='-M384m' in my .bashrc. But in GHC7 they added a security measure that unless a program is compiled with -rtsopts, it simply fails when it is given any RTS option either on a command line argument or in GHCRTS. Unfortunately, almost no Haskell programs are compiled with this flag, so setting this variable makes everything to fail (as I discovered in After upgrading to GHC7, all programs suddenly fail saying "Most RTS options are disabled. Link with -rtsopts to enable them.").

Any ideas how to make any use of GHCRTS with GHC7, or another convenient way how to prevent my programs taking all memory?

like image 865
Petr Avatar asked Sep 07 '12 18:09

Petr


1 Answers

You can compile your own programs with -with-rtsopts=-M384m to set RTS options at compile time (once and for all). You could also set up a "blacklist" of programs that shouldn't be run with GHCRTS in your .bashrc; perhaps something like

for i in foo bar baz
do
    alias $i="GHCRTS= $i"
done
like image 106
Daniel Wagner Avatar answered Nov 03 '22 13:11

Daniel Wagner