Received: by 2002:a05:7412:cfc7:b0:fc:a2b0:25d7 with SMTP id by7csp2592731rdb; Wed, 21 Feb 2024 12:36:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXBgXrPDCAwsQQIUrWceK0ttjs3nO1I269sAnoQQvrRhug8/il8YGWvMT9RO1DLBFo2MLHJNcn2awLy5OmUvBSvh5a3U6ZyFDjQtTnK/g== X-Google-Smtp-Source: AGHT+IEMv5/JfyyUQ0l/1VN4CRFWWd2WwR3DHAjmnEx1l7mDMr6LRWhKiLO4NSV+tpDYVVkCcen3 X-Received: by 2002:ac8:5a15:0:b0:42c:2d78:8493 with SMTP id n21-20020ac85a15000000b0042c2d788493mr24432652qta.34.1708547776152; Wed, 21 Feb 2024 12:36:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708547776; cv=pass; d=google.com; s=arc-20160816; b=wWKp7LRcGusGo9f0/CfM3QLoEaBl6mb9k9s5snhQyk2/p5EHwAMt7dC2JWFHMJVnlz JrfZzqZkvex7CfzZbdW/5vkUDMhfe2SsUHmkQoxJ3tVrDvS5aeZCo5JBGfl4qcM7P0MK ddJKgKR8qHtWh+M07tz9mrmBPkwEnW1m81E8elv/YWOnQGLxCqMSz7MWdzaL1ZN6QsXU 0y/VGTEWRkiiUR7H/eVExO1ZzTrjwr4gH7XPfLtSXFQW8nle/0cD7UwDeapA2t1CLCi/ OZK1f6MIP8JYC7dLna4MeVJLpGR/zv/GNZjQabvmhAJ9VPLuC4lKKlqU26WpTVD3ssHW gR1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date:dkim-signature; bh=RmvCzu/yUeqVtryQzxOkj9l9Tdhl3SMCOD5K5IFbqUI=; fh=Zb9GS0ior5OYyz2pJ6iCbKndlCdbzInw+EyOrIGuBHQ=; b=fbo7D2mVpP4aXXeCmFHdwkxbb1vUfmwj78/p1mNY0bcDUqxg4hXzdvaGfjueJjgVsW w30MITJvqkH0IMI2nE1Ypg78YQyM1kDAuKoMPDgPtiYky2UPwM+AzURuwMWU2KzfmQx1 b3FWPPZXOIrrIbMp7phM5dP6PzZxVkx29TUJZhHsnlz1xwVceBUEoDvrZlt+6XGnpSlJ XKjWrp37JzhzurHK7hD+hZ8mfIkMJlqpYFsYD5CWCb/iDu5Eu1QkoubgspQpFvuCqa1/ W9bsI+nbeBdqOndk6Ef0eywATd88bzjB6qs6P6b6qgjNh+8ohKi5sPV9nmaiK+3cRd8/ uVRg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=NhXTm9Ss; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-75467-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75467-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id s14-20020a05622a1a8e00b0042e1614768csi7189306qtc.726.2024.02.21.12.36.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 12:36:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-75467-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=NhXTm9Ss; arc=pass (i=1 dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-75467-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-75467-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E2A461C2113A for ; Wed, 21 Feb 2024 20:36:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 96FDE3A1AF; Wed, 21 Feb 2024 20:36:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="NhXTm9Ss" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B064453A1 for ; Wed, 21 Feb 2024 20:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708547770; cv=none; b=DiaHGISGRbQY9axAUt7N1h7ImAXDQIYNtzfhoonk0rBKyyaKhsw2Xi3zS/yk9p3iN7FXHGA3XPUQ5GZVuDLs/j2QFFvkfC4TY0k/lmMEUZOdHlBGuLBFpT2sbFmdKiANm5JOpUHWZZtsahTiY8LSXHBKZ3VVXLoAUIskZelvJkE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708547770; c=relaxed/simple; bh=hWY1Y7gwaHsCt+60O0plbbDiTxgt1/isDaR9hySz3Bo=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=QMqpyIzffGrLr/Iq/ZTeFYrxYd0wBaeZ8+rUfXJHUbUpMv6vU4lAR7nHSMeHtLsrLaIcfVLqXq6rmnslhY9L6t9rIMfXPEneIGY8X1TksdCt6DV1d99nXd1wA8+cFO5XG3d/9NTGKjCBA+atHC78MC5SifP59EVracSHnNCBq4o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=NhXTm9Ss; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DFE0C433F1; Wed, 21 Feb 2024 20:36:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1708547770; bh=hWY1Y7gwaHsCt+60O0plbbDiTxgt1/isDaR9hySz3Bo=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NhXTm9Ss+RtkoPhR9wtAeLEzXXMWA+4u6rw8ILNyykZ9foBpB4ny8n/PFimlKdEY6 LXlO6hlrVfgSbm0HQ6HtxVv8I17FVhBaYhkC+6xF8aZb7w7ZUoNalfj4gSNTZz1NCg tKwNt2lg7LFKJR3fvlZcAtPNbNG2IXowaer4P7WY= Date: Wed, 21 Feb 2024 12:36:09 -0800 From: Andrew Morton To: Barry Song <21cnbao@gmail.com> Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Barry Song Subject: Re: [PATCH] mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases Message-Id: <20240221123609.3cd20c3dc2d6adeaf5d3ffc8@linux-foundation.org> In-Reply-To: <20240221091028.123122-1-21cnbao@gmail.com> References: <20240221091028.123122-1-21cnbao@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Wed, 21 Feb 2024 22:10:28 +1300 Barry Song <21cnbao@gmail.com> wrote: > From: Barry Song > > The code is quite hard to read, we are still writing swap_map after > errors happen. Though the written value is as before, > > has_cache = count & SWAP_HAS_CACHE; > count &= ~SWAP_HAS_CACHE; > [snipped] > WRITE_ONCE(p->swap_map[offset], count | has_cache); > > It would be better to entirely drop the WRITE_ONCE for both > performance and readability. > > ... > > --- a/mm/swapfile.c > +++ b/mm/swapfile.c > @@ -3320,6 +3320,9 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) > } else > err = -ENOENT; /* unused swap entry */ > > + if (err) > + goto unlock_out; > + > WRITE_ONCE(p->swap_map[offset], count | has_cache); > > unlock_out: I agree, but why add the goto? --- a/mm/swapfile.c~mm-swapfile-__swap_duplicate-drop-redundant-write_once-on-swap_map-for-err-cases-fix +++ a/mm/swapfile.c @@ -3335,10 +3335,8 @@ static int __swap_duplicate(swp_entry_t } else err = -ENOENT; /* unused swap entry */ - if (err) - goto unlock_out; - - WRITE_ONCE(p->swap_map[offset], count | has_cache); + if (!err) + WRITE_ONCE(p->swap_map[offset], count | has_cache); unlock_out: unlock_cluster_or_swap_info(p, ci); _