From: Wei Liu Subject: Re: [PATCH] python/xc: add missing Py_DECREF() to fix a memory leak Date: Mon, 31 Aug 2015 13:04:56 +0100 Message-ID: <20150831120456.GA22586@zion.uk.xensource.com> References: <1440797718-28045-1-git-send-email-zhigang.x.wang@oracle.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1ZWNpv-0005wI-0v for xen-devel@lists.xenproject.org; Mon, 31 Aug 2015 12:05:19 +0000 Content-Disposition: inline In-Reply-To: <1440797718-28045-1-git-send-email-zhigang.x.wang@oracle.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Zhigang Wang Cc: xen-devel@lists.xenproject.org, wei.liu2@citrix.com List-Id: xen-devel@lists.xenproject.org On Fri, Aug 28, 2015 at 05:35:18PM -0400, Zhigang Wang wrote: > Python PyList_Append() will increase reference count of the item. We have to > decrease its reference count to let it garbage collected. > > We missed the Py_DECREF() for 'cpuinfo_obj' here, thus we have a memory leak. > > The memory leak could be easily confirmed by: > > # python > >>> import xen.lowlevel.xc > >>> xc = xen.lowlevel.xc.xc() > >>> for i in range(1000): xc.getcpuinfo(1) > > And check the python process memory usage before and after: > > # ps f -o vsize,rss,%mem,size,cmd -p > > Signed-off-by: Zhigang Wang Acked-by: Wei Liu There is no in-tree user of python binding, I was planning to remove it in 4.7 window. But it seems like Oracle is still actively using it? Would you be happy to step up to be the maintainer of this binding? I wouldn't expect too much traffic regarding this piece of code (there were only 8 commits so far in this cycle touching this binding, most of which cosmetic), so the workload wouldn't be a big problem. With a maintainer and active user in place we can probably avoid some of the back and forth when touching this piece of code. For example: commit ec55a3ae01a5be34d9a753781fba41d5930569f0 Author: Wei Liu Date: Mon Jul 27 18:45:08 2015 +0100 python/xc: reinstate original implementation of next_bdf I missed the fact that next_bdf is used to parsed user supplied strings when reviewing. The user supplied string is a NULL-terminated string separated by comma. User can supply several PCI devices in that string. There is, however, no delimiter for different devices, hence we can't change the syntax of that string. This patch reinstate the original implementation of next_bdf to preserve the original syntax. The last argument for xc_assign_device is always 0. Signed-off-by: Wei Liu Acked-by: Ian Campbell commit 9b34056cb4cab826771dba031735f77a02df015c Author: Tiejun Chen Date: Wed Jul 22 01:40:08 2015 +0000 tools: extend xc_assign_device() to support rdm reservation policy This patch passes rdm reservation policy to xc_assign_device() so the policy is checked when assigning devices to a VM. Note this also bring some fallout to python usage of xc_assign_device(). CC: Ian Jackson CC: Stefano Stabellini CC: Ian Campbell CC: Wei Liu CC: David Scott Signed-off-by: Tiejun Chen Acked-by: Wei Liu You will also get least surprise when using the binding in new version of Xen. Wei.