From patchwork Wed Feb 21 21:08:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13566288 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 EA80AC48BEB for ; Wed, 21 Feb 2024 21:09:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5CB526B0072; Wed, 21 Feb 2024 16:09:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 57A9B6B0075; Wed, 21 Feb 2024 16:09:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4431C6B0078; Wed, 21 Feb 2024 16:09:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 3646B6B0072 for ; Wed, 21 Feb 2024 16:09:16 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 05E451A0B8C for ; Wed, 21 Feb 2024 21:09:16 +0000 (UTC) X-FDA: 81817051512.29.CE7C50C Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) by imf26.hostedemail.com (Postfix) with ESMTP id 18B0B14001B for ; Wed, 21 Feb 2024 21:09:12 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Dr0vNxyD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708549753; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=MgEgI0pyQ0ahFABUGJN4FTJZ0fWcQT3ObrmUIWNiMM0=; b=G8mLEobJxIaxhl0rIBErhw98WAovR+RUPjR+53ucfbEkjo1NbSBFTFSDh7csmqUrZ62X6D iDPtwTlIYGBLSX1q5T1DMlsFX9ihmF8m1Guq71wnPnw5pAQjOIEb6tZblT9JWfwDRzKOuu /5Rzof/LisBdMFIMZJB/WRAG49woF4Y= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Dr0vNxyD; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.178 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708549753; a=rsa-sha256; cv=none; b=dVEVGZwuvtOVYd4ynVFsPVPk1rUosgqyCyBMZ/j/EDHpuOnAVtlhNjDnrraHtn7mNVP2oG qWVg9OZPU5gVCB+BP/5VBoFGIo/QXbUNe4Zl8b9U4B7y5GFAetZmF4uzg+YPqqRTu3LDDv A1xKkddWMxWrlMIicRfkqaISsfZpEms= Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5d42e7ab8a9so5076419a12.3 for ; Wed, 21 Feb 2024 13:09:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708549752; x=1709154552; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=MgEgI0pyQ0ahFABUGJN4FTJZ0fWcQT3ObrmUIWNiMM0=; b=Dr0vNxyDjXDLtzVeIsqLL5kyRQp2q92YVUDd2Dh8YLHz4oAevkpvZ3XVngtg0AEVj8 Vee1xj4D0qgz1dmWbW0hRSrzqLzQzGGmDTr77HTUXdSmpDKvLpl8DLytVeyT4KRxc2eK v8cF+hIZH8D6YzIoUzAlIgXFWEXQyTnElIb6uT5CZLe/x7dYFho2x8kmtABtrT/qbN1C idSvw+dhya/E4UhQUbVKJF+VNAnB5NoDnPX6JxTmMAt+qNON2MOChUXMqEHIBX17V38u LeGCyMp8rhvF+/u1hCd4tr1+jbHIpxp/645LLmMxsXhShZ3q1gGLczcER03OWJ4Yukzr bOoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708549752; x=1709154552; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=MgEgI0pyQ0ahFABUGJN4FTJZ0fWcQT3ObrmUIWNiMM0=; b=KzHk6ZNMZPiovVKqiXTYK5L3jOYVPOfU8YB8V4aS/u9owMj4B023ESk88rbuXus6XV xnc3CgqyXH4k9efaiLhZXTIqGfiZDjic/T4MbNx7TEAd7yTqeVxdpOa9kIQusAVvLKPN AkwYpcuoiEEmvE5Ht27MZeWdLPUQRFZIF9bKWRnXlME8AC8jzZ64B/s3y2vXMpBBdwbp qTcQJ2dMlcqJ2sTzAZXChqtMsETfF5iPsxU3nUah3ZJ5JxWUmFppRhr1XnOkYUwP+d0R 9wf3fIJ3wmwBl+1IdiScZX01nzw9LGf4S+HSCweTq9C8Yx11oZeXnNf+o4VqZTE5ncKZ qhUQ== X-Forwarded-Encrypted: i=1; AJvYcCXyHIBAR2KPfzubusQ6yhZbvjj9dY6upEv1JzYwpObAiX1XxBFYViPNnAaUfzsjjXwLtZb6Pr/BJPig/Mab5PuKaIw= X-Gm-Message-State: AOJu0Yw3tFyBXp48reCd35gbNoHkjldH2hIeH76tWBbnzwPOx+wR6c5N kqUiN7AQ6DKhysdVsDqiweX4DSZwduXXOGjVS8zG78X8MLqlyf1v X-Google-Smtp-Source: AGHT+IGx4Ckh9+rgDzCEHIwqC+BEIR8tWS3MN+9/iDSLEeA1aJK0bU29MEZzWU3iKIn72xFWfbRGzQ== X-Received: by 2002:a17:90a:bf0f:b0:299:6479:4678 with SMTP id c15-20020a17090abf0f00b0029964794678mr8599563pjs.19.1708549751681; Wed, 21 Feb 2024 13:09:11 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:366d:9fa0:e78b:3075]) by smtp.gmail.com with ESMTPSA id l21-20020a17090aaa9500b00298c9790610sm10004596pjq.6.2024.02.21.13.09.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 13:09:11 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Barry Song Subject: [PATCH v2] mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases Date: Thu, 22 Feb 2024 10:08:45 +1300 Message-Id: <20240221210845.13488-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Queue-Id: 18B0B14001B X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: t8zywrmkyjs1azfzf4k3x17fmdcuzmon X-HE-Tag: 1708549752-456910 X-HE-Meta: U2FsdGVkX1/slqVViDhT4pjNSMzvxMY/Fini77J6s7kQJQnh2+3ECqrcnSTBbWOYMFCi8XOaJNHrUMT8WQZYGSYNUUqYYKCk+aKmjqpWiauWwQCbl+5oSPPVlJAUXW7k/6+zHuXDsI0DMJ9oZi2LOin5uBfQZEkjFtDWBZv9iiMCzJ4w/0SPICfNgVVb5Y7ncpC+O3+C2ZvF42Gm/UEGNsT+jAgp6lQgLcjkqbcNX8VtHIMsuxqvtJcfVWXsQsZU8DJPQjX79X+QwobzwmyuGgAD47VNal49N2mXzmxdXHbZqpS+KxHKcdVfSvdxXMKIFQMfNcwYIYwu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vPZIYSBvY0XEZHvzJ8+RaKRV/brXG8ogLU2QalgIdGeUg6Mur2U01EiFpSsY18pV9Z8DOPOZ0DLyQoUQEst+yUQpYqhC36zQFlbQYl6rAg0HdxrHCAMxTMGPcmsg6hdENz0dCYBp15Hoy3gF 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: List-Subscribe: List-Unsubscribe: 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. Signed-off-by: Barry Song --- -v2: drop goto according to Andrew, Thanks! mm/swapfile.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/swapfile.c b/mm/swapfile.c index 556ff7347d5f..7cb6d9a2d51d 100644 --- a/mm/swapfile.c +++ b/mm/swapfile.c @@ -3320,7 +3320,8 @@ static int __swap_duplicate(swp_entry_t entry, unsigned char usage) } else err = -ENOENT; /* unused swap entry */ - 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);