[Haskell-cafe] GHC 7.0.1 developer challenges

John D. Ramsdell ramsdell0 at gmail.com
Fri Dec 10 05:36:59 CET 2010


I found out how to compute a good memory limit for the GHC runtime on
Linux systems.  One opens /proc/meminfo, and sums the free memory with
the reclaimable memory.  The memory allocated to file buffers and the
disk cache are reclaimable, and can be added to the memory of a
growing GHC process.  Once you get beyond that memory size, thrashing
is in your futures.

I have enclosed a short lex program that computes the limit.  It's
basically what is done by the procpc program called free, except that
I printed only the number of interest to a GHC runtime.

John
-------------- next part --------------
/* Compute the free memory on a Linux system with /proc/meminfo */

%{
#include <stdio.h>
#include <stdlib.h>
static int mem_free = 0, buffers = 0, cached = 0;
%}

DIGITS  [0-9]+
SP      [ \t]+

%%

^MemFree:{SP}{DIGITS}   { mem_free = atoi(yytext + 8); }
^Buffers:{SP}{DIGITS}   { buffers = atoi(yytext + 8); }
^Cached:{SP}{DIGITS}    { cached = atoi(yytext + 7); }

.|\n                    { }

%%

int main(void)
{
  const char meminfo[] = "/proc/meminfo";
  yyin = fopen(meminfo, "r");
  if (!yyin) {
    fprintf(stderr, "Cannot open %s\n", meminfo);
    return 1;
  }
  int rc = yylex();
  if (rc) return rc;
  printf("%dm\n", (mem_free + buffers + cached) >> 10);
  return 0;
}


More information about the Haskell-Cafe mailing list