Bug 548249
Summary: | Perl threads leak memory when detached | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Product: | Red Hat Enterprise Linux 5 | Reporter: | Bryan Mason <bmason> | ||||||||||
Component: | perl | Assignee: | perl-maint-list | ||||||||||
Status: | CLOSED ERRATA | QA Contact: | Petr Šplíchal <psplicha> | ||||||||||
Severity: | high | Docs Contact: | |||||||||||
Priority: | urgent | ||||||||||||
Version: | 5.4 | CC: | cww, jpazdziora, jwest, ohudlick, ovasik, plyons, ppisar, psplicha, rkhadgar, schlichting, spoyarek | ||||||||||
Target Milestone: | rc | Keywords: | Patch, ZStream | ||||||||||
Target Release: | --- | ||||||||||||
Hardware: | All | ||||||||||||
OS: | Linux | ||||||||||||
URL: | http://rt.perl.org/rt3/Ticket/Display.html?id=80484 | ||||||||||||
Whiteboard: | |||||||||||||
Fixed In Version: | perl-5.8.8-29.el5 | Doc Type: | Bug Fix | ||||||||||
Doc Text: |
Cause
Perl appears to leak memory when threads are created and then detached.
Consequence
The program consumed memory, seemingly without bounds.
Fix
Perl internal is freed.
Result
No huge memory leaks after detaching of threads.
|
Story Points: | --- | ||||||||||
Clone Of: | Environment: | ||||||||||||
Last Closed: | 2012-02-21 05:39:41 UTC | Type: | --- | ||||||||||
Regression: | --- | Mount Type: | --- | ||||||||||
Documentation: | --- | CRM: | |||||||||||
Verified Versions: | Category: | --- | |||||||||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||||||||
Cloudforms Team: | --- | Target Upstream Version: | |||||||||||
Embargoed: | |||||||||||||
Bug Depends On: | 641320 | ||||||||||||
Bug Blocks: | 502912, 590060, 701632 | ||||||||||||
Attachments: |
|
Description
Bryan Mason
2009-12-17 01:36:51 UTC
This request was evaluated by Red Hat Product Management for inclusion in the current release of Red Hat Enterprise Linux. Because the affected component is not scheduled to be updated in the current release, Red Hat is unfortunately unable to address this request at this time. Red Hat invites you to ask your support representative to propose this request, if appropriate and relevant, in the next release of Red Hat Enterprise Linux. The test case is wrong as it can create threads faster than they terminate. Better test case: use threads; sub ThreadRoutine {} while (1) { $thread = threads->new(\&ThreadRoutine); $thread->join; } Created attachment 442431 [details]
Script measuring leaked memory per thread
This code can be used to test how much memory leaks per thread.
The memory must be ballooned in memory() function to prevent other leaks/fragmentation of different type. Also calling the memory() as &memory is important part of ballooning (yet another bug).
This bug presents in 5.8 branch only (5.9.0 and higher are not affected). 5.8.0 is ok, 5.8.8 tip is broken. I identified 5f2f4dbeb153fb32f97b9eec41efcf5c3e2f2a81 commit (some Win32 related things) as first one introducing this bug. However simple revert does not fix 5.8.8. There are other bugs introduced later after the commit probably. I will try to found them (319 interleaving commits). Created attachment 442606 [details]
Script measuring leaked memory per thread
Former test contained a race (measure while running worker thread). This one is better. However it does behaves differently depending on ballooning.
Bisects show two different places where bug has been introduced:
3848b9623cf7b0bd4a28a02073a51953b168b7a6 Bad (perl-5.8.0-749-g3848b96)
26ab6a78adda605ad55978d97dd5c8d4b282375a Bad (perl-5.8.7-76-g26ab6a7)
I'm still trying to find the latest one.
Created attachment 443303 [details]
Proposed fix
This patch reverts 26ab6a78adda605ad55978d97dd5c8d4b282375a (1200 lines) that introduced the memory leaks in perl-5.8.8.
The reverted patch changed a way ho to manipulate with perl variables to get simpler (and maybe faster) code.
With the revert, all tests bundled within perl-5.8.8 pass (except those that failed before either), the measurement script shows 0 leaks, the test case from this bug does not grow perl memory.
Everything seems O.k. so far, but I'm not able to tell whether this patch introduce some other (performance) bugs. It's quite long patch.
5.8.9 (last maintenance version of 5.8 released by upstream) and HEAD of maint-5.8 branch (VCS branch for 5.8 development) is affected too. Thus my revert is currently only way how to fix this issue without rebasing to 5.10. Created attachment 464991 [details]
Reduced fix
I went through the patch today and reduced it to the one-liner attached. This is working the same as the 12k+ chunk in terms of memory allocation and does not seem to have any regressions.
Technical note added. If any revisions are required, please edit the "Technical Notes" field accordingly. All revisions will be proofread by the Engineering Content Services team. New Contents: Cause Perl appears to leak memory when threads are created and then detached. Consequence The program consumed memory, seemingly without bounds. Fix Perl internal is freed. Result No huge memory leaks after detaching of threads. Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory, and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. http://rhn.redhat.com/errata/RHBA-2012-0199.html |