Version française
Home     About     Download     Resources     Contact us    
Browse thread
memory usage
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: John Lepikhin <john@i...>
Subject: Re: [Caml-list] Re: memory usage

> Yeah, I flushed the output and I used /dev/zero - I still see no
> 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 <PID>:

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    <-- ?
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