Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp113684iob; Tue, 17 May 2022 20:40:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJydBvbCDArnZh1/8ZpvWFw8Pq2KexaN5m+Yhcs9HyFL8A5x8AEwqiuUAJaV1p5zGxXTrQOi X-Received: by 2002:a62:1c4c:0:b0:518:ded:1e19 with SMTP id c73-20020a621c4c000000b005180ded1e19mr4911648pfc.24.1652845231002; Tue, 17 May 2022 20:40:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652845230; cv=none; d=google.com; s=arc-20160816; b=hWo640NJdjPhAxxdhCxnUiCwvwe3z5zijLzZ5OyQ62Y8WbB5iPfiYb00nGee+sCfT0 GIy0HgX9/JZEUY9UVRxv3Q2s0/4QX6vSB0LonzrHC3mo6BBBI9hmN05wUVpGqrSLBPIP DyEteEPLtVjt/WpdqtGkyzakg9qiuO5sIQYTckZXypA7XPwbNk8IWXNdJZet3/9uhi65 SgqGvJWyfIrdaztwYAfBbq1k6+nB29l5j87930Zn++mp26dyyMERLdxOFzYrHnqJPPRV rEaOT45M87Uvw18K28Qg9V/Pdvc+8MgYSM4GDV5ErjaD9/6iWlb7V/p1o69gcrh1FrxZ 9zCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=k0eBuSb9tIpfzvmfOx7Pt/l+furpnSwuBIhmGu/nXAg=; b=TanAY6ihHZcVoBD9Sq3k+SCU3yvM5CjUMzH0hOdQbDC88WjHN4Y3ynRrwLCl2DOAsK bumZYSfthYSl7honItLtTyGgDwCgexdtd90Nq2EfJVYYo15ln7LQpgd6nrW+FDgIohv2 naEW5LwOk8iIFVIODJ/1zwYrsye40XDMuC0Cb+/ko+gNygGg+JRWK85O7nootF6vhDMR WepMHvP46OVHpIfJQz01BYjnWTPACD89gQORH03TSz4J7+aN8uVIzILd6VZOM3y3ivZH ipPkG7WWDYSD56FaWFX6wm7XGEqTxR4woR8YSh63aIFNDkZDyvYdXydOvOtj8nX2Zk3C lrYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=nTkTzCQq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n13-20020a170903110d00b0015791a0f6f4si1276937plh.577.2022.05.17.20.40.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 20:40:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=nTkTzCQq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C84F3663DE; Tue, 17 May 2022 20:29:01 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231897AbiEQXjS (ORCPT + 99 others); Tue, 17 May 2022 19:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229655AbiEQXjQ (ORCPT ); Tue, 17 May 2022 19:39:16 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5A3452B2D for ; Tue, 17 May 2022 16:39:15 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 74D64B81D63 for ; Tue, 17 May 2022 23:39:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D69F9C385B8; Tue, 17 May 2022 23:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1652830753; bh=65mgIOZQb4alucF36hrCIzo3EqeozYcFQHGE5BWleDw=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=nTkTzCQq+k6ZGWtcRrAwxyP+pEayku3g3Cn2dp8puLuk+tazqL2q2aL4bYpFSK+Xc /Y1Mj3RyBkGrdCnPdj1naIR9j81C5G38jaWIBfyuzL/bbfirPxyIzyodpq8rRPBXHf //e3yx2m8Uke14VNx08u4foLV4M0F78b+XhjxzRM= Date: Tue, 17 May 2022 16:39:12 -0700 From: Andrew Morton To: Miaohe Lin Cc: NeilBrown , , , , , , , , , , Subject: Re: [PATCH 09/15] mm/swap: avoid calling swp_swap_info when try to check SWP_STABLE_WRITES Message-Id: <20220517163912.919475bf7fb5923da1325822@linux-foundation.org> In-Reply-To: References: <20220509131416.17553-1-linmiaohe@huawei.com> <20220509131416.17553-10-linmiaohe@huawei.com> <165214248406.14782.6536817483979050668@noble.neil.brown.name> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 10 May 2022 10:21:21 +0800 Miaohe Lin wrote: > On 2022/5/10 8:28, NeilBrown wrote: > > On Mon, 09 May 2022, Miaohe Lin wrote: > >> Use flags of si directly to check SWP_STABLE_WRITES to avoid possible > >> READ_ONCE and thus save some cpu cycles. > >> > >> Signed-off-by: Miaohe Lin > >> --- > >> mm/memory.c | 2 +- > >> 1 file changed, 1 insertion(+), 1 deletion(-) > >> > >> diff --git a/mm/memory.c b/mm/memory.c > >> index 9c3e7e6ac202..89dd15504f3d 100644 > >> --- a/mm/memory.c > >> +++ b/mm/memory.c > >> @@ -3892,7 +3892,7 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > >> */ > >> exclusive = true; > >> } else if (exclusive && PageWriteback(page) && > >> - (swp_swap_info(entry)->flags & SWP_STABLE_WRITES)) { > >> + (si->flags & SWP_STABLE_WRITES)) { > > > > Should this have a data_race() annotation. Other bit-tests of si->flags > > do because scan_swap_map_slots can update it asynchronously, but we know > > that won't matter in practice. > > Yes, you're right. scan_swap_map_slots can update si->flags asynchronously while > do_swap_page tests SWP_STABLE_WRITES here. We know this is harmless because > SWP_STABLE_WRITES is only changed at swapon/swapoff. > > Will add data_race() annotation in next version to avoid possible KCSAN data-race complaint. > I did this: --- a/mm/memory.c~mm-swap-avoid-calling-swp_swap_info-when-try-to-check-swp_stable_writes-fix +++ a/mm/memory.c @@ -3889,7 +3889,7 @@ vm_fault_t do_swap_page(struct vm_fault */ exclusive = true; } else if (exclusive && PageWriteback(page) && - (si->flags & SWP_STABLE_WRITES)) { + data_race(si->flags & SWP_STABLE_WRITES)) { /* * This is tricky: not all swap backends support * concurrent page modifications while under writeback. _