Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5255301imm; Tue, 9 Oct 2018 12:04:11 -0700 (PDT) X-Google-Smtp-Source: ACcGV60ZzTSCzz645ccyYXI5jVxAtOtz0A10UZ1We96TTEhVQoZA9ER5qyQm5clMKUFC3ziPR11I X-Received: by 2002:a17:902:9a48:: with SMTP id x8-v6mr29433563plv.72.1539111851142; Tue, 09 Oct 2018 12:04:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539111851; cv=none; d=google.com; s=arc-20160816; b=EF1vyYowsHU7Eh4rl77FU2MjV+w67EzneMV7GjvTY1Y5mhGS8QBhNxi9F8fXf/odOp WWm2+rfXAJ1RGwYyhXA31EaIqc4F4485En2kMA1EvdNCVOlxvWr+KQQIdznyvOfhfXQ+ DPorUTfr68Hn3u6ZG8BMjb7Xo4vTnRXSlifSTTU63I/MmukR38552/SwevNSl8Dhb+Nw 1daBaAhlJDoFJCd2bOph/jbR1D07S6dZrGccfi6DPYhqjmWk7c+3eMx9h3+VMwhwt4Im JQTN/K5nxEMmAOOdmqsb4z6+xUTkYXpu59PpcIKjC8miO9huC44oiBz0L+suaiE+rYpb L9mg== 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 :user-agent:message-id:date:to:from:subject; bh=NVaX57Js8YHtOdVnl1vBp3hbFClktNK+E7sc3hfewQY=; b=TRXlnSzn15PDAm0fDzL0OZhszEGU9OT2IEv/XPoLaRgBOnzXnVtn/3xYs3XPbfem1l iIsMdXM4NSwYVLbWC6VEb4d/iL94hBhzTWWjBtvarjJC4eBDU3RJtN/lhXIFgejzpmqh D+srrLmKhkQh83+33kUN9nKI3qtHxIV9hGjew+8vRArky8Dg8gWc8+fq+xIFRmf/VJLC IAegxF4fGndJ1V7w0GQIkZBJ/YeDELIq/AQQNA8pizU8Y+LtHIIsL1cZQM5BGxtXq1Wg hdyHhozFyS0BjtadlksxTbM3q1/bLtXSfKq3f4OZ1pLDilL1dYCwa7qdleIosLDrPB5O acIQ== 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; dmarc=fail (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 y73-v6si23392596pfi.61.2018.10.09.12.03.56; Tue, 09 Oct 2018 12:04:11 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727248AbeJJCUM (ORCPT + 99 others); Tue, 9 Oct 2018 22:20:12 -0400 Received: from relay.sw.ru ([185.231.240.75]:45244 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726445AbeJJCUM (ORCPT ); Tue, 9 Oct 2018 22:20:12 -0400 X-Greylist: delayed 4504 seconds by postgrey-1.27 at vger.kernel.org; Tue, 09 Oct 2018 22:20:11 EDT Received: from [172.16.25.169] (helo=localhost.localdomain) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1g9w5x-0005MO-Vo; Tue, 09 Oct 2018 20:46:58 +0300 Subject: [PATCH] mm: Convert mem_cgroup_id::ref to refcount_t type From: Kirill Tkhai To: akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org, ktkhai@virtuozzo.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Date: Tue, 09 Oct 2018 20:46:56 +0300 Message-ID: <153910718919.7006.13400779039257185427.stgit@localhost.localdomain> User-Agent: StGit/0.18 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This will allow to use generic refcount_t interfaces to check counters overflow instead of currently existing VM_BUG_ON(). The only difference after the patch is VM_BUG_ON() may cause BUG(), while refcount_t fires with WARN(). But this seems not to be significant here, since such the problems are usually caught by syzbot with panic-on-warn enabled. Signed-off-by: Kirill Tkhai --- include/linux/memcontrol.h | 2 +- mm/memcontrol.c | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 4399cc3f00e4..7ab2120155a4 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -78,7 +78,7 @@ struct mem_cgroup_reclaim_cookie { struct mem_cgroup_id { int id; - atomic_t ref; + refcount_t ref; }; /* diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7bebe2ddec05..aa728d5b3d72 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -4299,14 +4299,12 @@ static void mem_cgroup_id_remove(struct mem_cgroup *memcg) static void mem_cgroup_id_get_many(struct mem_cgroup *memcg, unsigned int n) { - VM_BUG_ON(atomic_read(&memcg->id.ref) <= 0); - atomic_add(n, &memcg->id.ref); + refcount_add(n, &memcg->id.ref); } 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)) { + if (refcount_sub_and_test(n, &memcg->id.ref)) { mem_cgroup_id_remove(memcg); /* Memcg ID pins CSS */ @@ -4523,7 +4521,7 @@ static int mem_cgroup_css_online(struct cgroup_subsys_state *css) } /* Online state pins memcg ID, memcg ID pins CSS */ - atomic_set(&memcg->id.ref, 1); + refcount_set(&memcg->id.ref, 1); css_get(css); return 0; } @@ -6357,7 +6355,7 @@ subsys_initcall(mem_cgroup_init); #ifdef CONFIG_MEMCG_SWAP static struct mem_cgroup *mem_cgroup_id_get_online(struct mem_cgroup *memcg) { - while (!atomic_inc_not_zero(&memcg->id.ref)) { + while (!refcount_inc_not_zero(&memcg->id.ref)) { /* * The root cgroup cannot be destroyed, so it's refcount must * always be >= 1.