Skip Menu |
 

This queue is for tickets about the Proc-ProcessTable CPAN distribution.

Report information
The Basics
Id: 100048
Status: resolved
Priority: 0/
Queue: Proc-ProcessTable

People
Owner: cpan [...] bargsten.org
Requestors: tom [...] eborcom.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.50
Fixed in: (no value)



Subject: Proc::ProcessTable Leaks Memory
Download (untitled) / with headers
text/plain 534b
When I use Proc::ProcessTable with code that calls fork() and exit(), my process leaks memory. When I use Devel::SizeMe instead, I see no leaks. As far as I can tell, this happens due to a leak somewhere in Proc::ProcessTable. I'm running Ubuntu 12.04.4 which uses Linux kernel 3.8.0-42. The attached scripts demonstrate the leak with Proc::ProcessTable (fork_leak.pl) and the absence of the leak with Devel::SizeMe (fork_no_leak.pl). Please let me know if I can provide more information to help resolve this problem. Tom Hukins
Subject: fork_leak.pl
Download fork_leak.pl
text/x-perl 448b
#!perl use strict; use warnings; use List::Util 'first'; use Proc::ProcessTable (); sub _do_a_fork { my $pid = fork(); if ( $pid == 0 ) { exit 0; } waitpid 1, $pid; } my $proc_table = Proc::ProcessTable->new; foreach my $i (0 .. 1_000_000 ) { unless ( $i % 100 ) { my $process = first { $_->pid == $$ } @{ $proc_table->table }; print "Count $i Size ", $process->rss, "\n"; } _do_a_fork(); }
Subject: fork_no_leak.pl
Download fork_no_leak.pl
text/x-perl 336b
#!perl use strict; use warnings; use List::Util 'first'; use Devel::SizeMe 'perl_size'; sub _do_a_fork { my $pid = fork(); if ( $pid == 0 ) { exit 0; } waitpid 1, $pid; } foreach my $i (0 .. 1_000_000 ) { unless ( $i % 100 ) { print "Count $i Size ", perl_size(), "\n"; } _do_a_fork(); }
Download (untitled) / with headers
text/plain 348b
What is 'waitpid 1, $pid;' (taken from your testscript) supposed to do? As far as i understand you're creating a bunch of zombies, therefore a bigger list of process, therefore a bigger memory footprint with every iteration. When i use 'waitpid $pid;' or 'waitpid -1;' the memory usage is constant as its supposed to be. Best regards, marderh
Subject: Re: [rt.cpan.org #100048] Proc::ProcessTable Leaks Memory
Date: Thu, 29 Jan 2015 16:04:38 +0000
To: Stefan Kopetzky via RT <bug-Proc-ProcessTable [...] rt.cpan.org>
From: Tom Hukins <tom [...] eborcom.com>
Download (untitled) / with headers
text/plain 515b
Hi, Stefan. Thank you for looking at the problem I reported. On Thu, Jan 29, 2015 at 10:21:02AM -0500, Stefan Kopetzky via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=100048 > > > What is 'waitpid 1, $pid;' (taken from your testscript) supposed to do?
I thought it meant "wait for the forked process to exit" but I realise it doesn't. If I replace 'waitpid 1, $pid;' with the correct 'waitpid $pid, 0;' I see no memory leak. I apologise for mistakenly reporting a non-existent problem. Tom
Download (untitled) / with headers
text/plain 391b
I should have read the waitpid documentation better. I was already fiddling around with it, but I could not generate stable test conditions (the "memory leak" was not consistent in different runs). Now I know why. Nice that it is solved. In any case: it is better to report a non-existent bug than not to report an existing bug. So thanks for reporting, Tom, and thanks for solving, marderh.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.