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
=== modified file 'NEWS'
--- NEWS 2009-12-15 22:04:24 +0000
+++ NEWS 2009-12-18 22:33:13 +0000
@@ -8,7 +8,7 @@
8bzr 2.0.4 (not released yet)8bzr 2.0.4 (not released yet)
9############################9############################
1010
11:Codename: template11:Codename:
12:2.0.4: ???12:2.0.4: ???
1313
14Compatibility Breaks14Compatibility Breaks
@@ -25,6 +25,12 @@
25 exporting over the network significantly faster (54min => 9min in one25 exporting over the network significantly faster (54min => 9min in one
26 case). (John Arbash Meinel, #343218)26 case). (John Arbash Meinel, #343218)
2727
28* ``bzr serve`` no longer slowly leaks memory. The compiled
29 ``bzrlib.bencode.Encoder()`` class was using ``__del__`` to cleanup and
30 free resources, and it should have been using ``__dealloc__``.
31 This will likely have an impact on any other process that is serving for
32 an extended period of time. (John Arbash Meinel, #494406)
33
28Improvements34Improvements
29************35************
3036
3137
=== modified file 'bzrlib/_bencode_pyx.pyx'
--- bzrlib/_bencode_pyx.pyx 2009-06-05 01:48:32 +0000
+++ bzrlib/_bencode_pyx.pyx 2009-12-18 22:33:13 +0000
@@ -261,7 +261,7 @@
261 self.maxsize = maxsize261 self.maxsize = maxsize
262 self.tail = p262 self.tail = p
263263
264 def __del__(self):264 def __dealloc__(self):
265 free(self.buffer)265 free(self.buffer)
266 self.buffer = NULL266 self.buffer = NULL
267 self.maxsize = 0267 self.maxsize = 0

Subscribers

People subscribed via source and target branches