From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753276AbcHPOZb (ORCPT ); Tue, 16 Aug 2016 10:25:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:3623 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751936AbcHPOZa (ORCPT ); Tue, 16 Aug 2016 10:25:30 -0400 Date: Tue, 16 Aug 2016 16:25:12 +0200 From: Oleg Nesterov To: Brenden Blanco , Johannes Weiner , Michal Hocko , Vladimir Davydov Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Alexander Shishkin , Alexei Starovoitov Subject: Re: uprobes: memory leak in enable/disable loop Message-ID: <20160816142511.GB17006@redhat.com> References: <20160815205810.GA22619@gmail.com> <20160816141350.GA17006@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20160816141350.GA17006@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 16 Aug 2016 14:25:29 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 08/16, Oleg Nesterov wrote: > > On 08/15, Brenden Blanco wrote: > > > > Hi folks, > > > > I think I have come across a memory leak in uprobes, which is fairly easy to > > reproduce. > > At first glance this looks as a problem in memcg, add CC's... > > put_page(old_page) looks properly balanced, and I assume we do not need > the additional "uncharge", we can rely on __page_cache_release(). > > And I do not see any leak if I try to reproduce with CONFIG_MEMCG=n. Heh. it seems that mem_cgroup_*() logic was always wrong in __replace_page(). Could you try the patch below? Oleg. --- --- x/kernel/events/uprobes.c +++ x/kernel/events/uprobes.c @@ -200,7 +200,8 @@ static int __replace_page(struct vm_area err = 0; unlock: - mem_cgroup_cancel_charge(kpage, memcg, false); + if (err) + mem_cgroup_cancel_charge(kpage, memcg, false); mmu_notifier_invalidate_range_end(mm, mmun_start, mmun_end); unlock_page(page); return err;