Ubuntu 64 Bit and GHCs Garbage Collector

Hi,

Update: I tested a kernel 2.6.31-12 (from kernel.org) and had the same (if not even worse) behaviour as with 2.6.31-19. So, I apologize. It has nothing to do with Ubuntu per se, but probably with the linux-kernel; that makes me wonder if I haven’t done something faulty: that behaviour should have attracted the attention of some other Haskell developers in the meantime, but I couldn’t find any information on it. So, take in mind that the following could be incorrect…

finding this strange behaviour had cost me a lot of hours (see also my post on the haskell-cafe mailing list), because honestly, who do you blame if your parallel programm behaves strangely:

  1. yourself
  2. the compiler
  3. the special patches of your OS vendor to your linux kernel

Since the probabilities of an error in 2. are quite low (at lot of people use GHC and its parallelization techniques) and — at least I thought that — those in 3. are low, too (some of those people from 1. should be using my OS with GHC for parallel development), I chose 1. Hence, I spent a lot of time trying to find synchronisation and performance problems in my code, which in fact, weren’t there!

The current setup of a standard Ubuntu 9.10 (64 bit) is a vanilla kernel (2.6.31-19-generic) , used with GHC 6.12.1. Look at this small and seemingly innocent program

-- File Pi.hs
-- you need the numbers package from hackage.
module Main where
import Data.Number.CReal
import System.Environment
import GHC.Conc

main = do
    digits <- (read . head) `fmap` getArgs :: IO Int
    showCReal (fromEnum digits) pi `pseq` return ()

that you can compile with

ghc -- make -O2 -threaded Pi.hs -o pi

Benchmarking with

for i in `seq 1 5`;do time pi 5000 +RTS -N1;done
for i in `seq 1 5`;do time pi 5000 +RTS -N2;done

I received the following exemplary runtimes for the vanilla ubuntu kernel.


And this is the threadscope profile of a particular bad run:


As you can see, nearly all time is spend in the Garbage Collector, doing…things, GCs do…

I then compiled my own kernel2.633 from kernel.org and received these results:

Conclusion: At least for me and my parallel programs (and even some innocent toy programs like Pi.hs) does the standard Ubuntu 64bit kernel harm parallel performance (especially that of the GC) a lot.

I find this highly surprising:

  • Ubuntu is a widely used distribution
  • 64 bit versions are also becoming quite common
  • in my perception Haskell developers use parallelism a lot

Question. Either the intersection of these properties is quite small or my measurements have some serious flaw. I’d be glad if someone could disprove my results (and give me the opportunity to learn a bit) or support my measurements.

3 Comments

  1. jlouis says:

    Use the same kernel as the one ubuntu uses. Otherwise you changed more than one parameter, making your point moot.

  2. Michael says:

    @jlouis. Correct, but first I’d like to be able to do productive work on my laptop. I’ll do these tests in a few weeks after some deadlines. As a side note: with an Ubuntu version 8.10 everthing worked fine.

  3. Simon Marlow says:

    See these tickets:

    http://hackage.haskell.org/trac/ghc/ticket/3553
    http://hackage.haskell.org/trac/ghc/ticket/3758

    I think this problem should be gone in GHC 6.12.2. In the meantime you can disable the parallel GC with +RTS -qg. If you’re able to test a pre-release that would be very helpful.

Leave a Reply