Received: by 10.192.165.156 with SMTP id m28csp662182imm; Fri, 13 Apr 2018 05:52:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx4864GMo47ElXvG2Dg7fFZRmCjttMr+Uz4p/W2P31vyavdwQCx4l+3binF280d4UDxIW4Pmm X-Received: by 2002:a17:902:1a4:: with SMTP id b33-v6mr5132862plb.303.1523623943687; Fri, 13 Apr 2018 05:52:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523623943; cv=none; d=google.com; s=arc-20160816; b=YdVhCK6CqMjUVfDJM2oTQFNbV1zVZhqcWAwYS2ZRTCEBsBEi/tRibPF730jW8bSlt2 s0kkA4Bl3CBm0yBPIbXRzgFL8CdIVoogS6VlM8SHAN4K04xg5PapeOe8CG4Kh8M4IGQg fyZUIzfEqyWH7J+07jl46jNuX9UeFRWWVqyjXIo1yu1uf3kvBlWy6EHLT2x+pipj9fQo /cfMR/UASNGGXklQrLr3IVca0sIKOSLo/FQk4LKuafOBOMcgVYos2ucwZyWPLcNJePHA RRINvFJGGChCQ448v2PBl2YpXvpnSR2ovbnA74W5g3cZjo6FgEBcNB+YULZFvWSIkKOE zxcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:arc-authentication-results; bh=h7m/H2wxffhbnxPLctAsMTF4Nh4/WlVVjJs68vmffRE=; b=wV8gDxl5/0aEZRRa+2oQNIUaWJLkLS0YbeYSSrKzUlwve5utx2+BZUZeUgc1966tDG UxffpfT8QqnxHvn1FtzqYf09P4SJflgTnFO21Y+q/dgRJVCd/3SJLMVCK+62M76HkBo2 FzzMSQXfGIP+rkGIByLufAc0sofEf1oug1CvXvTl3xxCzEPr0xEC4PI0qEmQlya83TFN jfPp68Uryr80dr/CpnYp4cHWVe+/SXvXrywTXYg98DmscWWopNVxYU3l5DNj0Cg3EeCg kKQQvGuMDvroO9sKnmiPI8dGevOdRMCQGycs3PkCyoLH3YXsrwbHb5IcZfr8UJgdiOzt 5D2g== 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 a11-v6si1503086pla.497.2018.04.13.05.52.09; Fri, 13 Apr 2018 05:52:23 -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 S1753784AbeDMMvF (ORCPT + 99 others); Fri, 13 Apr 2018 08:51:05 -0400 Received: from mx2.suse.de ([195.135.220.15]:46385 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751024AbeDMMvE (ORCPT ); Fri, 13 Apr 2018 08:51:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id F290EAED5; Fri, 13 Apr 2018 12:51:02 +0000 (UTC) Date: Fri, 13 Apr 2018 14:51:01 +0200 From: Michal Hocko To: Kirill Tkhai Cc: akpm@linux-foundation.org, 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: <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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180413121433.GM17484@dhcp22.suse.cz> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 8c2ed1c2b72c..ca7e981a8a1a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4351,6 +4351,14 @@ static void __mem_cgroup_free(struct mem_cgroup *memcg) { int node; + /* + * We are trying to remove the idr key when the last memcg + * reference drops which can be sooner than when the last + * css reference is dropped to recycle ids faster. + */ + if (memcg->id.id > 0) + idr_remove(&mem_cgroup_idr, memcg->id.id); + for_each_node(node) free_mem_cgroup_per_node_info(memcg, node); free_percpu(memcg->stat_cpu); @@ -4411,8 +4419,6 @@ static struct mem_cgroup *mem_cgroup_alloc(void) 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_free(memcg); return NULL; } -- Michal Hocko SUSE Labs