develooper Front page | perl.perl5.porters | Postings from November 2008

[perl #60774] threads memory leak on linux 2.6

Thread Next
From:
perlbug-followup
Date:
November 24, 2008 08:37
Subject:
[perl #60774] threads memory leak on linux 2.6
Message ID:
rt-3.6.HEAD-10965-1227538123-1477.60774-75-0@perl.org
# New Ticket Created by  reportbug@faxm0dem.org 
# Please include the string:  [perl #60774]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=60774 >



This is a bug report for perl from reportbug@faxm0dem.org,
generated with the help of perlbug 1.36 running under perl 5.10.0.


-----------------------------------------------------------------
[Please enter your report here]

I'm experiencing memleaks using threads; Running the following code uses up more and more memory, but quite unpredictably depending on the contents of $sub1:

--
use threads;
use strict;
use warnings;

for (;;) {
	my $thr = threads->new($sub1)->join;
	undef $thr;
}
--

I'm monitoring rss usage on linux and perl 5.10 using:

--
i=0; while :; do A=$(ps -C threads3 -o ppid,pid,cmd,rss --no-headers); [ -n "$A" ] && echo $i $A || i=0 ; sleep 1; i=$(($i+1)); done
--

Here's the output of this, with different values of $sub1:

--
# $sub1 = sub { my $a=[ 1 .. 10000] };
1 19959 1137 /usr/bin/perl ./threads3 5276
2 19959 1137 /usr/bin/perl ./threads3 5140
3 19959 1137 /usr/bin/perl ./threads3 5700
[...]
642 19959 1137 /usr/bin/perl ./threads3 124244
643 19959 1137 /usr/bin/perl ./threads3 124736
644 19959 1137 /usr/bin/perl ./threads3 125380
# $sub1 = sub { my $a=[ 1 .. 100000] };
1 19959 8329 /usr/bin/perl ./threads3 24176
2 19959 8329 /usr/bin/perl ./threads3 24176
3 19959 8329 /usr/bin/perl ./threads3 24176
[...]
642 19959 8329 /usr/bin/perl ./threads3 28368
643 19959 8329 /usr/bin/perl ./threads3 26036
644 19959 8329 /usr/bin/perl ./threads3 34460
# $sub1 = sub { };
1 19959 13288 /usr/bin/perl ./threads3 3152
2 19959 13288 /usr/bin/perl ./threads3 3796
3 19959 13288 /usr/bin/perl ./threads3 4564
[...]
642 19959 13288 /usr/bin/perl ./threads3 400640
643 19959 13288 /usr/bin/perl ./threads3 401312
644 19959 13288 /usr/bin/perl ./threads3 401980
--

$sub1 = sub { my $a=[ 1 .. 100000] } seems to have minor memleak, while
$sub1 = sub { } does the most damage.

Also using a small pause betwee thread creation doesn't improve the situation.
(select undef, undef, undef, 0.1;)

Now I tried the code on perl 5.8.5 linux 2.6 x86_64, and it does not memleak.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=library
    severity=high
---
Site configuration information for perl 5.10.0:

Configured by Debian Project at Sun Oct  5 13:26:12 UTC 2008.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.6.18-6-xen-amd64, archname=x86_64-linux-gnu-thread-multi
    uname='linux sid 2.6.18-6-xen-amd64 #1 smp fri jun 6 06:38:05 utc 2008 x86_64 gnulinux '
    config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN -Dcccdlflags=-fPIC -Darchname=x86_64-linux-gnu -Dprefix=/usr -Dprivlib=/usr/share/perl/5.10 -Darchlib=/usr/lib/perl/5.10 -Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5 -Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local -Dsitelib=/usr/local/share/perl/5.10.0 -Dsitearch=/usr/local/lib/perl/5.10.0 -Dman1dir=/usr/share/man/man1 -Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1 -Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl -Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio -Uusenm -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib -Dlibperl=libperl.so.5.10.0 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing -pipe -I/usr/local/include'
    ccversion='', gccversion='4.3.2', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=/lib/libc-2.7.so, so=so, useshrplib=true, libperl=libperl.so.5.10.0
    gnulibc_version='2.7'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib'

Locally applied patches:
    

---
@INC for perl 5.10.0:
    /home/fwernli/.perlib/share/perl/5.10.0
    /home/fwernli/.perlib/share/perl
    /home/fwernli/.perlib/lib/perl/5.10.0
    /home/fwernli/.perlib/lib/perl
    /home/fwernli/.perlib/lib/perl5/x86_64-linux-gnu-thread-multi
    /home/fwernli/.perlib/lib/perl5
    /usr/share/perl5/Debconf/DbDriver
    /etc/perl
    /usr/local/lib/perl/5.10.0
    /usr/local/share/perl/5.10.0
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.10
    /usr/share/perl/5.10
    /usr/local/lib/site_perl
    .

---
Environment for perl 5.10.0:
    HOME=/home/fwernli
    LANG=C
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=:/opt/bin::/opt/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/home/fwernli/script:/home/fwernli/script/lcg:/home/fwernli/script:/home/fwernli/script/lcg
    PERL5LIB=/home/fwernli/.perlib/share/perl:/home/fwernli/.perlib/lib/perl:/home/fwernli/.perlib/lib/perl5:/usr/share/perl5/Debconf/DbDriver
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About