Measuring memory usage of Glasgow Haskell programs

Simon Marlow simonmar@microsoft.com
Thu, 21 Mar 2002 13:40:06 -0000


> Judging from the source (rts/Stats.c), the "10 Mb total memory in use"
> figure here counts the number of megablocks allocated... but what does
> this actually mean?
>=20
> It's fairly straightforward to determine a program's maximum=20
> stack size by
> fiddling with the -K runtime option and using a binary search.
>=20
> Is there a similarly easy way to find a program's maximum=20
> heap size?  I
> don't think fiddling the -M option will work, because that affects the
> execution (it can cause extra GCs).

You can find an approximation to the maximum instantaneous resident data
size by switching to 2-space collection (+RTS -G1) and fixing the
allocation area size to some arbitrarily small value (eg. +RTS -A256k).
The program will take a long time to run, because it will do a major GC
every time the allocation area is full up.  You can decrease the run
time (and the accuracy) by increasing the size of the allocation area.
The stats output will then tell you both the maximum and average
residency of the program.

> And is there a way to measure static memory usage?  And then the
> maximum combination of stack+heap+static?  (I guess that is=20
> the "maximum
> residency" above)?

The residency only takes into account heap-resident data, static data
isn't included.  I think the stack is excluded from this figure, though.

Cheers,
	Simon