Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5088515imm; Tue, 16 Oct 2018 05:08:18 -0700 (PDT) X-Google-Smtp-Source: ACcGV604I1PoxC9Vq+sQLkTH7DZmAhBqg3xp2BE0XY7I8U3B5FjFl7y95MVcXT7k6WdJ1hdQ5H7C X-Received: by 2002:a65:4385:: with SMTP id m5-v6mr18935462pgp.219.1539691698780; Tue, 16 Oct 2018 05:08:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539691698; cv=none; d=google.com; s=arc-20160816; b=BdxmEkMdgQSfziOqC8/eMmtgMJy5LnfPqiql9iioBM2jYNVMMvl5r7+KGppnahM+Hn CU7acP002FVzLdpdNEWJ49nofVitksm1INNC1Nr291n9T57Sk+cSSRDxVclp3WXr1iYm /dM0/smEEvJ/ifDqtW1sykFxnWvTiprhlVFMZu/G4YSJStA6UvjAFX2zw+ps2//y5W1F MjgSvqWUdNpBiDIJbq4ae+tdKRkci+vdfuo9Z0c1rWPg+rKZ3+g3TNYeJrS+wZKYuwPQ bduYWie0+iSnjf2LYyjZMWrTSlWL7WONk01PEYy0BRz64SVJf5Zz55pPU+Ue9QMi+f4q +3XA== 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; bh=+5iwTmT1334y5OOOALRJkZUv14rqEESnznOBrw6GHes=; b=xn9Y5K7tUgDotvu0uJYAdiuAmd7odBXRj0LTss84b+phFHkzhc/XoBUlR6zh6JclKb rib0F9aDlAEXW9aGv7kY3zj9LjCUCSYYU3LB90ZzgaxkkXKlgVp37Aj77tBYvz5h2yGe NKfj+AcsKWvDn5P5l8Ug2j1StdK+DWJ+tOs8Mj9TafikE+VsMbC/ewNYV3Ry8jrPF4ch 52hs2cM44VZRLDYrY1PlyzhrQoz+zvfFDB4yq8w3Qdta5nAGNwQi/4UkXRxZLiCRrO6a LU/FwV2tFICK89o/sh0o9r4oq0qAH8I/j/QlbxGvrk/OKc2RySYgg16Gp/NsyIssr8jz 6sjQ== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n25-v6si13723725pfh.207.2018.10.16.05.08.02; Tue, 16 Oct 2018 05:08:18 -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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727055AbeJPT4G (ORCPT + 99 others); Tue, 16 Oct 2018 15:56:06 -0400 Received: from mx2.suse.de ([195.135.220.15]:44056 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726718AbeJPT4G (ORCPT ); Tue, 16 Oct 2018 15:56:06 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id D06DEB030; Tue, 16 Oct 2018 12:05:54 +0000 (UTC) Date: Tue, 16 Oct 2018 14:05:54 +0200 From: Michal Hocko To: Kirill Tkhai Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, vdavydov.dev@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] mm: Convert mem_cgroup_id::ref to refcount_t type Message-ID: <20181016120554.GT18839@dhcp22.suse.cz> References: <153910718919.7006.13400779039257185427.stgit@localhost.localdomain> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <153910718919.7006.13400779039257185427.stgit@localhost.localdomain> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue 09-10-18 20:46:56, Kirill Tkhai wrote: > 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. -- Michal Hocko SUSE Labs