Snow Leopard Erlang woes (and the fix!)


After upgrading to Snow Leopard, I found my os_mon erlang application exploded in a very ugly error message.

=CRASH REPORT==== 12-Oct-2009::23:29:20 ===
      initial call: memsup:init/1
      pid: <0.76.0>
      registered_name: memsup
      exception exit: {{badmatch,{error,{fread,input}}},
        in function  gen_server:terminate/6
      ancestors: [os_mon_sup,<0.46.0>]
      messages: []
      links: [<0.47.0>]
      dictionary: []
      trap_exit: true
      status: running
      heap_size: 233
      stack_size: 24
      reductions: 172

After some investigation, it turns out that Snow Leopard changed their output on vm_stat, the tool to look at the memory available on the system. The new output added the line:

Pages speculative:                   42219.

Where the erlang module memsup depends upon that not being there. The erlang developers get the ugliness. In any case, the patch looks like:

--- a/lib/os_mon/src/memsup.erl
+++ b/lib/os_mon/src/memsup.erl
@@ -728,8 +728,12 @@ get_memory_usage({unix,darwin}) ->
        io_lib:fread("Pages active:~d.", skip_to_eol(Str2)),
     {ok, [Inactive],Str4} =
        io_lib:fread("Pages inactive:~d.", skip_to_eol(Str3)),
+         {ok, _,Str5} =
+       io_lib:fread("Pages speculative:~d.", skip_to_eol(Str4)),
     {ok, [Wired],_} =
-       io_lib:fread("Pages wired down:~d.", skip_to_eol(Str4)),
+       io_lib:fread("Pages wired down:~d.", skip_to_eol(Str5)),
+  %     {ok, [Wired],_} =
+  % io_lib:fread("Pages wired down:~d.", skip_to_eol(Str4)),
     NMemUsed  = (Wired + Active + Inactive) * 4000,
     NMemTotal = NMemUsed + Free * 4000,

Save this to a file, such as /tmp/erlang_patch. Full instructions for upgrading your erlang:

git clone git://
cd erlang-otp
patch -l -i /tmp/erlang_patch -p1
./configure --prefix=/opt/erlang --enable-hipe
make install
export PATH=/opt/erlang/bin:$PATH

After that, you should be able to start os_mon:

1> application:start(sasl).
2> application:start(os_mon).

If it starts, you're done!

Hope this helps.

Fixed typo, thanks to Craig Krigsman