<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2009/01/5f78645d7a4e6fa8b81fb7463499c76e"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-13T16:01:29"
  subject="Re: [Caml-list] Re: memory usage"
  prev="2009/01/ae503c1c2f4bb9e29394aac85b4110d9"
  next="2009/01/2f5d00de6b9c387999dd888337bb57b9"
  prev-in-thread="2009/01/dce041a4fbff95ebf478e0c47dc4fe06"
  next-in-thread="2009/01/e3d8df8aa8dc8aaa7e53b7f77dd8ffd3"
  prev-thread="2009/01/df2de1846d5559d3faa62662b822bba6"
  next-thread="2009/01/5bb736622b71197f45b645c4e626de56"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="memory usage">
<msg 
  url="2009/01/bdb3d4c35cff66ea7be1c275b5f87645"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-12T07:41:53"
  subject="memory usage">
<msg 
  url="2009/01/e4eaf4f820bcc524d576bbc14d55acea"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-01-12T08:39:16"
  subject="Re: [Caml-list] memory usage">
<msg 
  url="2009/01/3ffffb747e8fb2737d56d6f15906a6a2"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-12T09:14:13"
  subject="Re: [Caml-list] memory usage">
<msg 
  url="2009/01/593f14a13f6cfc4cafb1b283c45ddaa6"
  from="Sylvain Le Gall &lt;sylvain@l...&gt;"
  author="Sylvain Le Gall"
  date="2009-01-12T10:45:44"
  subject="Re: memory usage">
<msg 
  url="2009/01/c46a7815fd8b38524a6d61062255bb6a"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-12T11:28:21"
  subject="[Caml-list] Re: memory usage">
<msg 
  url="2009/01/56bab8bd7437a13d82231cb7b0f7123e"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-01-12T11:41:31"
  subject="Re: [Caml-list] Re: memory usage">
<msg 
  url="2009/01/b49c746cd7aade6ef27fa16971c513af"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-12T15:03:40"
  subject="Re: [Caml-list] Re: memory usage">
<msg 
  url="2009/01/857b0402f61e849b3d54008d0a34c8ff"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-01-12T19:55:25"
  subject="Re: [Caml-list] Re: memory usage">
</msg>
</msg>
<msg 
  url="2009/01/a0bda203ac057a468832f4734e9d297a"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-12T17:57:13"
  subject="Re: [Caml-list] Re: memory usage">
<msg 
  url="2009/01/6964c5f12939a3533765c4eeca1c659a"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-01-12T20:12:20"
  subject="Re: [Caml-list] Re: memory usage">
<msg 
  url="2009/01/f780bfd50b3219200f52cd0238ca708b"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-12T21:34:37"
  subject="Re: [Caml-list] Re: memory usage">
<msg 
  url="2009/01/dce041a4fbff95ebf478e0c47dc4fe06"
  from="Richard Jones &lt;rich@a...&gt;"
  author="Richard Jones"
  date="2009-01-12T22:01:31"
  subject="Re: [Caml-list] Re: memory usage">
<msg 
  url="2009/01/5f78645d7a4e6fa8b81fb7463499c76e"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-13T16:01:29"
  subject="Re: [Caml-list] Re: memory usage">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
<msg 
  url="2009/01/e3d8df8aa8dc8aaa7e53b7f77dd8ffd3"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-12T15:05:50"
  subject="Re: [Caml-list] memory usage">
</msg>
<msg 
  url="2009/01/727ffcb417322fa6253f028466ffca77"
  from="Florian Hars &lt;hars@b...&gt;"
  author="Florian Hars"
  date="2009-01-12T16:29:35"
  subject="Re: [Caml-list] memory usage">
<msg 
  url="2009/01/8dbf9add071cbdba9d0de2236b19ec61"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-12T16:44:54"
  subject="Re: [Caml-list] memory usage">
<msg 
  url="2009/01/4e5dda7ad406ebd71375072454f7dcb8"
  from="Sylvain Le Gall &lt;sylvain@l...&gt;"
  author="Sylvain Le Gall"
  date="2009-01-12T17:55:37"
  subject="Re: memory usage">
<msg 
  url="2009/01/3e3b7d53accdc38893eac2582d8904f0"
  from="John Lepikhin &lt;john@i...&gt;"
  author="John Lepikhin"
  date="2009-01-12T18:02:02"
  subject="Re: [Caml-list] Re: memory usage">
<msg 
  url="2009/01/66abfef8939863574be285ef81b22ca2"
  from="Sylvain Le Gall &lt;sylvain@l...&gt;"
  author="Sylvain Le Gall"
  date="2009-01-12T18:26:51"
  subject="Re: memory usage">
</msg>
</msg>
</msg>
</msg>
</msg>
</msg>
</thread>

<contents>

&gt; Yeah, I flushed the output and I used /dev/zero - I still see no
&gt; messages.

That's strange. Anyway, it looks like a memory leak, isn't it?

20 threads * 1KB max = 20 KB of memory for data storage should be used
(plus 20KB*500% for heap overhead = 100KB). I changed delay to 1 ms:

ignore (Unix.select [] [] [] 0.001);

After 2 minutes of work on FreeBSD, 19MB(!) was used:

# ps auxw | grep a.out | grep -v grep
root 35136 30.1  0.2 60348 19304  p5  L+    1:36PM   2:08.07 ./a.out

