From patchwork Tue Sep 24 01:17:04 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: 13810016 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 8B9B8CF9C5B for ; Tue, 24 Sep 2024 01:17:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 645036B0089; Mon, 23 Sep 2024 21:17:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5F51E6B008A; 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 446C76B008C; Mon, 23 Sep 2024 21:17:21 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2220F6B0089 for ; Mon, 23 Sep 2024 21:17:21 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A4C881A16A7 for ; Tue, 24 Sep 2024 01:17:20 +0000 (UTC) X-FDA: 82597868640.26.9EF488E Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) by imf08.hostedemail.com (Postfix) with ESMTP id 7C88716000F for ; Tue, 24 Sep 2024 01:17:18 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=dAplLPa3; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf08.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.12 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727140603; a=rsa-sha256; cv=none; b=6c/TosiBkMl3bJ7T5hd+47km/7WUTFoinYfQB9JV10g1Psx+fFrJfxSETUrxWAmUvunpfq yomry4MyFh5OE6uUaV6mvLitMwRuTPFftJne8KArfmRfJbAkbqdn2eEm5P2Huhfo9TT5WR 9lb5cU914d5exlHIqdTnbIbU3gsmmfI= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=dAplLPa3; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf08.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.12 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727140603; 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=EBv3m2nI93FladilCYs/u/j4frjUgCIUIZqiel6SNjs=; b=wSrXDg4P1H6nKDkETeRt9jC8qHnO5hG1IgiK+tohpg9xJ3VzvQcM+Cxh2vgKink++jLmgr En8dCSo81IooA8RwheTogL/FQbqos/w9G+/umfd/KIxt8ki12GX6MNmQdBEQxq5uP1+QT0 alawMeT8jimWfseuHUpNsjPboc1WuVY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1727140638; x=1758676638; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RHgitxCwk2O92AmxepTIkYLlPlxcPNy3AMLz8p6gNWk=; b=dAplLPa3MKGgvE5u6qeVAAFexb7Dr0m7os5pHhABOW78z1ahL1AsuUMj lHGHIi238vFoSAP3IT2RTCkMRvjZzVYgHg9fwIhviiK+y82ti4PYJ+Soc C2KH8dU2UD6yhMBuKCRM87qyrHJu1LMghFVn2JSw2FM4t220/AcOmssxJ upDQiREZTjntElrZZi9A28uJ2Wi+Qwgb/Lsms3PNdul6qwbpo5Orftvqn bKg0sSLT2rb7XSiKY7Z6M5JyriMqSOJLKoqzElvJbGE5LVNSwbJ1EBexc qkPly2zJ7GBWFt33sxFq0qK30RtMOnhJJwu0tIx+bq/CS4gBWjFK0M/NW A==; X-CSE-ConnectionGUID: zC5nTFl8QEKbZ3Y5uZXiiQ== X-CSE-MsgGUID: L2O18fw1Q9CkPp3zRaILNQ== X-IronPort-AV: E=McAfee;i="6700,10204,11204"; a="30002020" X-IronPort-AV: E=Sophos;i="6.10,253,1719903600"; d="scan'208";a="30002020" 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:10 -0700 X-CSE-ConnectionGUID: l8/bok0JQDenH8syzM42bQ== X-CSE-MsgGUID: 3+hniOHXQ32cgOpTEREr0A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,253,1719903600"; d="scan'208";a="108688451" 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 3/8] mm: zswap: Refactor code to store an entry in zswap xarray. Date: Mon, 23 Sep 2024 18:17:04 -0700 Message-Id: <20240924011709.7037-4-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-Rspam-User: X-Rspamd-Queue-Id: 7C88716000F X-Rspamd-Server: rspam01 X-Stat-Signature: ro33ahszeqpfj8gwx4eh1pk7xa5ezkhy X-HE-Tag: 1727140638-18410 X-HE-Meta: U2FsdGVkX199Sn2Hc/bSpwiZGPX+g+7TopnoCwD/z2VV8Hf8n1XyTvqIfhJOp+ks924gI6rBpVDYYVG6Z7teD2XkbDo1irXIJrWybgHPp7tih3fNGZgFOB5zmpreMpzrHPIX5+KtWaJlf2/opaOVHYJW0y3fLqO2yuZc6cYy2+ZgD7q+ex4bOmWaXMtxjFbSK9HIHeHzr6gvtn7AWUoPZRfWfjxQvINg3h68xDfOemsMCMqGqkgSbHVUvEMlB3u9Ik/SZHtHEI1ClHb4u+8zv8JbWJs0HunFJHX3ase/qwskg81D8XaTiDGUU96fvl4tdWzJTZ8/SFbQLZNeqeyBphHTTA5rzGnzX95XrKp0oT7hifKtqthx3g3F5p86OqBkBUZvCn7Hj3qWkR695mhE7ta0QHB5x9AQZhSH3gKJl1mdISvprLY1c/2M+wDYD8O19336xh3VJyq+Kgu+cNo/bC/bfRdNpCpA6T3Rcj/EJTuBcmGwdyI59DVE+YicHKy06Ce3ta7JzjOH+y3l5dZwBCHdUb8B66W0UBEHmv80hf057bBRJt6YsQc7gokFRdweUu72MahIsMjJJR3N+5Sq1anU/JC8K/qhTUH2iYy18lSm3ZvGOs6fuvErqxo5dE8wfhjuo7PlMfTUgh1aVU/arDXAvD5kBRkxY00mOpEiPUuMB59PVLZNSDdUJGUIxt79+obPXSeITG6FQ0Foj4IQULjx9PKShHaY0Cg3O2IGbWHt33CLkFwAl0vnMigaYBjJG59wLqpbRsgonbsygg3KvypYzgOevat0N0/p3JudwRPs9P+4BzNfVNoHFVsrN8Mknp6B6b5f0n0merV78gL4OFeNXW2L/K+OzK05OJTGLMDu5QZqY4Peqh/CJB/kNTkRr3mJ3YlsZKSw4sQYjGBSir66L2b+VYZXnpgyczCGN9S9p4Ut4piMilccHoestTuy0/lCmARxrV8wLCOBHdO a3ybvtH7 PgIif0zgTwhQ3YaOMF51dGnjkb07aJEE/Ax3G6aobUVdjI+9P+S5kTpM0NecC9nJvdyAjPd/Hj8Dn3iR2n0eRcyrCMJnypyR6/JhDgviTJ69IzLSFoJCIbLEMTFXBzWq1wCWcluSYfV70EdmGu5vFOFgxX1BCuOYGYR+j8GKMUqE4cTGRDBBhPGfGHA== 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_store_entry() that refactors the code currently in zswap_store() to store an entry in the zswap xarray. This will allow us to call this procedure for each storing the swap offset of each page in an mTHP in the xarray, as part of zswap_store() supporting mTHP. Also, made a minor edit in the comments for 'struct zswap_entry' to delete the description of the 'value' member that was deleted in commit 20a5532ffa53d6ecf41ded920a7b0ff9c65a7dcf ("mm: remove code to handle same filled pages"). Signed-off-by: Kanchana P Sridhar Reviewed-by: Nhat Pham --- mm/zswap.c | 51 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 59b7733a62d3..fd35a81b6e36 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -190,7 +190,6 @@ static struct shrinker *zswap_shrinker; * section for context. * pool - the zswap_pool the entry's data is in * handle - zpool allocation handle that stores the compressed page data - * value - value of the same-value filled pages which have same content * objcg - the obj_cgroup that the compressed memory is charged to * lru - handle to the pool's lru used to evict pages. */ @@ -1404,12 +1403,44 @@ static void shrink_worker(struct work_struct *w) /********************************* * main API **********************************/ + +/* + * Returns true if the entry was successfully + * stored in the xarray, and false otherwise. + */ +static bool zswap_store_entry(struct xarray *tree, + struct zswap_entry *entry) +{ + struct zswap_entry *old; + pgoff_t offset = swp_offset(entry->swpentry); + + old = xa_store(tree, offset, entry, GFP_KERNEL); + + if (xa_is_err(old)) { + int err = xa_err(old); + + WARN_ONCE(err != -ENOMEM, "unexpected xarray error: %d\n", err); + zswap_reject_alloc_fail++; + return false; + } + + /* + * We may have had an existing entry that became stale when + * the folio was redirtied and now the new version is being + * swapped out. Get rid of the old. + */ + if (old) + zswap_entry_free(old); + + return true; +} + bool zswap_store(struct folio *folio) { swp_entry_t swp = folio->swap; pgoff_t offset = swp_offset(swp); struct xarray *tree = swap_zswap_tree(swp); - struct zswap_entry *entry, *old; + struct zswap_entry *entry; struct obj_cgroup *objcg = NULL; struct mem_cgroup *memcg = NULL; @@ -1465,22 +1496,8 @@ bool zswap_store(struct folio *folio) entry->objcg = objcg; entry->referenced = true; - old = xa_store(tree, offset, entry, GFP_KERNEL); - if (xa_is_err(old)) { - int err = xa_err(old); - - WARN_ONCE(err != -ENOMEM, "unexpected xarray error: %d\n", err); - zswap_reject_alloc_fail++; + if (!zswap_store_entry(tree, entry)) goto store_failed; - } - - /* - * We may have had an existing entry that became stale when - * the folio was redirtied and now the new version is being - * swapped out. Get rid of the old. - */ - if (old) - zswap_entry_free(old); if (objcg) { obj_cgroup_charge_zswap(objcg, entry->length);