Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp5172067imm; Tue, 16 Oct 2018 06:21:28 -0700 (PDT) X-Google-Smtp-Source: ACcGV62hj+YYx15FfwG3Lhv2HBl6Ayb1bvloCAuF5flvCzGPaRizeTgohAbArXttamhMcmN3DG+n X-Received: by 2002:a17:902:16a4:: with SMTP id h33-v6mr21119290plh.3.1539696088398; Tue, 16 Oct 2018 06:21:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539696088; cv=none; d=google.com; s=arc-20160816; b=N53mfgkUkb31e1TJpoMmOyxv6TdQmpy8BSvmdXV5EMJYXTjiz6ooNQNbut7RSL75Fq XamiafaDEPWMDIm3ldpHa2DnKCFt4KUTphBlh9npcHWNVd9Hrj9J1Iy6NZtkEo2d/JTC qs4NdYlIdC7+bUgKHDTG47or7fIERRn+xWo1cTRNS086PqbDT5Cxcf+RLJKgi2JW+vwX 9B2NP7NTqrNHA3ZAXeXy9dNhb1e3wpgb91/qt/ILx0rbnLVHHXgiu+yY5+jBCUZCadG/ PGVvyDKCTsL8U7rgyFh/VgNBOhH/NnXL4TNfDqEpR2ZCx4TStuete5auoTjvCP8fYu7O ruvQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=ZnLKrG9+B7VktA1JtJCaw3UJdvKJNl7YvEwvCVVI138=; b=ovIVRobfvREJekQtYyKvSxt7r9IMRJ+m7c8xTqJ+aepFCaj2NUlqT0JYByA4jw4I6Y YbjGTH5uMj6FKIrCyNcsV6TczdTe2V6IsK4Wcysgtr1rScgpWCE72qLzxw1V1ti09+3W nHzODI378NXY25MZqpygbiDApZuZCfC00JxM4kjGVMLvv6LSRt7oziOwB1BV2rB3ro1G NM4Ufig/2Az5OOuTaezojOXBJq0MBQDPXPRyY+5oc7IrFloag9UU/rKwlEA5dSyf5BkM sltVMm82iBgYeY69FGPfg7WVZSxAqz5SRD4Ab+3GLTqh0Pn1VBwoqIKV6CWuAyNvpcDc wqxQ== 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 a33-v6si13260057plc.8.2018.10.16.06.21.12; Tue, 16 Oct 2018 06:21:28 -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 S1727086AbeJPVKT (ORCPT + 99 others); Tue, 16 Oct 2018 17:10:19 -0400 Received: from relay.sw.ru ([185.231.240.75]:40416 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726760AbeJPVKS (ORCPT ); Tue, 16 Oct 2018 17:10:18 -0400 Received: from [172.16.25.169] by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gCPGA-00018u-7T; Tue, 16 Oct 2018 16:19:42 +0300 Subject: Re: [PATCH] mm: Convert mem_cgroup_id::ref to refcount_t type To: Andrea Parri Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org References: <153910718919.7006.13400779039257185427.stgit@localhost.localdomain> <20181016124939.GA13278@andrea> From: Kirill Tkhai Message-ID: Date: Tue, 16 Oct 2018 16:19:40 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20181016124939.GA13278@andrea> Content-Type: text/plain; charset=windows-1252 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Andrea, On 16.10.2018 15:49, Andrea Parri wrote: > Hi Kirill, > > On Tue, Oct 09, 2018 at 08:46:56PM +0300, 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(). > > refcount_{sub_and_test,inc_not_zero}() are documented to provide > "slightly" more relaxed ordering than their atomic_* counterpart, > c.f., > > Documentation/core-api/refcount-vs-atomic.rst > lib/refcount.c (inline comments) > > IIUC, this semantic change won't cause problems here (but please > double-check? ;D ). I just don't see a place, where we may think about using a modification of struct mem_cgroup::id::ref as a memory barrier to order something, and all this looks safe for me. Kirill >> 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. >>