# pmap &lt;PID&gt;:

Address              Kbytes  RSS Shared Priv Mode  Mapped File
0000000000400000        204  360      -  360 r-x   /tmp/a.out
0000000000532000         80   76      -   80 rw-   /tmp/a.out
0000000000546000         28   16      -   28 rw-     [ anon ]
0000000040532000        148  108    148    - r-x   /libexec/ld-elf.so.1
0000000040557000        132  108      -  132 rw-     [ anon ]
0000000040657000         28   28      -   28 rw-   /libexec/ld-elf.so.1
000000004065E000         24   20      -   24 rw-     [ anon ]
0000000040664000         92   76     92    - r-x   /lib/libm.so.5
000000004067B000          4    4      -    4 r-x   /lib/libm.so.5
000000004067C000       1024    0   1024    - r-x   /lib/libm.so.5
000000004077C000          8    8      -    8 rw-   /lib/libm.so.5
000000004077E000         64   64     64    - r-x   /lib/libthr.so.3
000000004078E000          4    4      -    4 r-x   /lib/libthr.so.3
000000004078F000       1024   12   1024    - r-x   /lib/libthr.so.3
000000004088F000         12   12      -   12 rw-   /lib/libthr.so.3
0000000040892000          8    8      -    8 rw-     [ anon ]
0000000040894000        932  452    932    - r-x   /lib/libc.so.7
000000004097D000          4    4      -    4 r-x   /lib/libc.so.7
000000004097E000       1020    0   1020    - r-x   /lib/libc.so.7
0000000040A7D000        116  116      -  116 rw-   /lib/libc.so.7
0000000040A9A000         92   36      -   92 rw-     [ anon ]
0000000040B00000      44032  13976    - 44032 rw-     [ anon ]
00007FFFF85A4000        128   12      -  128 rw-     [ anon ]
00007FFFF87A5000        128   12      -  128 rw-     [ anon ]
00007FFFF89A6000        128   12      -  128 rw-     [ anon ]
00007FFFF8BA7000        128   12      -  128 rw-     [ anon ]
00007FFFF8DA8000        128   12      -  128 rw-     [ anon ]
00007FFFF8FA9000        128   12      -  128 rw-     [ anon ]
...

(gdb) info thr
  18 Thread 0x40b01120 (LWP 101068)  0x00000000408e4d4c in _umtx_op ()
from /lib/libc.so.7
  17 Thread 0x40b01290 (LWP 100489)  0x0000000040971cfc in select ()
from /lib/libc.so.7
  16 Thread 0x40b01b30 (LWP 100079)  0x00000000408e4d4c in _umtx_op ()
from /lib/libc.so.7
  15 Thread 0x40b04d80 (LWP 100858)  0x0000000040971cfc in select ()
from /lib/libc.so.7
  14 Thread 0x40b02260 (LWP 101096)  0x00000000408e4d4c in _umtx_op ()
from /lib/libc.so.7
  13 Thread 0x40b04200 (LWP 101128)  0x0000000040971cfc in select ()
from /lib/libc.so.7
  12 Thread 0x40b03960 (LWP 101175)  0x00000000408e4d4c in _umtx_op ()
from /lib/libc.so.7
  11 Thread 0x40b02820 (LWP 101189)  0x00000000408e4d4c in _umtx_op ()
from /lib/libc.so.7
  10 Thread 0x40b03680 (LWP 101217)  0x00000000408e4d4c in _umtx_op ()
from /lib/libc.so.7
  9 Thread 0x40b03f20 (LWP 100057)  0x00000000408e4d4c in _umtx_op ()
from /lib/libc.so.7
  8 Thread 0x40b020f0 (LWP 100066)  0x0000000040971cfc in select ()
from /lib/libc.so.7
  7 Thread 0x40b05ec0 (LWP 100535)  0x0000000040971cfc in select ()
from /lib/libc.so.7
  6 Thread 0x40b04370 (LWP 100564)  0x00000000408e4d4c in _umtx_op ()
from /lib/libc.so.7
  5 Thread 0x40b04c10 (LWP 100698)  0x0000000040971cfc in select ()
from /lib/libc.so.7
  4 Thread 0x40b02b00 (LWP 101224)  0x0000000040971cfc in select ()
from /lib/libc.so.7
  3 Thread 0x40b03ad0 (LWP 101227)  0x0000000040971cfc in select ()
from /lib/libc.so.7
  2 Thread 0x40b037f0 (LWP 101258)  0x00000000408e4d4c in _umtx_op ()
from /lib/libc.so.7
* 1 Thread 0x40b05620 (LWP 100101)  0x00000000409643dc in open ()
from /lib/libc.so.7
(gdb) 

I also added special thread to check GC:

let print_stats _ =
  while true do
    Gc.compact ();
    Gc.print_stat stdout;
    flush stdout;
    Unix.sleep 10;
  done

Thread.create print_stats ();

GC statistics after 1 minute:

minor_words: 21929847    &lt;-- ?
promoted_words: 2474840
major_words: 2939105
minor_collections: 1655
major_collections: 635
heap_words: 61440
heap_chunks: 1
top_heap_words: 61440
live_words: 1024
live_blocks: 115
free_words: 60416
free_blocks: 1
largest_free: 60416
fragments: 0
compactions: 7


</contents>

</message>

