From patchwork Tue Sep 24 01:17:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Sridhar, Kanchana P" X-Patchwork-Id: 13810017 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 73173CF9C5B for ; Tue, 24 Sep 2024 01:17:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D4B9F6B008C; Mon, 23 Sep 2024 21:17:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CE3F56B0093; Mon, 23 Sep 2024 21:17:21 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B723B6B0092; Mon, 23 Sep 2024 21:17:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 9B4976B008A for ; Mon, 23 Sep 2024 21:17:21 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 519FCA16AE for ; Tue, 24 Sep 2024 01:17:21 +0000 (UTC) X-FDA: 82597868682.21.B774DB1 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by imf09.hostedemail.com (Postfix) with ESMTP id 233FD140007 for ; Tue, 24 Sep 2024 01:17:18 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SZZv6PUn; spf=pass (imf09.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.12 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727140579; a=rsa-sha256; cv=none; b=sUdn+aKxV6i5f8nubi1fxTgDDzSS5EO2C9f1aDlTL2TwjWo1myWuu+xdyweqbxAngT/pOj Opkm41dhkBSPMn219XFX5bvVGlp/08ug121EZ1NbzJEb87s4bFrrlE++9eJrhB32xTPAGv tsxjFMwXAJTx3bJCWVnzEp7/crqb2U8= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=SZZv6PUn; spf=pass (imf09.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.12 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727140579; 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:in-reply-to:references:references:dkim-signature; bh=YfUB20h+ZbfWHXPjxyHIrlPz9ExwouRgac9n957/Lm8=; b=pCz61/tlW8Fk90SGIUhz7Qvf3zSssjxNpiGrskNkFsG5Ve4h1xX4t+slxsVqf/DGATdV1+ sZVi94lir+RJKGrtsWzDuA53W9iqpD20m0oJ27qvtXz0QaDPH3uNyVA8G+X6CKMggX0QJu gKgm1ungz47dk6QmnLmrUUCAhPMr2fg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727140639; x=1758676639; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=C86so49XKpWlsyU2wpioV+UDdpE1jz5mE0FAlDLAhFE=; b=SZZv6PUnJj1997NGsPTLbA0B5sX4tvp5Op2k82qSHMYRvFzEP+LS4t3t zHioAHW+g6p8rgUr0LDWOLEL3FPsvegWFsy5h8gRVhYbdY+JDQ4rXM3Oi mnNuNhnHAZmpfS5yQF82P4zV+4UplmflCj07mkmeE1JqFAEjHBO9ZrLJy Lp4+sRxvV+B6wr7iqiJoKM7EHRCAoz3XUqPErsGU1WJWh6GkwqCSUvZFe W2wwGaVh1IKUG9xUQUbShn0SdhjUh+xvplTS/z7B7IKYGwrrr6yr+Yowg BeyxOHSCK6uw8jmMw3stUmGUBWISo3i+sE8ddeJFYGERuA/wcVsmuUG81 g==; X-CSE-ConnectionGUID: EKgL/Z5hSb2YgbCpwruddA== X-CSE-MsgGUID: SkL9sTUOSFGdO5fXUAbCNA== X-IronPort-AV: E=McAfee;i="6700,10204,11204"; a="30002027" X-IronPort-AV: E=Sophos;i="6.10,253,1719903600"; d="scan'208";a="30002027" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2024 18:17:11 -0700 X-CSE-ConnectionGUID: sEGsfpQ9TySxYR5zKcbTVw== X-CSE-MsgGUID: jSs+zcAeQrCa4Hib2fFedw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,253,1719903600"; d="scan'208";a="108688454" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by orviesa001.jf.intel.com with ESMTP; 23 Sep 2024 18:17:10 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, chengming.zhou@linux.dev, usamaarif642@gmail.com, shakeel.butt@linux.dev, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org Cc: nanhai.zou@intel.com, wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [PATCH v7 4/8] mm: zswap: Refactor code to delete stored offsets in case of errors. Date: Mon, 23 Sep 2024 18:17:05 -0700 Message-Id: <20240924011709.7037-5-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240924011709.7037-1-kanchana.p.sridhar@intel.com> References: <20240924011709.7037-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Stat-Signature: iq6tth6fmutj16bru1szq57txo8wpiti X-Rspamd-Queue-Id: 233FD140007 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727140638-51306 X-HE-Meta: U2FsdGVkX18MNgv15U/8IEHO5uVTrM1EH5Uns5fRF9z9SqRY8PUvBqWbQ09V+JcuF2IJ2U4J4LJVRM7CpsRrV3K2qbuvl4SI1sXlSAdAqVhxDvHgf4vxhibFO+3D6M7Y0p1nwuPNxSksfTOJ/NshPn4viZsILCfithfFUSxrLm4X+N3jb2AZsoZUht94mEcNsA95/mvic7Za028ArrFwQuI9KcDqCx0KRLRsC2BVIy5mYvywfdoF+3zeEZ2716n10ZMAerN0EEqWfX0N0CafO5GqGn5E+t2Tgyf79yXwZbwooxhaN5nYlhLtRphtdPD+cIujIGqeEKjoKVOF8IGsvlxuIyboCEB198TPy7V3JfDYc9PyMJF1UactFEh+JOaOgZD0GyACcchtsXTsovnBi9qPURjk3J/xiP0+e614io1y8itL8rVH1PFlzXfZsxUb+xqzXkbmUYHY8zljxYDsZTB207CnyY8yUG6hBUjgqv5WscHCJFFDJAe230ZTdtEbDN33cWtJb2cxItq5vhJCkAue6VIUocq5O3HW+FHJaE3g7WcgFO4wIyGt9Epu2Jo2EdUwFxBcCgylw7A3Z8kxz+BS0fv/KzXwcCkSdtzTYsOpU+UEespQARd/JdyW7ntfch032K+NWI1n2QevpUyvkkGG5dP2LUwK7F1+KBsVo8SW8K5n33Gytzpsrv3TYX29qDK0gQcsHI89AqVb1d4115hZ7YAuZh8stsA4GwzvHfFAZmXFO6KNvxXJAHupwNpTlELGeNjfR8uDWCEj0OuvdLRf71a7Dmc+GCIaAmg8A8AZMpcV5/fCaG1BdBST4pCrd+PfWkABhxCXCOY/oLKdRn/qMbz3P1kRT4TpjdttcoTZRLaVyaUa2RxiW7IlKuBo3CkYBns/HPkzXLTV2vSg5skeDUeLDi0HlmbjHbwTGDTqOEb4SmiXwNs9M5ySpwSDYgvxylrJV7kh3qeI0qN b9gV9nXt 0WZqXwu98PqkDDiY8+F66ikClgb/L67T+YQugpl138dMfFYzuNTniqaP8SOnrcTEkGX86K5doILBmkgEnYrJ7ST0BqUrlNP7UD4Y0Swg1hk24rPSMJrSDvT+wZYiXJGqlBMifvJzfb74C0zbndlyz/agIG28BM/B0zRtKEkPtb7/tmPthP8o5AG34ivlVOZPpBIOUFc+9IxW8ynai4aBDnGq3Vw== 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: Added a new procedure zswap_delete_stored_offsets() that can be called to delete stored offsets in a folio in case zswap_store() fails or zswap is disabled. Refactored the code in zswap_store() that handles these cases, to call zswap_delete_stored_offsets(). Signed-off-by: Kanchana P Sridhar --- mm/zswap.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index fd35a81b6e36..9bea948d653e 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1435,8 +1435,37 @@ static bool zswap_store_entry(struct xarray *tree, return true; } +/* + * If the zswap store fails or zswap is disabled, we must invalidate the + * possibly stale entries which were previously stored at the offsets + * corresponding to each page of the folio. Otherwise, writeback could + * overwrite the new data in the swapfile. + * + * This is called after the store of an offset in a large folio has failed. + * All zswap entries in the folio must be deleted. This helps make sure + * that a swapped-out mTHP is either entirely stored in zswap, or entirely + * not stored in zswap. + * + * This is also called if zswap_store() is invoked, but zswap is not enabled. + * All offsets for the folio are deleted from zswap in this case. + */ +static void zswap_delete_stored_offsets(struct xarray *tree, + pgoff_t offset, + long nr_pages) +{ + struct zswap_entry *entry; + long i; + + for (i = 0; i < nr_pages; ++i) { + entry = xa_erase(tree, offset + i); + if (entry) + zswap_entry_free(entry); + } +} + bool zswap_store(struct folio *folio) { + long nr_pages = folio_nr_pages(folio); swp_entry_t swp = folio->swap; pgoff_t offset = swp_offset(swp); struct xarray *tree = swap_zswap_tree(swp); @@ -1541,9 +1570,7 @@ bool zswap_store(struct folio *folio) * possibly stale entry which was previously stored at this offset. * Otherwise, writeback could overwrite the new data in the swapfile. */ - entry = xa_erase(tree, offset); - if (entry) - zswap_entry_free(entry); + zswap_delete_stored_offsets(tree, offset, nr_pages); return false; }