Received: by 10.192.165.156 with SMTP id m28csp2055285imm; Thu, 12 Apr 2018 07:56:00 -0700 (PDT) X-Google-Smtp-Source: AIpwx48omo9BdiHqT1LReK/J8NlnqpjnkpHBqPaP6MuTThE26zRErmLPG/KWO00HgvSjWe+1z+Ex X-Received: by 2002:a17:902:5a8e:: with SMTP id r14-v6mr1393810pli.138.1523544960775; Thu, 12 Apr 2018 07:56:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523544960; cv=none; d=google.com; s=arc-20160816; b=yqWaXtXVcwXpdFa++dIaKp1zHwgdikoikisvZ26lFoMrjV39/ezt/X6r9wWXmYfn5j gokd07YxWUodOmk+OBcjVI0H+TF7q2mKez/eHR24VndnJ1IrUwyX6BU+YpGAFlhVqSYG Il5AXlnXp99bAs4PGOOww43JAct/OcBF+nUPswPgEIDyFrUt/rx+HCNPbE/iWUoNeON7 sOzJHBv28Ub//p79R7wzsj6GOzSZhZa03xJn3APv331GdHtq5r9eFFXesmulNYW4W07j MoHF57NX/O5JXvhh0ZmrveXtFBKt8saP6213eHBa6JBX345ZlShS9xHpgcPwNgRIyzN/ hr+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :user-agent:message-id:date:to:from:subject:dkim-signature :arc-authentication-results; bh=VcqWop4mR/UeOmwyinIz+r0iXyOkNXPUvaMoOhprB3k=; b=Kj8jhyFQKJfVsAbCqjqeKcbIyzY83Oturi/D96RFlgwl27+SCmK3cAov63dvjPOux/ 3A5dS0ErAA5i3vDgGP/uAaTAvhqEhfHctT3eE/oxu+grRO63BMEzh5cVXaIZn8xd8TjQ EFYi3YxEYjXAtvk9a0+UWMTwJezJ2ap832RFIBctOJOKthFzcll/imm6W/Xs8hp4urT7 JGRoCIJA/533v6BnJY6+9+3T5FIX4+X3UjatmkL6ifdW5AsOyJiUfLRsJKDp54L82JhD GqAxMzleStgvgsIuETuGu9hzLTcVNDWcnNe850mPLc24YX7PjBjCYO+28ojXS4Wu705r mHnw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=Q/9hk4T5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k15si2397250pgp.278.2018.04.12.07.55.23; Thu, 12 Apr 2018 07:56:00 -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; dkim=pass header.i=@virtuozzo.com header.s=selector1 header.b=Q/9hk4T5; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752995AbeDLOwN (ORCPT + 99 others); Thu, 12 Apr 2018 10:52:13 -0400 Received: from mail-eopbgr30095.outbound.protection.outlook.com ([40.107.3.95]:18907 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752917AbeDLOwL (ORCPT ); Thu, 12 Apr 2018 10:52:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=VcqWop4mR/UeOmwyinIz+r0iXyOkNXPUvaMoOhprB3k=; b=Q/9hk4T5+N7tVh6U2fBuLuu29VBTtig2hAI4/1Plwu0lOeUYfbkLNjqu20Mrer4I6ne7zY6bjsMFH9beealwbXpaTSSUtRs0JKCG91axEM2yywQCbxCzx3G33pEcfKl+u+6fNP6wdn+7OdFkkh+GEw8VMm1873ZbCjiEnWRIrr0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=ktkhai@virtuozzo.com; Received: from localhost.localdomain (195.214.232.6) by HE1PR0801MB1338.eurprd08.prod.outlook.com (2603:10a6:3:39::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.653.12; Thu, 12 Apr 2018 14:52:06 +0000 Subject: [PATCH] memcg: Remove memcg_cgroup::id from IDR on mem_cgroup_css_alloc() failure From: Kirill Tkhai To: akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, cgroups@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Date: Thu, 12 Apr 2018 17:52:04 +0300 Message-ID: <152354470916.22460.14397070748001974638.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR05CA0375.eurprd05.prod.outlook.com (2603:10a6:7:94::34) To HE1PR0801MB1338.eurprd08.prod.outlook.com (2603:10a6:3:39::28) X-MS-PublicTrafficType: Email X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(5600026)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(2017052603328)(7153060)(7193020);SRVR:HE1PR0801MB1338; X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1338;3:cze17YHZ2a19mBDpl+sr0ET/oHZDgVy2S86Kf32jpFavzBnq7AKmJTxCm+SpW/TWuhQrdgzmAVpV1Djp+eRJUgRdOdjSj6yH0CFkVv+DMJsm+7CbjRuonHM5ulh4nxcr3s0A1pdbyP0FRUBFYrwft2b16flEyjxs55O/woGZLPmxL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CLOB+6dmK2HkPssB/7qtHfvy6X//VSsK5OUz18KPv+g188GEsBIZbdIFZnnv1kJXyETJj6mH8ZYdOxkt23t99vtLe7VlLs6IVO66YUqH5DIrkqCiujO9Yr6OUpDapyg1BPklhDquWSem+VuZ93fy7qnYBYBNzMKasiH+/WBgloRDd8fJK;4:AHDKkUGlnlPL1VpZMEG+oEnx6I/kmPRY2DX3WOjR1nYiaKemkS1rrcpgQqxLwyj6qMFLZZVbJ7Pz2jLMpnY8BQfr3gJbNbsea/UDL+7oEZs37GEGbGgeHtwxRuEnZ5+xauFoz8RPIPT11cObZ4IG0x5auEetILFt8mHmQx0jEvFkZaTCISWO+SPrlTpHWl7lCvDm7aNfRBWv0A0Q87k4NnYrM4qZgg7F4gekHzdoT/OJ3SjYkKBDoLQJST0yNhMSlN+smX3RwfNnra8nzVDmMQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040522)(2401047)(5005006)(8121501046)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6041310)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011);SRVR:HE1PR0801MB1338;BCL:0;PCL:0;RULEID:;SRVR:HE1PR0801MB1338; X-Forefront-PRVS: 06400060E1 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(6069001)(346002)(39830400003)(396003)(376002)(39380400002)(366004)(189003)(199004)(58126008)(386003)(81166006)(316002)(61506002)(6506007)(103116003)(55236004)(33896004)(81156014)(66066001)(59450400001)(5660300001)(3846002)(86362001)(7736002)(39060400002)(68736007)(47776003)(305945005)(25786009)(1857600001)(186003)(230700001)(55016002)(26005)(2906002)(478600001)(2486003)(486006)(8936002)(6116002)(476003)(23676004)(50466002)(97736004)(53936002)(105586002)(956004)(106356001)(16526019)(9686003)(7696005)(52116002)(8676002);DIR:OUT;SFP:1102;SCL:1;SRVR:HE1PR0801MB1338;H:localhost.localdomain;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?utf-8?B?MTtIRTFQUjA4MDFNQjEzMzg7MjM6dWY3Mmp2ZTRPZDdHU20rRTEza0J5WVRm?= =?utf-8?B?QVlFYWUzeEtGbytUQ0t2YzVhTUJFM1JhRTNYSExpRGJQcU4wejlNa3E1MHZp?= =?utf-8?B?VTFmYTIyaWtPNkUyeWRVemIrQ2FlcGlVYXVKVURUVUVQVnZHbnFNOXpyS2dW?= =?utf-8?B?Tm1RaGt0ZklBNDZLcHcvM014NkFETFFQcmRBdkhvTnVpVWFMYm9ySW9XbTJ3?= =?utf-8?B?V0NHUEV3NlljRmc3WHNGTEtWZmRZZXlrOEhtcGRZV3hLb1l5L2s3TjVENTRx?= =?utf-8?B?b2RSQ0dCZDZGcjlHUnhuSGpOcDNValErNkNMc2tEaVpJblNYN2lYRHhJVXEz?= =?utf-8?B?TDZtd0wxWDVCQzlqcmsrUjJnc3J4Qm15ZC91Q3M5Z01RU240Ly9JYnZWbTlm?= =?utf-8?B?VlpmTTRhdGN5NG1BcXdNTURwZGx1OWdrYVdOdE8wT1JiMjRsYUExcTJ1OWJH?= =?utf-8?B?VDBoTFVqc3QwajBDUVNmVmt2R01YRE51V0MrK3VKbllxaEJ4WFd6QW1Gd3dR?= =?utf-8?B?NFQvZXBKWFcvZmJkbFlDeGZnTndkbTF2MWxHR1A5V010MXlTWWdiYVZNZFlu?= =?utf-8?B?TExqbkhOeVpLclZqdlRJUjNaUk1QTi9ZUWhjb0I4bVhja3dLZW1nL2l0MFpI?= =?utf-8?B?NEFtbG9rakRIRWtjUHc2Ukdsa21CZXY4bVpnYThKVUFIRlhDQTAxY0ZPSXg5?= =?utf-8?B?aGpyK1p2NERIZjJFRE15NzJzMFFaSzhVUkpiRk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SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;HE1PR0801MB1338;7:oBLAYgfv9wqG5O5cqnR4BX7IiF1VcJcmVNrqRjWk4Ngo+cXFdKLhOII0KSZcWKISQBMMZgNsZorhtjsDFxrLDMEqgQiiFJdUbfFV/OUetFTZSkCcD4N07Z2ahvdmuzUxFI2gVAaXnMIsQWN2Z+jawbjbUIWJT2ovmz2mEkwTZ3aDej72pZ515l0FYqICYP6BSdaZ2dZLV1A1imWQn2d1vDuNxSvgYqOpOpMNJHUmKJ8pt4/rxY9fHVimybkJ02j/;20:05rNec4++nSxaVHkjrcQOmnYYQAxSQwDMczH1qN9uS3OkusUA/Q/Xd2XtWfDhCBPxy4lRjnmeeVtOwrggnUc9yBePL12ZnxQEGFG2GK8cQGvY5P+kbFfyoaUe9HluqbcgIFA3FAsEQMB3rpIpeshcgHuJNRZTpWTUClwIBJ2pHU= X-MS-Office365-Filtering-Correlation-Id: 2977641a-c0e1-4c4d-6130-08d5a084f630 X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Apr 2018 14:52:06.6316 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2977641a-c0e1-4c4d-6130-08d5a084f630 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1PR0801MB1338 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In case of memcg_online_kmem() fail, 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 removing into mem_cgroup_css_alloc(), which fixes the problem. For better readability, it adds generic helper, which will be used in mem_cgroup_alloc() and mem_cgroup_id_put_many() too. Fixes 73f576c04b94 "mm: memcontrol: fix cgroup creation failure after many small jobs" Signed-off-by: Kirill Tkhai --- mm/memcontrol.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 3e7942c301a8..448db08d97a0 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4263,6 +4263,14 @@ static struct cftype mem_cgroup_legacy_files[] = { 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); @@ -4273,8 +4281,7 @@ static void mem_cgroup_id_put_many(struct mem_cgroup *memcg, unsigned int n) { 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); @@ -4411,8 +4418,7 @@ 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_id_remove(memcg); __mem_cgroup_free(memcg); return NULL; } @@ -4471,6 +4477,7 @@ mem_cgroup_css_alloc(struct cgroup_subsys_state *parent_css) return &memcg->css; fail: + mem_cgroup_id_remove(memcg); mem_cgroup_free(memcg); return ERR_PTR(-ENOMEM); }