[Haskell-cafe] [GHC 7.8.4] IO Monad leak space?

Tom Ellis tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk
Fri Jul 3 16:52:22 UTC 2015


On Fri, Jul 03, 2015 at 04:06:45PM +0000, Baojun Wang wrote:
> Full source code:
> 
> https://github.com/wangbj/haskell/blob/master/lcmsum.hs
> 
> I build the program with:
> 
> ghc -O2 --make -rtsopts -prof -auto-all lcmsum
> 
> and run it with:
> 
> echo -ne '5\n100\n1000\n10000\n100000\n1000000\n'  | ./lcmsum +RTS -sstderr
> -p
> 
> I've tried use
> 
> ``let !ret = (v1+(fromIntegral i) * (fromIntegral v)) in r'' instead,
> however it didn't make any difference per profiling. (both Array are
> Unboxed).

Correct, since they're unboxed forcing the thunk is done automatically.

I'm puzzled.  What output are you seeing and what were you expecting?  I see
"13 MB total memory in use".  That doesn't sound like a lot when you are
allocating two arrays of size 10^6.  There's a lot of *allocation*, but not
so much peak memory usage.  I get the same result on GHC 7.6.3 and 7.8.4.

My complete output:

% ghc -O2 --make -rtsopts -prof -auto-all lcmsum
[1 of 1] Compiling Main             ( lcmsum.hs, lcmsum.o )

lcmsum.hs:48:9: Warning:
    In the use of `unsafeFreeze'
    (imported from Data.Array.IO, but defined in Data.Array.MArray):
    Deprecated: "Please import from Data.Array.Unsafe instead; This will be
    removed in the next release"

lcmsum.hs:51:3: Warning:
    In the use of `unsafeFreeze'
    (imported from Data.Array.IO, but defined in Data.Array.MArray):
    Deprecated: "Please import from Data.Array.Unsafe instead; This will be
    removed in the next release"
Linking lcmsum ...
% echo -ne '5\n100\n1000\n10000\n100000\n1000000\n'  | ./lcmsum +RTS -sstderr -p
152935099400
1529628080000
278320460000
277913417200000
277811686426000000
   2,273,379,656 bytes allocated in the heap
         233,104 bytes copied during GC
      12,002,728 bytes maximum residency (3 sample(s))
         580,184 bytes maximum slop
              13 MB total memory in use (0 MB lost due to fragmentation)

                                    Tot time (elapsed)  Avg pause  Max pause
  Gen  0      4350 colls,     0 par    0.02s    0.02s     0.0000s    0.0000s
  Gen  1         3 colls,     0 par    0.00s    0.00s     0.0003s    0.0005s

  INIT    time    0.00s  (  0.00s elapsed)
  MUT     time    2.66s  (  2.65s elapsed)
  GC      time    0.02s  (  0.02s elapsed)
  RP      time    0.00s  (  0.00s elapsed)
  PROF    time    0.00s  (  0.00s elapsed)
  EXIT    time    0.00s  (  0.00s elapsed)
  Total   time    2.67s  (  2.67s elapsed)

  %GC     time       0.6%  (0.6% elapsed)

  Alloc rate    856,218,428 bytes per MUT second

  Productivity  99.4% of total user, 99.5% of total elapsed


More information about the Haskell-Cafe mailing list