R13B02-1: badmatch in memsup:get_memory_usage (Mac OS X 10.6)

Winston Smith <>
Sat Oct 17 19:13:43 CEST 2009


I found the problem, the output of vm_stat has changed in Snow Leopard
(10.6) and the code in memsup.erl, in get_memory_usage({unix,darwin})
fails to read the number of pages wired:

get_memory_usage({unix,darwin}) ->
    Str = os:cmd("/usr/bin/vm_stat"),
    {ok, [Free],Str2} = io_lib:fread("Pages free:~d.",skip_to_eol(Str)),
    {ok, [Active],Str3} =
	io_lib:fread("Pages active:~d.", skip_to_eol(Str2)),
    {ok, [Inactive],Str4} =
	io_lib:fread("Pages inactive:~d.", skip_to_eol(Str3)),
    {ok, [Wired],_} =
	io_lib:fread("Pages wired down:~d.", skip_to_eol(Str4)),		%% FAILS HERE
    NMemUsed  = (Wired + Active + Inactive) * 4000,
    NMemTotal = NMemUsed + Free * 4000,
    {NMemUsed,NMemTotal};


Here's the new output of vm_stat (they've inserted "Pages speculative"
before "Pages wired down" comparing to 10.5):

winston$ /usr/bin/vm_stat
Mach Virtual Memory Statistics: (page size of 4096 bytes)
Pages free:                         110845.
Pages active:                       563208.
Pages inactive:                     201387.
Pages speculative:                    8936.
Pages wired down:                   164629.
"Translation faults":            128602101.
Pages copy-on-write:               2406604.
Pages zero filled:                66882837.
Pages reactivated:                   39662.
Pageins:                            232245.
Pageouts:                            12164.
Object cache: 173 hits of 69999244 lookups (0% hit rate)


Hope this helps!

Thanks.


On Sat, Oct 17, 2009 at 12:14 AM, Winston Smith
<> wrote:
> Running R13B02-1 on Mac OS 10.6.2 (x86_64), I'm seeing the following
> error when I start my OTP application:
>
> =SUPERVISOR REPORT==== 17-Oct-2009::00:10:08 ===
>     Supervisor: {local,os_mon_sup}
>     Context:    child_terminated
>     Reason:     {{badmatch,{error,{fread,input}}},
>                  [{memsup,get_memory_usage,1},
>                   {memsup,'-handle_info/2-fun-0-',2}]}
>     Offender:   [{pid,<0.74.0>},
>                  {name,memsup},
>                  {mfa,{memsup,start_link,[]}},
>                  {restart_type,permanent},
>                  {shutdown,2000},
>                  {child_type,worker}]
>
>
> Not sure how to diagnose this further ...
>


More information about the erlang-bugs mailing list