From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89167C2B9F4 for ; Fri, 25 Jun 2021 07:30:18 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 118DB6141E for ; Fri, 25 Jun 2021 07:30:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 118DB6141E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=bytedance.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id ABCE66B0036; Fri, 25 Jun 2021 03:30:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A1F326B005D; Fri, 25 Jun 2021 03:30:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 84BA16B006C; Fri, 25 Jun 2021 03:30:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id 442AE6B0036 for ; Fri, 25 Jun 2021 03:30:16 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 6366A250C4 for ; Fri, 25 Jun 2021 07:30:16 +0000 (UTC) X-FDA: 78291422832.18.3E3A625 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf22.hostedemail.com (Postfix) with ESMTP id 3C40FC00CBE2 for ; Fri, 25 Jun 2021 07:30:15 +0000 (UTC) Received: by mail-pf1-f181.google.com with SMTP id c8so7359751pfp.5 for ; Fri, 25 Jun 2021 00:30:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=dk863fuzW21r4G77h5O77SvX4KOoOky/K7FqkqXXvqA=; b=P+hZ4H0VeB859TjMuIVl1zKuXnANOsqkQ+jKS7xhIpN7i4b0Eb5zgSUiqK8s82mHsc Dk6IjeAJemBp4GB/cZ+Hg62qc6XvUMp5iueM82lUygukZIVJjPkL+WDvrvDpbMtSzlGt gkaThWphg3pcmhDZ+DFvpu4IBoACoSOFULZmTLTeV/V2BrrCmMYdNagVd4DT4cbSCX/c M0/or4/1OaSJ9zrJilpLZuROTTV6m18Cp1O1Zvd576AsaI+bAiuLUcvHXwrig0trTXjV Q78rpBJyTLbo8r5AMKdWIrym0Nz9UI43nizDjm4yRdvCzERC4ISIG0EmDzcBHnyA1in5 1BPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=dk863fuzW21r4G77h5O77SvX4KOoOky/K7FqkqXXvqA=; b=ltJf4FSI+oKMX3kROoSO6sQnXfw7cIUmiY/GqvLRfFJdvJAvTzGVOmaydnZH4ZlvbB OqFZQwdYQpgY5/oQxhPxqEz6VRIJc5XeWTQXtd9zIriGlGeAvN1AuONYqwB7xwpAKAyK 5lNWGjaY56xr3D9Fw6gfNZTDQn+YEClcD10UHKbuZTTXtlXaRZQb+XRDBpeLUOvRdING XDbIYA+/gIOU+RWgx1eZmUEGczcK6Et3ZZpcWYeCYvt2cB809X258OgcU45k4uB68TEr ARnKivJKP2CDK6ZoI1bdDxV6cU5ET1VDADbL7molQyVo+DLxUMys5WYXA80ZcnkBRDGl IHuw== X-Gm-Message-State: AOAM530Wa2+pp1oUVtUMbZs7Z5MVlyUHqccmPzCnzSKJYr0vCGfd7ZaW BQt7QFmKgCYQ6xXNOn6bUVi4hZwlryntw0RaL7NykQ== X-Google-Smtp-Source: ABdhPJwojrxOtYNSZ/h1aOkE1Huj/+abO15E/b7QA85zSXAzjcAkkCH60ACB4mUEEjEqbTh1wmgYQkcYr9+uWTYnxi4= X-Received: by 2002:a65:63ce:: with SMTP id n14mr8327870pgv.273.1624606213877; Fri, 25 Jun 2021 00:30:13 -0700 (PDT) MIME-Version: 1.0 References: <20210624123930.1769093-1-linmiaohe@huawei.com> <20210624123930.1769093-3-linmiaohe@huawei.com> <1b38b33f-316e-1816-216f-9923f612ceb6@huawei.com> In-Reply-To: <1b38b33f-316e-1816-216f-9923f612ceb6@huawei.com> From: Muchun Song Date: Fri, 25 Jun 2021 15:29:37 +0800 Message-ID: Subject: Re: [Phishing Risk] [External] [PATCH 2/3] mm/zsmalloc.c: combine two atomic ops in zs_pool_dec_isolated() To: Miaohe Lin Cc: Andrew Morton , Minchan Kim , ngupta@vflare.org, senozhatsky@chromium.org, LKML , Linux Memory Management List Content-Type: text/plain; charset="UTF-8" Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=P+hZ4H0V; dmarc=pass (policy=none) header.from=bytedance.com; spf=pass (imf22.hostedemail.com: domain of songmuchun@bytedance.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=songmuchun@bytedance.com X-Stat-Signature: xtmq6tiw7nuo4ipnoupagg6ikuoqrk66 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 3C40FC00CBE2 X-HE-Tag: 1624606215-747185 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: 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. > > > 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 > >> > > . > > >