mono-sgen

Mono has a new generational garbage collector (since version 2.6.4 afair, and the current version is 2.11.1)

Using of this collector is critical for hosting environments, because the old GC doesn't free fragmented memory and causes memory exhaustion after some time.

This collector works well when dev-lang/mono is built for Gentoo, but in default build of lang/mono for FreeBSD it gives the following message:

Code:
mono-sgen test.exe
sgen is not supported when using --with-tls=pthread.

Stacktrace:

How to build mono-sgen for FreeBSD properly?

See also:
https://bugzilla.novell.com/show_bug.cgi?id=660413
 
Arsen -- I've been trying to get this to work on the current version of Mono from the Ports system (2.11.4). It should be possible for the 'sgen' garbage collector to work on FreeBSD, but I don't know enough about the internals of FreeBSD to fix it.

I spent an afternoon fussing with the configuration settings in the 'configure.in' file; if you change '--with-tls=pthread' to '--with-tls=__thread', there's a section further down in the 'configure.in' file which checks the validity of the setting by compiling and running a small test program which uses the __thread qualifier. When I try it on FreeBSD 9.1-RELEASE, the test passes, but then Mono fails to compile -- some other preprocessor symbol defined by 'configure.in' causes an error in the 'libgc/pthread_support.c' file.
 
Oh..
I was the one who originated this "bug".
Myself I don't know how to make sgen to work with pthread (Posix Thread), and my knowledge about it is pretty close to null right now. If I had some courage, I'd take some times to dive into this, but I now think I lack the patience.
Maybe one day the Mono Project (aka. Xamarin) will just release a version with SGen as its standard Generational Garbage Collector ... or not :)
 
One of the new features in LLVM 3.2 (to be released any day now) is support for Thread Local Storage (TLS), i.e., the __thread qualifier. Once LLVM 3.2 is released, perhaps the Mono/Xamarin devs can get the code to build entirely with Clang/LLVM -- it might just fix this problem, and it'd also keep us from having to install GCC just to build Mono once FreeBSD 10 rolls around.
 
UPDATE -- I figured out how to fix this problem!

I downloaded the source tarball for Mono 3.0.2, and after making some tweaks to the configuration files I've got Mono 3.0.2 running with the 'sgen' GC on FreeBSD 9.1-RELEASE.

I'll try to create a patch for the Mono port later this afternoon and submit it for inclusion in the ports tree; if I can't get the patch working right, I'll write up all of the steps here so someone else can do it.
 
It looks like @romain took care of updating the Mono port to the latest version (3.0.3). It doesn't include the fix for using the 'sgen' garbage collector though, so I'll post my patch for it here -- perhaps he (or someone else with ports access) can verify that the patch works on their system (it does on mine ;) and then add it to the ports tree?
 

Attachments

  • mono-sgen-patch.tar.gz
    428 bytes · Views: 298
I figured out the last (well, second-to-last) piece of the puzzle today -- the Makefile for the lang/mono port wasn't calling Mono's autogen.sh, so certain parts of the build weren't being configured properly. This meant that even with my patch for the configure.in file (see my previous post), if you just ran the usual [CMD="make install clean"][/CMD], the configuration options wouldn't be set correctly for the 'sgen' GC.

I've submitted a PR with a diff containing a fix for the lang/mono Makefile as well as the new patch-configure.in which allows the 'sgen' GC to be compiled.

http://www.freebsd.org/cgi/query-pr.cgi?pr=175518
 
Back
Top