From: HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com>
To: tromey@redhat.com
Cc: gdb-patches@sourceware.org
Subject: Re: question: python gc doesn't collect buffer allocated by read_memory()
Date: Tue, 27 Mar 2012 01:52:00 -0000 [thread overview]
Message-ID: <20120327.105206.71087856.d.hatayama@jp.fujitsu.com> (raw)
In-Reply-To: <87iphrs3ip.fsf@fleche.redhat.com>
Hello Tom,
From: Tom Tromey <tromey@redhat.com>
Subject: Re: question: python gc doesn't collect buffer allocated by read_memory()
Date: Mon, 26 Mar 2012 10:58:22 -0600
>>>>>> ">" == HATAYAMA Daisuke <d.hatayama@jp.fujitsu.com> writes:
>
>>> Sorry for missing. I first found this on gdb-7.2-48.el6.x86_64. I used
>>> 7.4 in the presentation of the first mail.
>
> Thanks.
>
>>> On the other hand, it appears to me that buffer objects returned by
>>> inferior.read_memory() is never collected by gc.collect().
>
> I think I found the problem.
>
> The issue is that PyBuffer_FromReadWriteObject acquires a reference to
> the base object -- but the code in gdb assumed that it stole a reference.
>
> Could you try the appended patch?
> It works for me; if it works for you, I will put it in.
> If you can't try it, I'll just assume it is ok and go ahead...
>
> Tom
>
Thanks! I was also looking into py-inferior.c but I've first started
with studying python gc and it must have been taken more time.
I tried your patch using gdb of today's daily update and the same
script below.
import gdb
import gc
i = gdb.inferiors()[0]
buf = gdb.parse_and_eval('buf')
count = 100000
while count >= 0:
i.read_memory(buf.address, buf.type.sizeof)
count -= 1
gc.collect()
I typed ps aux command to see VSZ/RSS each time I executed the script
above that reads 4KB buffer 100000 times so about 390MB total.
[Before]
$ ps aux | head -1
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
$ ps aux | grep gdb | grep -v grep
hat 28438 1.0 0.3 81936 12340 pts/1 S+ 10:15 0:00 /media/pub/repos/gdb/gdb/gdb ./testpro ./core.27403
$ ps aux | grep gdb | grep -v grep
hat 28438 9.3 10.7 491876 422296 pts/1 S+ 10:15 0:01 /media/pub/repos/gdb/gdb/gdb ./testpro ./core.27403
400 MB increased.
[After]
$ ps aux | head -1
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
$ ps aux | grep gdb | grep -v grep
hat 28446 8.6 0.4 86164 16756 pts/1 S+ 10:15 0:00 /media/pub/repos/gdb/gdb.fixed ./testpro ./core.27403
$ ps aux | grep gdb | grep -v grep
hat 28446 1.5 0.5 90928 21444 pts/1 S+ 10:15 0:01 /media/pub/repos/gdb/gdb.fixed ./testpro ./core.27403
4 MB increased.
So, it seems to me that buffers allocated in infpy_read_memory() are
now collected sanely. I confirm the issue I reported has been fixed.
BTW, there is still about 4MB increment. I tried two more times, then
still saw constant increase.
$ ps aux | grep gdb | grep -v grep
hat 28446 2.1 0.6 95548 26132 pts/1 S+ 10:15 0:02 /media/pub/repos/gdb/gdb.fixed ./testpro ./core.27403
$ ps aux | grep gdb | grep -v grep
hat 28446 0.7 0.7 100304 30820 pts/1 S+ 10:15 0:02 /media/pub/repos/gdb/gdb.fixed ./testpro ./core.27403
And the increment can be reproduced by simplifying the script to
i.read_memory() only.
(gdb) python
>count=100000
>while count >= 0:
> i.read_memory(addr, size)
> count -= 1
>gc.collect()
>end
I suspect another objects allocated remain while not collected.
Thanks.
HATAYAMA, Daisuke
next prev parent reply other threads:[~2012-03-27 1:52 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-19 6:17 HATAYAMA Daisuke
2012-03-20 20:59 ` Tom Tromey
2012-03-21 4:16 ` HATAYAMA Daisuke
2012-03-26 18:56 ` Tom Tromey
2012-03-27 1:52 ` HATAYAMA Daisuke [this message]
2012-03-28 17:37 ` Tom Tromey
2012-03-29 0:49 ` HATAYAMA Daisuke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120327.105206.71087856.d.hatayama@jp.fujitsu.com \
--to=d.hatayama@jp.fujitsu.com \
--cc=gdb-patches@sourceware.org \
--cc=tromey@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox