[Gc] Re: Threads leak memory?

Ludovic Courtès ludo at gnu.org
Sun Nov 2 13:16:59 PST 2008


ludo at gnu.org (Ludovic Courtès) writes:

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

The phenomenon has apparently nothing to do with libgc: threads in my
program are detached, and the storage associated with these threads is
not necessarily reclaimed by the time the program parses
`/proc/self/smaps', hence the apparently large heap.

The attached C program reproduces the problem.  Running it several times
shows that the displayed "VM size" varies between 8 and 25 MiB,
depending on timing.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: ,,libgc-pthread.c
Type: application/octet-stream
Size: 2082 bytes
Desc: The program
Url : https://napali.hpl.hp.com/pipermail/gc/attachments/20081102/873f5d5a/libgc-pthread.obj

More information about the Gc mailing list