[Mono-dev] slowdown with USE_MUNMAP

Michal Moskal michal.moskal at gmail.com
Sun Aug 21 11:06:00 EDT 2005


I've encountered a big slowdown in our .NET application (the Nemerle
compiler) running on mono after -DUSE_MMAP and -DUSE_MUNMAP was
enabled. The ``big'' translates to 2x slowdown in GC_mark_from (which results
in about 10% slowdown of the entire application).

After some investigation I've managed to create a simple C testcase
(as lupus suggested). It seems that -DUSE_MUNMAP makes garbage collection
to be called twice as many times, -DUSE_MMAP
doesn't seem to affect that. The question is: is it normal? How can it
be avoided?

I tested the C program on amd64 and x86.

The Nemerle compiler exhibits better memory behavior with -DUSE_MMAP
(by about 2%) and further better memory behavior with -DUSE_MUNMAP
(by about 10%). The C test program doesn't seem to exhibit this though
(probably because of lack of false positives and large allocations).

Here's the test C program:

#include "include/gc.h"

#include <stdio.h>

typedef struct _tree_node {
        struct _tree_node *left;
        struct _tree_node *right;
        long d1, d2, d3;
        long d4, d5, d6;
} tree_node;

int bytes_allocated;
int counter;

tree_node *alloc(int depth)
        tree_node *n;
        int size;

        if (depth < 0)
                return NULL;

        // make some garbage
        if (counter++ % 3 == 0)
                alloc(depth - 1);

        size = sizeof (tree_node);
        bytes_allocated += size + sizeof(void*);

        n = GC_malloc (size);
        n->left = alloc (depth - 1);
        n->right = alloc (depth - 1);

        return n;

int main ()
        tree_node *n = alloc (19);

        printf ("%.3fM %.3fM %ld %p\n", bytes_allocated / (1024.0*1024.0),
                        GC_get_heap_size () / (1024.0*1024.0),GC_gc_no,  n);

        return 0;

   Michal Moskal,

More information about the Mono-devel-list mailing list