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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C293C433EF for ; Tue, 17 May 2022 23:39:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E66978D0001; Tue, 17 May 2022 19:39:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E154A6B0074; Tue, 17 May 2022 19:39:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D04718D0001; Tue, 17 May 2022 19:39:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C191B6B0073 for ; Tue, 17 May 2022 19:39:15 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 7200D61DDD for ; Tue, 17 May 2022 23:39:15 +0000 (UTC) X-FDA: 79476853470.11.BB64F14 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf12.hostedemail.com (Postfix) with ESMTP id 6A4D1400A3 for ; Tue, 17 May 2022 23:38:46 +0000 (UTC) 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 dfw.source.kernel.org (Postfix) with ESMTPS id CEBED6147D; Tue, 17 May 2022 23:39:13 +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-Stat-Signature: z4r1w7yrpnz3f7dm9e8omntz7s6hk3m1 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 6A4D1400A3 Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=nTkTzCQq; spf=pass (imf12.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-Rspam-User: X-HE-Tag: 1652830726-684674 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 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. _