Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp176856imm; Thu, 26 Jul 2018 16:27:21 -0700 (PDT) X-Google-Smtp-Source: AAOMgpd7T2f1nwDg3Z+apROX/6aBSoTl/pzmRsPIxWkDeJ4zSCkD+yrDIvJnidl1o002m702MqxK X-Received: by 2002:a17:902:2006:: with SMTP id n6-v6mr3644960pla.325.1532647641824; Thu, 26 Jul 2018 16:27:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532647641; cv=none; d=google.com; s=arc-20160816; b=BLFBgmgIoFSIrJ1fi6Y8Ka8ey+06o5yT4SY1fvpyX83OpwhmcBwOh1yxwmGV6cNjY9 B578C0bxZSdhEDSlcf6jSpB+QCxjHFTylyrbGBxNiXzZA8RmfmujegYYDHWyWMzew1vu f0v6DCK4vzEizyMWg7hpsiN7Cz7oGjdu2mD++zKsnTgAzv4TLM9nmJfRd3skOZ9EITSt f59jzxPnr0XNI2cumVL+4v+0Kng1PyniJ0q/W7DJx1bbh7Ixqf6JlUgL4tEPbpbw1Nc9 rStofEf/i4igHAK5c9UBCMdEvwnwAC3iqr7ZC7x08lugH5uQEsnkA1w1pxq33kBbrNQt +rkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=gUavw0S65tNox/mhYGmRbte9J228SJZ3sLZxCEFfL6M=; b=NRLFWBXscbGJf+vmYZxi2BrSUfo5JgqaICbvWRDllq9iq87I8MlGLnLpxkPanPqoI6 ngM5dVNrvgBETXBiUmyDRffGKetdqFRR8Th5Txr+CSDLgML6KC7szT7DLpg/ebbCV6C+ 74ynp5QcWtpRheVXgEYmS9uRcJDU/ozquUujcykputLekHWZ8XlcMFPXBKr/SHKjLaIV xNXrDqpTeAK/tOFrEordVPgArf5/C8piTolGQKZKR93YdhwNCbk3frRyunO0+inAIqCA Le30V8SkLrW/q152xhJ6NNRCOMcZY2aJs87700s0cOtuEzd/pmEUszOsJJx3rccckvZP OROw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w6-v6si2498936pgb.61.2018.07.26.16.27.04; Thu, 26 Jul 2018 16:27:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731773AbeG0AoR (ORCPT + 99 others); Thu, 26 Jul 2018 20:44:17 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:55942 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730610AbeG0AoQ (ORCPT ); Thu, 26 Jul 2018 20:44:16 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.92]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C2A14CC0; Thu, 26 Jul 2018 23:25:13 +0000 (UTC) Date: Thu, 26 Jul 2018 16:25:12 -0700 From: Andrew Morton To: Michal Hocko Cc: Kirill Tkhai , hannes@cmpxchg.org, vdavydov.dev@gmail.com, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] memcg: Remove memcg_cgroup::id from IDR on mem_cgroup_css_alloc() failure Message-Id: <20180726162512.6056b5d7c1d2a5fbff6ce214@linux-foundation.org> In-Reply-To: <20180413125101.GO17484@dhcp22.suse.cz> References: <20180413110200.GG17484@dhcp22.suse.cz> <06931a83-91d2-3dcf-31cf-0b98d82e957f@virtuozzo.com> <20180413112036.GH17484@dhcp22.suse.cz> <6dbc33bb-f3d5-1a46-b454-13c6f5865fcd@virtuozzo.com> <20180413113855.GI17484@dhcp22.suse.cz> <8a81c801-35c8-767d-54b0-df9f1ca0abc0@virtuozzo.com> <20180413115454.GL17484@dhcp22.suse.cz> <20180413121433.GM17484@dhcp22.suse.cz> <20180413125101.GO17484@dhcp22.suse.cz> X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 13 Apr 2018 14:51:01 +0200 Michal Hocko wrote: > On Fri 13-04-18 14:14:33, Michal Hocko wrote: > [...] > > Well, this is probably a matter of taste. I will not argue. I will not > > object if Johannes is OK with your patch. But the whole thing confused > > hell out of me so I would rather un-clutter it... > > In other words, this > This discussion has rather petered out. afaict we're waiting for hannes to offer an opinion? From: Kirill Tkhai Subject: memcg: remove memcg_cgroup::id from IDR on mem_cgroup_css_alloc() failure In case of memcg_online_kmem() failure, memcg_cgroup::id remains hashed in mem_cgroup_idr even after memcg memory is freed. This leads to leak of ID in mem_cgroup_idr. This patch adds removal into mem_cgroup_css_alloc(), which fixes the problem. For better readability, it adds a generic helper which is used in mem_cgroup_alloc() and mem_cgroup_id_put_many() as well. Link: http://lkml.kernel.org/r/152354470916.22460.14397070748001974638.stgit@localhost.localdomain Fixes 73f576c04b94 ("mm: memcontrol: fix cgroup creation failure after many small jobs") Signed-off-by: Kirill Tkhai Cc: Johannes Weiner Cc: Vladimir Davydov Cc: Michal Hocko Signed-off-by: Andrew Morton --- mm/memcontrol.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff -puN mm/memcontrol.c~memcg-remove-memcg_cgroup-id-from-idr-on-mem_cgroup_css_alloc-failure mm/memcontrol.c --- a/mm/memcontrol.c~memcg-remove-memcg_cgroup-id-from-idr-on-mem_cgroup_css_alloc-failure +++ a/mm/memcontrol.c @@ -4037,6 +4037,14 @@ static struct cftype mem_cgroup_legacy_f static DEFINE_IDR(mem_cgroup_idr); +static void mem_cgroup_id_remove(struct mem_cgroup *memcg) +{ + if (memcg->id.id > 0) { + idr_remove(&mem_cgroup_idr, memcg->id.id); + memcg->id.id = 0; + } +} + static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n) { VM_BUG_ON(atomic_read(&memcg->id.ref) <= 0); @@ -4047,8 +4055,7 @@ static void mem_cgroup_id_put_many(struc { VM_BUG_ON(atomic_read(&memcg->id.ref) < n); if (atomic_sub_and_test(n, &memcg->id.ref)) { - idr_remove(&mem_cgroup_idr, memcg->id.id); - memcg->id.id = 0; + mem_cgroup_id_remove(memcg); /* Memcg ID pins CSS */ css_put(&memcg->css); @@ -4185,8 +4192,7 @@ static struct mem_cgroup *mem_cgroup_all idr_replace(&mem_cgroup_idr, memcg, memcg->id.id); return memcg; fail: - if (memcg->id.id > 0) - idr_remove(&mem_cgroup_idr, memcg->id.id); + mem_cgroup_id_remove(memcg); __mem_cgroup_free(memcg); return NULL; } @@ -4245,6 +4251,7 @@ mem_cgroup_css_alloc(struct cgroup_subsy return &memcg->css; fail: + mem_cgroup_id_remove(memcg); mem_cgroup_free(memcg); return ERR_PTR(-ENOMEM); } _