[Gc] Threads leak memory?

Ludovic Courtès ludo at gnu.org
Fri Oct 24 07:46:26 PDT 2008


While comparing my BDW-GC-based Guile with current Guile, I noticed
something fishy in terms of memory usage in the presence of pthreads on
GNU/Linux using GC 7.1.

A tiny script of mine (attached) allows me to measure the complete heap
usage of a Guile as seen by the OS.  To that end, it parses Linux'
`/proc/self/smaps' file and approximates the total heap size as the sum
of the mappings marked "[anon]" or "[heap]", plus all private anonymous
mappings (i.e., nameless mappings whose permission bits contain `p').
This approximation makes sense as Guile doesn't use `mmap ()' directly.

The script also displays the result of `GC_get_heap_size ()', which is
usually slightly smaller than what's measured with the above method,
since it does not include internal GC data structures, for instance
(typically the total is 1.5 times `GC_get_heap_size ()').

However, when a thread is created and terminates, the total measured via
`smaps' is as much as 18 times `GC_get_heap_size ()'; with 10 threads
created, it's 23 times `GC_get_heap_size ()'; it doesn't go much beyond
as the number of threads increases.

I confirmed with GDB that `GC_delete_thread ()' is actually called upon
thread exit, so I guess GC's cleanup procedure *is* performed.
`GC_dump ()' doesn't show any significant difference between the
single-thread and two-thread versions (e.g., the black list is pretty
much as large in both cases), though.

Any idea what's going wrong or what I should look at?

Thanks in advance,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: gc-profile.scm
Type: application/octet-stream
Size: 5914 bytes
Desc: The Guile profiling script
Url : https://napali.hpl.hp.com/pipermail/gc/attachments/20081024/4758b73f/gc-profile.obj

More information about the Gc mailing list