Merge lp:~jameinel/bzr/2.0.4-494406-serve-memory-leak into lp:bzr/2.0

Proposed by John A Meinel
Status: Merged
Merged at revision: not available
Proposed branch: lp:~jameinel/bzr/2.0.4-494406-serve-memory-leak
Merge into: lp:bzr/2.0
Diff against target: 38 lines (+8/-2)
2 files modified
NEWS (+7/-1)
bzrlib/_bencode_pyx.pyx (+1/-1)
To merge this branch: bzr merge lp:~jameinel/bzr/2.0.4-494406-serve-memory-leak
Reviewer Review Type Date Requested Status
Andrew Bennetts Approve
Review via email: mp+16369@code.launchpad.net
To post a comment you must log in.
Revision history for this message
John A Meinel (jameinel) wrote :

I managed to track down the memory leak on server-side operations to bzrlib.bencode.Encoder.

It turns out that Encoder was using '__del__' as its cleanup function, when it should have been '__dealloc__'. I don't know if __del__ ever gets called for Pyrex objects, but I do know that __dealloc__ always gets called. (And doesn't cause problems with GC cycles, as it gets put into the tp_dealloc slot.)

Anyway, this one-line patch gets rid of the memory leak as near as I can tell. (At least cycling on 'bzr commit' no longer leaks memory.)

It could also have a fair impact on codehostings 'lp-serve'. As that would be encoding a *lot* of bytes to send over the wire. This memory was also "dark" memory, in that it was allocated directly using 'malloc()' and thus not seen by Meliae. I'm not positive, but I think for every byte that 'bzr lp-serve' would send over the wire, it would get wrapped by a 'bencode' operation, which means that every byte sent out gets permanently leaked in memory. (Maybe we don't serve bulk data through a bencode wrapper.) At least, all of the response tuples are certainly encoded.

It doesn't affect my 'memory reduction' tests that I used for 2.1.0b3, because those were operating locally.

Revision history for this message
Andrew Bennetts (spiv) wrote :

My understanding of Pyrex is that it doesn't treat __del__ as a special method at all. This change makes perfectly good sense, good catch!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2009-12-15 22:04:24 +0000
3+++ NEWS 2009-12-18 22:33:13 +0000
4@@ -8,7 +8,7 @@
5 bzr 2.0.4 (not released yet)
6 ############################
7
8-:Codename: template
9+:Codename:
10 :2.0.4: ???
11
12 Compatibility Breaks
13@@ -25,6 +25,12 @@
14 exporting over the network significantly faster (54min => 9min in one
15 case). (John Arbash Meinel, #343218)
16
17+* ``bzr serve`` no longer slowly leaks memory. The compiled
18+ ``bzrlib.bencode.Encoder()`` class was using ``__del__`` to cleanup and
19+ free resources, and it should have been using ``__dealloc__``.
20+ This will likely have an impact on any other process that is serving for
21+ an extended period of time. (John Arbash Meinel, #494406)
22+
23 Improvements
24 ************
25
26
27=== modified file 'bzrlib/_bencode_pyx.pyx'
28--- bzrlib/_bencode_pyx.pyx 2009-06-05 01:48:32 +0000
29+++ bzrlib/_bencode_pyx.pyx 2009-12-18 22:33:13 +0000
30@@ -261,7 +261,7 @@
31 self.maxsize = maxsize
32 self.tail = p
33
34- def __del__(self):
35+ def __dealloc__(self):
36 free(self.buffer)
37 self.buffer = NULL
38 self.maxsize = 0

Subscribers

People subscribed via source and target branches