Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit memory used by cabal install?

I'm limited by 1GB memory on my server hosting. When I want to compile some big program like git-annex, Cabal eats lot of memory. Is there a way to limit cabal or gcl using some option to limit memory usage?

I updated question with some details: I'm running cabal (1.22.4.0) and Ghc 7.10.2 on the Webfaction hosting (CentOS 7 - 64bit), with access to shell (non root access). Webfaction admin/robot generally tolerate some burst due to compilation. But Ghc / Cabal need too much memory and spend too many minutes for certain package compilation. So system automatically kills all processes.

I need to relaunch the compilation many times to finally obtain a successful result.

My primary objective is that compilation ends with success, however long it takes.

like image 790
reyman64 Avatar asked Nov 05 '15 13:11

reyman64


2 Answers

@reyman64 suggestion confirmed to work on Xubuntu 18.04 with 2GB ram. Thanks! So, cabal install -v cabal-install hangs the system. The following works fine:

cabal install -v --ghc-options='+RTS -M1G -RTS' cabal-install
like image 187
HadoopMarc Avatar answered Oct 22 '22 19:10

HadoopMarc


EDIT: the post was unclear about the true issue, so ignore this answer as it was written with something else in mind, but has some useful comments.

I think if you externally limit Cabal's or GHC's memory consumption to 1GB, you will start getting a lot of failed builds due to early terminations by a Linux memory guard (or whatever it's called — somebody, please?). This might not be the case if you find a way to convince Cabal itself to use less memory, and convince GHC to go on a diet, too.

I ran into this just recently while building Curry KiCS2 on a 1GB virtual machine with just 1GB of swap space. (Of course my goal was not to limit memory consumption but instead get the damn thing to finish building, so all I did was increase VM memory to 4GB and swap to 8GB, but that's clearly not what you're after.)

So I think there is probably no workaround to GHC consuming a lot of memory during compilation. Just make sure parallel compilation is turned off though. And research means to reduce GHC's memory consumption, by compilation flags (of GHC itself, possibly), or turn off optimization phases that might consume a lot of memory, etc.

A brighter mind could prove me wrong though.

like image 29
Erik Kaplun Avatar answered Oct 22 '22 19:10

Erik Kaplun