From patchwork Tue Oct 9 17:46:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirill Tkhai X-Patchwork-Id: 10633057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 40B6B174A for ; Tue, 9 Oct 2018 17:47:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2037D29580 for ; Tue, 9 Oct 2018 17:47:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCD6C2953F; Tue, 9 Oct 2018 17:47:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CA8F294E5 for ; Tue, 9 Oct 2018 17:47:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 500826B0007; Tue, 9 Oct 2018 13:47:04 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 4AF316B0008; Tue, 9 Oct 2018 13:47:04 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39EF66B000A; Tue, 9 Oct 2018 13:47:04 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by kanga.kvack.org (Postfix) with ESMTP id BF3AA6B0007 for ; Tue, 9 Oct 2018 13:47:03 -0400 (EDT) Received: by mail-lf1-f72.google.com with SMTP id m79-v6so322954lfi.11 for ; Tue, 09 Oct 2018 10:47:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:subject:from :to:date:message-id:user-agent:mime-version :content-transfer-encoding; bh=NVaX57Js8YHtOdVnl1vBp3hbFClktNK+E7sc3hfewQY=; b=KvGujfVJeuJqsjy/qvpW+p1JbG0hGqACjmUpxgZ5+z+MOfVjH0/zOg2lRTzGnt7Ge4 Xt47wGvezGMdAFnY+EscXla4YQUrtUauThUXxWmB0FU6qF2SC0D0nAyzohULsRHp7FQt Izu6sO5610o0cSTli1pnee+EBvZRY1DShoIBITc4+OPDjrQ3XXFtot71JIxrg4Ebrsco e2Fn9qbXIea/Chv6V6KzypO9Q7eLBL/XDAplQk2+/4OTV4k4Kt2zGYm+Qo2SGI6JTm5P 0XLyksbaO6Ququ2g2PXbnQAG0S4srBtivAQaLl+XDZXGEgdl2cK9nW9IwvJn7v1RgHIm cJLw== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of ktkhai@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=ktkhai@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com X-Gm-Message-State: ABuFfohkCyDbmSXTxcoQSOnVRkiuE5xDE0UpHdAANPsVInlb9GGZ5b2F jykHmcP4USbV821KrXWvV3BQ81u2T3XzWjpIw98eDDrLeSSIxHepQZu82/gzM5F+EwO6StwJKbU xDj5F5Hr6X5U2XpLIPZ/Et0uJKPelJcnYG4C5dccJ6SgCajDyl4Dk4t1frt2SIPhqeQ== X-Received: by 2002:a19:7112:: with SMTP id m18-v6mr16047438lfc.64.1539107223003; Tue, 09 Oct 2018 10:47:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV61HDWFa1AoyNGJUWSgDO+eUyxVggkhLoXFxTgSSJgUV8u7QihrQKJUChpLNciXcqeWeqUSV X-Received: by 2002:a19:7112:: with SMTP id m18-v6mr16047399lfc.64.1539107222055; Tue, 09 Oct 2018 10:47:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539107222; cv=none; d=google.com; s=arc-20160816; b=nrfGTI5iLb4Zf5Nwd0lOfgMfM4ZBjpQcz9VGoTpScBUfkXVZnt0yTs2ABV/cUhM+LG bBIBlBq5kWbvEZrjWP8319OelL2UWvOgD5WWnBXH0arZIgWudN4Y3AR8bn1lvhmojV9a GSW4CLEcsH7Ys3Kfk9feUs99VrD8Yt0jbmLW0cFsNeScqn7stVX5FltzUl1R7LG8pZ11 SkzTl0s4dw5X38d4wS04+2i1PirfaImckPeb21AlHKN3dnHszSYDouxuHMvus2Vy4f1I nyY9LBluRaywiSn9tg2yqZuxU95eDIsS01aIRNYXpTPqYqvTqiHEvOrNjFVT9nkU8uwd msxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:user-agent:message-id:date :to:from:subject; bh=NVaX57Js8YHtOdVnl1vBp3hbFClktNK+E7sc3hfewQY=; b=pataZbrwQ0AaURQN9Lj+zvSV7BdHmeY8RwWCa70ja+7z8dHixVLVpO1z6fmmehAbPv 27yEAD5sLYhGO8qjYrh5/5FpbDgcV0Wq9FG0LIGlr7il9h1fktVgiPM+N7Cx6PGfKPLm WVe9KQU07UvEnGabVd/pX23zRb39ANx165Pn3hHkmkyOkBA3yKAb5J5D92CxzAeVo1J4 8Pq0iQj0uyyPDGdpwGExgjBVSSsanmJ3Gqvyo77sE+7X/aieurr5XiFsFB3ixKTb2P7d 0VmdHAJxzC8mseBIaUCGxUTxFPAy+oWlBOCrbdwTJcPFG5gZ3duCnPYys0EvRtWJXapM KE1Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ktkhai@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=ktkhai@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: from relay.sw.ru (relay.sw.ru. [185.231.240.75]) by mx.google.com with ESMTPS id 7-v6si16451016lfq.145.2018.10.09.10.47.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 10:47:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ktkhai@virtuozzo.com designates 185.231.240.75 as permitted sender) client-ip=185.231.240.75; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ktkhai@virtuozzo.com designates 185.231.240.75 as permitted sender) smtp.mailfrom=ktkhai@virtuozzo.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com 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 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 Acked-by: Michal Hocko --- 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.