From patchwork Wed Feb 21 09:10:28 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: 13565140 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 39AE3C48BC3 for ; Wed, 21 Feb 2024 09:10:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A85906B0071; Wed, 21 Feb 2024 04:10:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0E416B0072; Wed, 21 Feb 2024 04:10:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8ADED6B0074; Wed, 21 Feb 2024 04:10:46 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7926D6B0071 for ; Wed, 21 Feb 2024 04:10:46 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 528E31C0A74 for ; Wed, 21 Feb 2024 09:10:46 +0000 (UTC) X-FDA: 81815240892.30.6648B7E Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf21.hostedemail.com (Postfix) with ESMTP id B6C5A1C0025 for ; Wed, 21 Feb 2024 09:10:43 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=k3x0Iume; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.177 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=1708506643; 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=AZrK/F617BnVPDrc38OOvpBVEVkH26jNk6vxgeNneU4=; b=e4I1A1N0XbjPP4illtuQ0YyvTdS25iIXZqixrwiC4woy51EQm8j+uB/UcOCVpf+BUKcXqT UmLgPaEwmewjp7PgLpyhCyRDFw7Yh+aPoh1j6AvAOSaO+loGSpaZkfjht4QGkS3iY3SWoM zBqO0Cwh62N+j2u+/8br2wn8vnHSiFo= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=k3x0Iume; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.177 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708506643; a=rsa-sha256; cv=none; b=BF2HdOBVDPjTd/wxxZbUK+WekI6Y+tp29M/KGNMdjywmoacAKcEXcFTkx/OzOKuVgxoYkV bDwJz4vy0IWWLaK4jfPdUTIcxDi7OvEdr9pDEtK0bxBWABKst4KNQNuEBQFtrz/sbUMh0H skfdnn0zOto6wwqZh4gMKrzX4P8Wxto= Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-6e3bdea186cso1742425b3a.3 for ; Wed, 21 Feb 2024 01:10:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708506642; x=1709111442; 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=AZrK/F617BnVPDrc38OOvpBVEVkH26jNk6vxgeNneU4=; b=k3x0IumeTJ6G5HOafUbx+DBSdU2/bi+eoUMNoXsklmQofeozD7/lSqIwkR1GTqaWUI Nr46erXtp3m3xoXxWoFFUqglmBgAw9cXI1k3+qFjDaANXDHbb6zIDVdMpv70QsDxUw+7 RIdiacFJKyUP9VwuXX8dhlsy/y2UvNzS/vni+APc7QyjIS6NiXDuxquiCUat8ufQRYop wR9mwrYzUlHsFvXrxZ+cvZ1VXuRKoDWwcE8Xqz+Kg6evoTeDsdt1R6jzBMNFM84VsVvd 1xOznHuS3J2DIklwF/vO5hNzNU7/+EzI58g8bQZ4DOypzPNHUXWnN/6WdSncvr5r/kOb FvOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708506642; x=1709111442; 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=AZrK/F617BnVPDrc38OOvpBVEVkH26jNk6vxgeNneU4=; b=ayrgKjErOq8l9guuQfpdhnpakthR+V4MEKk5/gZoyIgLHw/tWKo4eUA5tVyWM+frGk Ofw3hN/kBvz6U5Ae1aZt294+HuHW3rlup4d1SQ+dxNlaWUboP4jPZIXsLUSAAoVSJkti BkyQ8CEB4AscDfJbBzexE4ky3LY+5/TjG4djknmg49tjPKA95snqq0GP1dCKUBk7rYjR DAf4QMCJB3POhk2uh4wtHUEF8Lpt12Xcap8IwCXrmGz/xQJsMY2eJEnPFHI1cBWUg8WL XF7Ll9XaNT/M9R7PufKpk4jYk05OlTAmWR/FUMjKTcyTuOXPRhL1BFmGS1KDVsOJBv5l MQmg== X-Forwarded-Encrypted: i=1; AJvYcCWBhHgBWJI85Ps7C66Vls2eexFFmb7M3Bor+T2W1mKCCKX3d65Qq3URvzjGoSgtrTbtHTqfCL/TD4MMwQtTbllfR5M= X-Gm-Message-State: AOJu0Yy/opdQPPqEDNkuqZsBujX68eWpCBytuAxljE5ErMW6zL8oakvh o+k/UYTtIhNnaFYIF/sJu86kj6wT+FMrHHz2amXMu7mfStkrNtXR X-Google-Smtp-Source: AGHT+IGXZqxfiiMDC6vtnenG2qgZLaSI/0g1HeRJtxblZfh2W0gcZVCz8c+V7ui1oDCM/18JuK1pdw== X-Received: by 2002:a05:6a20:6f88:b0:1a0:64bc:743 with SMTP id gv8-20020a056a206f8800b001a064bc0743mr17634507pzb.7.1708506642497; Wed, 21 Feb 2024 01:10:42 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:e5f3:9cc7:f0fb:8762]) by smtp.gmail.com with ESMTPSA id jk2-20020a170903330200b001da18699120sm7628159plb.43.2024.02.21.01.10.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 01:10:42 -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] mm/swapfile:__swap_duplicate: drop redundant WRITE_ONCE on swap_map for err cases Date: Wed, 21 Feb 2024 22:10:28 +1300 Message-Id: <20240221091028.123122-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: B6C5A1C0025 X-Stat-Signature: jf7wsig1tsh1wh1mtkpxnsdu1yy8dy7o X-Rspam-User: X-HE-Tag: 1708506643-52284 X-HE-Meta: U2FsdGVkX19KzwhD1l9iEZaSoMXZPNhzkPR54FOkH5OSoKuX0pq+y3ioAX1Z838ucvVje/Za7B91R03F2ZXPs5H+Mbwkq+KulGTMLyMFURKS431Bq5l9oBWbaJniXLV172glEuYctR6HSfu+cfASOtflnkr8MY2cJyOvMVQOrX/4s/APrR4jjqEW9su4ZkPx25DN0rIZ1RJtHi2GYX994to062EB0d1SwDxh8eEIHgmT/Yt3wFcySanJ+48VmrYa45zwRyz6mUDrAE4ku2HfZGqY37weSH5IuuvvANQ3uBunNN4A4Y06mgRhVv1Y7hNTSXxzAhWKknJTVLbWw5LDyYsmBYhU8Eh4K9YvGwYCly7qhbqSRIg93QCISXU8CiTRBQpD9tyr1G/bIEu+aOLG/UXZ5isubB5PeDLuEJdr5yNNsExRs19abPeQIzRAH+1zr9olxzxSxbr9Ip/eW32bNN4M64ZvfwzplHCzKxsZAXw0m9g8GV9v+9f96xugJr5XijrFCtw7eZmS/AqMDJUxrTaEQGvpxtqSqHAu1ohSjb/QbRwAkEELJnHlv+ltyrZg1dU30hQcZI3VMyKP3inMNOAEZ8C0S9kaMdpcYZxlyeFjLp/RzqL0xuXHhhYdOiiNj91RoIT6hCQx0xFv3s0Z3gft9WcxzhncT6EQZou8ohEKjLnJrAxiCS/xADopFBiXGZ2/ICDtKHQ10X6R6MDY8ENokJcXYuYiez7cTNTB5OftKPBt0ngLMzOqK653G0/Rz0jGOWUu2aGB8ATgkMeycGvtCFiE2AlzZpO6E2ASyc/p22s2fKmuVN9ZLwFZ3zo+GFJ+gYZkXkKzoFcjWDLZ/p1N5xRPKsYlUsQsDMfO2wPRt2jbLp4mbqRNJPlZkXZ0u/BT6eaBK14cbQOR7X2/S1AqH+i3ufwl3GbqsElnHGVZR0jJoF/lgpj+H1p1G4MLtTNDyJS5kLOsv/JTVmh cQBFBuFH sk1giY87bCQEPzUvmQm4I8yqy8sg3Hlzmd/Kvl8Qo+67EEx+6kioRoD7vTWuD9xJpQR+HlpG1Wqc/t2dvRydifrO0gqUcCgJcF1T8iq0OjKX5SgF4Nl5OCGHIqU4DuXe/lceyY8jCU3qMEW+q+oHhyB2XapwtV45qfMZW X-Bogosity: Ham, tests=bogofilter, spamicity=0.095153, 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 --- mm/swapfile.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/swapfile.c b/mm/swapfile.c index 556ff7347d5f..17557003858c 100644 --- 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: