ghc releasing memory during compilation

Bulat Ziganshin bulat.ziganshin at
Mon Mar 13 08:06:59 EST 2006

Hello Simon,

Monday, March 13, 2006, 3:40:21 PM, you wrote:

>> just to check available PHYSICAL memory he answered that he don't know
>> that is physical memory, only virtual memory matters

SM> I think that's a mischaracterisation of what I said.  Actually I said 
SM> that I didn't understand your comment about physical vs. virtual memory,
SM> and in fact, looking back at the message, I still don't understand it :)


SM> I think what you're suggesting is that the runtime should detect the 
SM> amount of physical memory on the system and auto-tune itself to switch
SM> to compacting collection when its residency reaches that amount.  This
SM> is certainly something we could do.  Bear in mind that GHC is not 
SM> necessarily the only process running on the machine, though, and what 
SM> about running multiple GHCs?

i suggest checking of AVAILABLE physical ram, that is perfectly
possible in windows

SM> Also, you can do this by setting your GHC_RTS environment variable. 
SM> Suppose you have 1G of physical mem.  You want GHC to give up when it 
SM> reaches 1.5G, and you want to switch to compacting collection when the
SM> residency reaches 300M.  You could do this:

SM> export GHC_RTS='-M1.5G -c20'

SM> because 300M is 20% of 1.5G.  Perhaps a better interface would be to 
SM> allow you to specify exactly the residency at which to switch to compaction.

you mix up two questions:

1) switching from copying to compacting algorithm
2) return memory to OS after GC

the only commonality between them is what we want to do both these
things only when we are short on physical memory

(1) is possible in GHC. (2) can be implemented, i think. so, the
questions is how to trigger each thing. GHC has mechanism to switching
GC algorithm although this mechanism is not enough flexible. i
personally will prefer to have API that allow to control all GC
parameters (although at this moment we also have this api unofficially
- we have access to all these variables). so the main question at this
time is implementation of returning memory to OS and providing some simple
mechanism of enabling this (say, in percents of maximal heap size like
this is done "-c"). then someone like me can roll out some API to
allow programs better control the entire mechanism

Best regards,
 Bulat                            mailto:Bulat.Ziganshin at

More information about the Glasgow-haskell-users mailing list