Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp944054pxv; Fri, 25 Jun 2021 01:47:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqR9RmjHKyFjv9yJcPk4ziB06hvNQUSv9jduXDA57DcGrdmCR3bAdLkzFmlBt0NVxZbfaX X-Received: by 2002:a05:6e02:1a4d:: with SMTP id u13mr6508721ilv.42.1624610839605; Fri, 25 Jun 2021 01:47:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624610839; cv=none; d=google.com; s=arc-20160816; b=F5vpkMq7mHkWNoR9gxpybGIz+u53A+wJqqXJbwRrfR9l5X7cgl2VNL4ogB/XPWDRP3 aBhMxKeRUSlphkgWl7lHJCGKEVzTiZ1gK+i4jNjblkS9K3unwRbGAYH7jQTro4bSf5h+ lNtcRjhoC8v07pf/Rtqbb7/74uYliq6cXVkFW5EA8LPJEp4dH9bs8FYcVYG879+UTFnG 32zOvK52yLNOhkkQGGHFGdlGbVGH5la8pEcdL/IMGMUYt0nTqiW4/bN7HsDGsiQwF+5F ZeBO8EYODvmgrFbEq+time3yHlVFdKh/q4ey1UkmTk5nSLBe7IhygtVw/F1aS+g4qm3Q F1iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=kNorM8Z9hlXPofx0BV7IDQ/KPe6nuPlT715oQCzHClY=; b=QpJo54cueI+T6bG/h+SUL1eqZckouz2kmuHjApzNOYHTM8zUWJsOtnHSvDAmptGQTW YsF6jMzl+WUPMB2hKgA1GERjQdJElRm2kUQXPTJR9V6mf6xRZ4oekD8Hb0aCbg+t3WmV jNRJFrFwcALBQVY+zNW+ibSXv80tYYsTp3Dzkrq5CMwM8I04pgiAZzlW8nG55RAanQB4 56+Z0o3Kh/OKWIvJDcDTxBEJA0RkxccGMDdd7xvgIa6KLUhnmMv2WcRId0EyILbqwa2U zFg3JInYMhfWvWGHKxg7ckjn7dydfYR5Xsz39yjzU3nNdhcJzkEcLhvVDEJWy0HE88tw t4dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g9si6597795ilq.106.2021.06.25.01.47.06; Fri, 25 Jun 2021 01:47:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230020AbhFYIs4 (ORCPT + 99 others); Fri, 25 Jun 2021 04:48:56 -0400 Received: from szxga01-in.huawei.com ([45.249.212.187]:5078 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229839AbhFYIs4 (ORCPT ); Fri, 25 Jun 2021 04:48:56 -0400 Received: from dggeme703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GB9TD4CcTzXkcs; Fri, 25 Jun 2021 16:41:20 +0800 (CST) Received: from [10.174.177.120] (10.174.177.120) by dggeme703-chm.china.huawei.com (10.1.199.99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 25 Jun 2021 16:46:33 +0800 Subject: Re: [Phishing Risk] [External] [PATCH 2/3] mm/zsmalloc.c: combine two atomic ops in zs_pool_dec_isolated() To: Muchun Song CC: Andrew Morton , Minchan Kim , , , LKML , Linux Memory Management List References: <20210624123930.1769093-1-linmiaohe@huawei.com> <20210624123930.1769093-3-linmiaohe@huawei.com> <1b38b33f-316e-1816-216f-9923f612ceb6@huawei.com> From: Miaohe Lin Message-ID: <01117bc0-53b1-d81a-a4d8-2a1dbe5dcd94@huawei.com> Date: Fri, 25 Jun 2021 16:46:32 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.174.177.120] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggeme703-chm.china.huawei.com (10.1.199.99) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/6/25 15:29, Muchun Song wrote: > On Fri, Jun 25, 2021 at 2:32 PM Miaohe Lin wrote: >> >> On 2021/6/25 13:01, Muchun Song wrote: >>> On Thu, Jun 24, 2021 at 8:40 PM Miaohe Lin wrote: >>>> >>>> atomic_long_dec_and_test() is equivalent to atomic_long_dec() and >>>> atomic_long_read() == 0. Use it to make code more succinct. >>> >>> Actually, they are not equal. atomic_long_dec_and_test implies a >>> full memory barrier around it but atomic_long_dec and atomic_long_read >>> don't. >>> >> >> Many thanks for comment. They are indeed not completely equal as you said. >> What I mean is they can do the same things we want in this specified context. >> Thanks again. > > I don't think so. Using individual operations can eliminate memory barriers. > We will pay for the barrier if we use atomic_long_dec_and_test here. The combination of atomic_long_dec and atomic_long_read usecase is rare and looks somehow weird. I think it's worth to do this with the cost of barrier. > >> >>> That RMW operations that have a return value is equal to the following. >>> >>> smp_mb__before_atomic() >>> non-RMW operations or RMW operations that have no return value >>> smp_mb__after_atomic() >>> >>> Thanks. >>> >>>> >>>> Signed-off-by: Miaohe Lin >>>> --- >>>> mm/zsmalloc.c | 3 +-- >>>> 1 file changed, 1 insertion(+), 2 deletions(-) >>>> >>>> diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c >>>> index 1476289b619f..0b4b23740d78 100644 >>>> --- a/mm/zsmalloc.c >>>> +++ b/mm/zsmalloc.c >>>> @@ -1828,13 +1828,12 @@ static void putback_zspage_deferred(struct zs_pool *pool, >>>> static inline void zs_pool_dec_isolated(struct zs_pool *pool) >>>> { >>>> VM_BUG_ON(atomic_long_read(&pool->isolated_pages) <= 0); >>>> - atomic_long_dec(&pool->isolated_pages); >>>> /* >>>> * There's no possibility of racing, since wait_for_isolated_drain() >>>> * checks the isolated count under &class->lock after enqueuing >>>> * on migration_wait. >>>> */ >>>> - if (atomic_long_read(&pool->isolated_pages) == 0 && pool->destroying) >>>> + if (atomic_long_dec_and_test(&pool->isolated_pages) && pool->destroying) >>>> wake_up_all(&pool->migration_wait); >>>> } >>>> >>>> -- >>>> 2.23.0 >>>> >>> . >>> >> > . >