From nobody Mon Feb 9 03:47:17 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 E75C7208A4 for ; Mon, 19 Aug 2024 02:16:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724033785; cv=none; b=pzoF9XyW6e9L5BzfXiOjW6G1zIL5nHI1tygMJZrTcbv2NOPk8qXVwSCeJ+nl8U+Dj5AHFzxE+Q9kXv1Nu/WMHEPSrLapnYiJ2QSNTfGE/HYY1q6tXpTxm7umCfVJoQRQl3PQaafFXjsLYUPRpq0zKDTtGmJH5T7thWl6eJfyVds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724033785; c=relaxed/simple; bh=i9i0GU1tqbl+gZG9rdF1xrCDy8bSikrdWFFB2p3UFUw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=n1xdH/L6xolWQ3SSwTI1BDno0ySVGJjPSuxWUzAXOE8qt3RW6lvHngDdTUN/L0fR3SxFkfxOMCgGV8U44GYzN+bu52CiNNfrVzy4OkG9DEYtEqRxkymj68P1snFk3AJFhE7ZvF0wVMtxBv1bZd27BR1gwoc336tBakV4I8nsfVM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=n8+ZbJkw; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="n8+ZbJkw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724033784; x=1755569784; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i9i0GU1tqbl+gZG9rdF1xrCDy8bSikrdWFFB2p3UFUw=; b=n8+ZbJkwIVZqGnxMaQ1Ip5KPL4n4+9mrj2IEcSrOhsL6EfKGV/4eI68T Gg8m4A4j/2puc9F6V9kAiKtpoeT3C/DmeH0kBm9c/5NS5Ulsy0KqIh5rt VY0AL+it8/ihygE4JfOOBOWpOM/9zTZbC0MMxSsrRQf78NaZ+GT9xG1pD HFNllmOjlp3VIGFGfRRoosFwnjcaPkIO6YDK0ZsAZX6JyzRDmmARCdga2 fGOHd/j0gRclDCd6RCXsxysYP/gYRX4XUiArYtKNudNcL12IWKmqTXHKL AIKeqkzh4Fzm2Un98XCpd3gqFhXHFdf7qfXcr01eQHIrCvssTyc3nhqRt g==; X-CSE-ConnectionGUID: cRZ2sW0iTZK3P5Oq2KvhiA== X-CSE-MsgGUID: J0WMNWvySDysrcSe2UAHcw== X-IronPort-AV: E=McAfee;i="6700,10204,11168"; a="44782958" X-IronPort-AV: E=Sophos;i="6.10,158,1719903600"; d="scan'208";a="44782958" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2024 19:16:23 -0700 X-CSE-ConnectionGUID: wUHvjw1jTIGDkmypoq16Tw== X-CSE-MsgGUID: R4qRuZDVT/aLemdFg0NPEQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,158,1719903600"; d="scan'208";a="64610270" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by fmviesa005.fm.intel.com with ESMTP; 18 Aug 2024 19:16:21 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, 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 v4 1/4] mm: zswap: zswap_is_folio_same_filled() takes an index in the folio. Date: Sun, 18 Aug 2024 19:16:18 -0700 Message-Id: <20240819021621.29125-2-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240819021621.29125-1-kanchana.p.sridhar@intel.com> References: <20240819021621.29125-1-kanchana.p.sridhar@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This change is being made so that zswap_store can process mTHP folios. Modified zswap_is_folio_same_filled() to work for any-order folios, by accepting an additional "index" parameter to arrive at the page within the folio to run the same-filled page check. Signed-off-by: Kanchana P Sridhar --- mm/zswap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index df66ab102d27..6434e76a4ea3 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1419,14 +1419,14 @@ static void shrink_worker(struct work_struct *w) /********************************* * same-filled functions **********************************/ -static bool zswap_is_folio_same_filled(struct folio *folio, unsigned long = *value) +static bool zswap_is_folio_same_filled(struct folio *folio, long index, un= signed long *value) { unsigned long *data; unsigned long val; unsigned int pos, last_pos =3D PAGE_SIZE / sizeof(*data) - 1; bool ret =3D false; =20 - data =3D kmap_local_folio(folio, 0); + data =3D kmap_local_folio(folio, index * PAGE_SIZE); val =3D data[0]; =20 if (val !=3D data[last_pos]) @@ -1496,7 +1496,7 @@ bool zswap_store(struct folio *folio) goto reject; } =20 - if (zswap_is_folio_same_filled(folio, &value)) { + if (zswap_is_folio_same_filled(folio, 0, &value)) { entry->length =3D 0; entry->value =3D value; atomic_inc(&zswap_same_filled_pages); --=20 2.27.0 From nobody Mon Feb 9 03:47:17 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 2DC0B224FD for ; Mon, 19 Aug 2024 02:16:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724033787; cv=none; b=erRGBooj+MsZZ41abimWULaedoIn2bFEKu9N8guViJ2+gmEE5M9xxSk8O+ZWa/ws6XByOm4mYxD5Qeha7PFWK9KVJ4+3uhK6Trxa/71qr7KFsHJRjVc7pLh6a7YfkYr5MUL94xqCagmygdxGjP0hV1UO5oWd/6snmb6BTxE/jqw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724033787; c=relaxed/simple; bh=Brs+d0RWd3m3x72bXC3nHyVxOKVWfAGnWhAdd32EUtA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ecZHeA4hcUBHsGib9A4Qgul3N1YOmeK9kPlx1NU6SBDK13jgWi/4fV9exeLP5hUfAUeWdII+HlREx9T06ap2BR40JCACkssHPmwCtqB6lhZOWQrglqpUQpcLzsjO/DqOIv0qy+kkOz/3NbnmPrGPc2pGGW1tSyFIgiPuRb4BsLg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=fpAgqG0j; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="fpAgqG0j" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724033785; x=1755569785; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Brs+d0RWd3m3x72bXC3nHyVxOKVWfAGnWhAdd32EUtA=; b=fpAgqG0jRVXljBJTZE+XZ8uHTLFs3HwtNNsgid74N8tPC6xz3MFtbw89 LsMbgMVkkS12GInwYWtPnLPU72x/FjmaO36WI2taTrMaCnKWBKVX8YYDg 4sVrO3kwlmbt9AYFrWNlU9X6IhVK8kBC2oQ4ngvGqgXxr/3RKGAMcBGxD Pf4AV2psGNBh08PDQOXxRA6Dxk+oU0eNxQrQKDIApTOTJdzH2N6yK3GGf 6XH5qpuTJeBIG2tjRW71+FAPtK/iUMI8Yzr/yB+QmySkc1EXJWOeksWLg ti/ph/234+M8SZRyjQCGUSGZkRAJq2GQeJRKPXmCRIgejTS3P3jPYUcTB w==; X-CSE-ConnectionGUID: q8mgrJaVQO+REw2PQEEIHQ== X-CSE-MsgGUID: P7SgcYYcTwiV32ZpPwo6Zw== X-IronPort-AV: E=McAfee;i="6700,10204,11168"; a="44782965" X-IronPort-AV: E=Sophos;i="6.10,158,1719903600"; d="scan'208";a="44782965" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2024 19:16:23 -0700 X-CSE-ConnectionGUID: xF8wM+DER2KVerhf5nrDDQ== X-CSE-MsgGUID: l8IiLFcXQl21mePbv8afzQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,158,1719903600"; d="scan'208";a="64610274" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by fmviesa005.fm.intel.com with ESMTP; 18 Aug 2024 19:16:22 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, 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 v4 2/4] mm: zswap: zswap_store() extended to handle mTHP folios. Date: Sun, 18 Aug 2024 19:16:19 -0700 Message-Id: <20240819021621.29125-3-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240819021621.29125-1-kanchana.p.sridhar@intel.com> References: <20240819021621.29125-1-kanchana.p.sridhar@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" zswap_store() will now process and store mTHP and PMD-size THP folios. This change reuses and adapts the functionality in Ryan Roberts' RFC patch [1]: "[RFC,v1] mm: zswap: Store large folios without splitting" [1] https://lore.kernel.org/linux-mm/20231019110543.3284654-1-ryan.robert= s@arm.com/T/#u This patch provides a sequential implementation of storing an mTHP in zswap_store() by iterating through each page in the folio to compress and store it in the zswap zpool. Towards this goal, zswap_compress() is modified to take a page instead of a folio as input. Each page's swap offset is stored as a separate zswap entry. If an error is encountered during the store of any page in the mTHP, all previous pages/entries stored will be invalidated. Thus, an mTHP is either entirely stored in ZSWAP, or entirely not stored in ZSWAP. This forms the basis for building batching of pages during zswap store of large folios, by compressing batches of up to say, 8 pages in an mTHP in parallel in hardware, with the Intel In-Memory Analytics Accelerator (Intel IAA). Also, addressed some of the RFC comments from the discussion in [1]. Co-developed-by: Ryan Roberts Signed-off-by: Signed-off-by: Kanchana P Sridhar Reported-by: kernel test robot --- mm/zswap.c | 234 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 172 insertions(+), 62 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 6434e76a4ea3..9862a4cf0651 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -886,7 +886,7 @@ static int zswap_cpu_comp_dead(unsigned int cpu, struct= hlist_node *node) return 0; } =20 -static bool zswap_compress(struct folio *folio, struct zswap_entry *entry) +static bool zswap_compress(struct page *page, struct zswap_entry *entry) { struct crypto_acomp_ctx *acomp_ctx; struct scatterlist input, output; @@ -904,7 +904,7 @@ static bool zswap_compress(struct folio *folio, struct = zswap_entry *entry) =20 dst =3D acomp_ctx->buffer; sg_init_table(&input, 1); - sg_set_folio(&input, folio, PAGE_SIZE, 0); + sg_set_page(&input, page, PAGE_SIZE, 0); =20 /* * We need PAGE_SIZE * 2 here since there maybe over-compression case, @@ -1455,36 +1455,83 @@ static void zswap_fill_folio(struct folio *folio, u= nsigned long value) /********************************* * main API **********************************/ -bool zswap_store(struct folio *folio) + +/* + * 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) { - swp_entry_t swp =3D folio->swap; - pgoff_t offset =3D swp_offset(swp); - struct xarray *tree =3D swap_zswap_tree(swp); - struct zswap_entry *entry, *old; - struct obj_cgroup *objcg =3D NULL; - struct mem_cgroup *memcg =3D NULL; - unsigned long value; + struct zswap_entry *old; + pgoff_t offset =3D swp_offset(entry->swpentry); =20 - VM_WARN_ON_ONCE(!folio_test_locked(folio)); - VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); + old =3D xa_store(tree, offset, entry, GFP_KERNEL); =20 - /* Large folios aren't supported */ - if (folio_test_large(folio)) + if (xa_is_err(old)) { + int err =3D xa_err(old); + + WARN_ONCE(err !=3D -ENOMEM, "unexpected xarray error: %d\n", err); + zswap_reject_alloc_fail++; return false; + } =20 - if (!zswap_enabled) - goto check_old; + /* + * 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); =20 - /* Check cgroup limits */ - objcg =3D get_obj_cgroup_from_folio(folio); - if (objcg && !obj_cgroup_may_zswap(objcg)) { - memcg =3D get_mem_cgroup_from_objcg(objcg); - if (shrink_memcg(memcg)) { - mem_cgroup_put(memcg); - goto reject; - } - mem_cgroup_put(memcg); + 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 the i-th 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 enabl= ed. + * 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 =3D 0; i < nr_pages; ++i) { + entry =3D xa_erase(tree, offset + i); + if (entry) + zswap_entry_free(entry); } +} + +/* + * Stores the page at specified "index" in a folio. + */ +static bool zswap_store_page(struct folio *folio, long index, + struct obj_cgroup *objcg, + struct zswap_pool *pool) +{ + swp_entry_t swp =3D folio->swap; + int type =3D swp_type(swp); + pgoff_t offset =3D swp_offset(swp) + index; + struct page *page =3D folio_page(folio, index); + struct xarray *tree =3D swap_zswap_tree(swp); + struct zswap_entry *entry; + unsigned long value; + + if (objcg) + obj_cgroup_get(objcg); =20 if (zswap_check_limits()) goto reject; @@ -1496,7 +1543,7 @@ bool zswap_store(struct folio *folio) goto reject; } =20 - if (zswap_is_folio_same_filled(folio, 0, &value)) { + if (zswap_is_folio_same_filled(folio, index, &value)) { entry->length =3D 0; entry->value =3D value; atomic_inc(&zswap_same_filled_pages); @@ -1504,43 +1551,21 @@ bool zswap_store(struct folio *folio) } =20 /* if entry is successfully added, it keeps the reference */ - entry->pool =3D zswap_pool_current_get(); - if (!entry->pool) + if (!zswap_pool_get(pool)) goto freepage; =20 - if (objcg) { - memcg =3D get_mem_cgroup_from_objcg(objcg); - if (memcg_list_lru_alloc(memcg, &zswap_list_lru, GFP_KERNEL)) { - mem_cgroup_put(memcg); - goto put_pool; - } - mem_cgroup_put(memcg); - } + entry->pool =3D pool; =20 - if (!zswap_compress(folio, entry)) + if (!zswap_compress(page, entry)) goto put_pool; =20 store_entry: - entry->swpentry =3D swp; + entry->swpentry =3D swp_entry(type, offset); entry->objcg =3D objcg; entry->referenced =3D true; =20 - old =3D xa_store(tree, offset, entry, GFP_KERNEL); - if (xa_is_err(old)) { - int err =3D xa_err(old); - - WARN_ONCE(err !=3D -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); =20 if (objcg) { obj_cgroup_charge_zswap(objcg, entry->length); @@ -1574,7 +1599,7 @@ bool zswap_store(struct folio *folio) else { zpool_free(entry->pool->zpool, entry->handle); put_pool: - zswap_pool_put(entry->pool); + zswap_pool_put(pool); } freepage: zswap_entry_cache_free(entry); @@ -1582,16 +1607,101 @@ bool zswap_store(struct folio *folio) obj_cgroup_put(objcg); if (zswap_pool_reached_full) queue_work(shrink_wq, &zswap_shrink_work); -check_old: + + return false; +} + +/* + * Modified to store mTHP folios. Each page in the mTHP will be compressed + * and stored sequentially. + */ +bool zswap_store(struct folio *folio) +{ + long nr_pages =3D folio_nr_pages(folio); + swp_entry_t swp =3D folio->swap; + pgoff_t offset =3D swp_offset(swp); + struct xarray *tree =3D swap_zswap_tree(swp); + struct obj_cgroup *objcg =3D NULL; + struct mem_cgroup *memcg =3D NULL; + struct zswap_pool *pool; + bool ret =3D false; + long index; + + VM_WARN_ON_ONCE(!folio_test_locked(folio)); + VM_WARN_ON_ONCE(!folio_test_swapcache(folio)); + + if (!zswap_enabled) + goto reject; + /* - * If the zswap store fails or zswap is disabled, we must invalidate the - * possibly stale entry which was previously stored at this offset. - * Otherwise, writeback could overwrite the new data in the swapfile. + * Check cgroup limits: + * + * The cgroup zswap limit check is done once at the beginning of an + * mTHP store, and not within zswap_store_page() for each page + * in the mTHP. We do however check the zswap pool limits at the + * start of zswap_store_page(). What this means is, the cgroup + * could go over the limits by at most (HPAGE_PMD_NR - 1) pages. + * However, the per-store-page zswap pool limits check should + * hopefully trigger the cgroup aware and zswap LRU aware global + * reclaim implemented in the shrinker. If this assumption holds, + * the cgroup exceeding the zswap limits could potentially be + * resolved before the next zswap_store, and if it is not, the next + * zswap_store would fail the cgroup zswap limit check at the start. */ - entry =3D xa_erase(tree, offset); - if (entry) - zswap_entry_free(entry); - return false; + objcg =3D get_obj_cgroup_from_folio(folio); + if (objcg && !obj_cgroup_may_zswap(objcg)) { + memcg =3D get_mem_cgroup_from_objcg(objcg); + if (shrink_memcg(memcg)) { + mem_cgroup_put(memcg); + goto put_objcg; + } + mem_cgroup_put(memcg); + } + + if (zswap_check_limits()) + goto put_objcg; + + pool =3D zswap_pool_current_get(); + if (!pool) + goto put_objcg; + + if (objcg) { + memcg =3D get_mem_cgroup_from_objcg(objcg); + if (memcg_list_lru_alloc(memcg, &zswap_list_lru, GFP_KERNEL)) { + mem_cgroup_put(memcg); + goto put_pool; + } + mem_cgroup_put(memcg); + } + + /* + * Store each page of the folio as a separate entry. If we fail to store + * a page, unwind by removing all the previous pages we stored. + */ + for (index =3D 0; index < nr_pages; ++index) { + if (!zswap_store_page(folio, index, objcg, pool)) + goto put_pool; + } + + ret =3D true; + +put_pool: + zswap_pool_put(pool); +put_objcg: + obj_cgroup_put(objcg); + if (zswap_pool_reached_full) + queue_work(shrink_wq, &zswap_shrink_work); +reject: + /* + * 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. + */ + if (!ret) + zswap_delete_stored_offsets(tree, offset, nr_pages); + + return ret; } =20 bool zswap_load(struct folio *folio) --=20 2.27.0 From nobody Mon Feb 9 03:47:17 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 88812241E7 for ; Mon, 19 Aug 2024 02:16:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724033787; cv=none; b=s4En2qyu2NWhW9i50GxtghXGG+vTPRCFcUUW327tG6KDbaGMY7GwEVHphOuXlWrJ+rQilCdg7I7dCpPeRRC2+fcdQzSYRVcJgVDLcrRqajLqN26RFAWmwAVo/bxpBrzvZ5C/EF7mI110KJ0eGlmh7kyjWFUPSS8CiiJoZKfKmcA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724033787; c=relaxed/simple; bh=pCqID+ibJQzADFduLDZJx6IU2iRBnr8hLVZlnSUbIa4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=GChpgQVq0TgP4mu76EH0VFBwIzOMvs37cjpVpD6Q2WXuKB26l7D80jMTNOylGrJkwpx1gAbAv3HseiWW/gaqqqTzRtVCEWyaV8B1EhDWQSqDBweVN3/3czBnySowPJq1BWwZB1o1Gsd539hqHgn7jfkHX+nXdhqnoWRMl9jY+0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=Ji42KxEE; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Ji42KxEE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724033786; x=1755569786; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=pCqID+ibJQzADFduLDZJx6IU2iRBnr8hLVZlnSUbIa4=; b=Ji42KxEE0LBNRE0J2WS2u0DJbJ4HEKB8LheSYEUITu6qXq/hsW94xTan tvc/BoxtPxue+xiKADQGGv1JUvPXBSe983SPDkhlayfvrNpSwl4mLFvkI djYOlLbSkMGWU2dgIBw97FDAg3HrPJe13TRXMtmvLGiz0vakRf+SgObHv pPHtPZG0DSC90Y6v0/O4ayldrSBfc35sIEDmZ/h+RcV835+tfbH+wT0dL kARMddRnV7JBsOU6iPlPBU79nbC7ausOLKgg7zipOqG1Sl5Nzx7VBe+4K b+LvPbUfzew/1Wo/o03Yul9dOKOcnFCOvAuiqxpPMP48PSIG3+VPqB5sp A==; X-CSE-ConnectionGUID: cDtzaNE6RS2iywyUnKjnwg== X-CSE-MsgGUID: TWWlKg/3RY+5aQiWcHhQpw== X-IronPort-AV: E=McAfee;i="6700,10204,11168"; a="44782972" X-IronPort-AV: E=Sophos;i="6.10,158,1719903600"; d="scan'208";a="44782972" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2024 19:16:24 -0700 X-CSE-ConnectionGUID: rdbxAd1TSN20Iehf1fk1wQ== X-CSE-MsgGUID: 2WIPODmDRpS0GbvMDmwXxQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,158,1719903600"; d="scan'208";a="64610277" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by fmviesa005.fm.intel.com with ESMTP; 18 Aug 2024 19:16:22 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, 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 v4 3/4] mm: Add MTHP_STAT_ZSWPOUT to sysfs per-order mthp stats. Date: Sun, 18 Aug 2024 19:16:20 -0700 Message-Id: <20240819021621.29125-4-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240819021621.29125-1-kanchana.p.sridhar@intel.com> References: <20240819021621.29125-1-kanchana.p.sridhar@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new MTHP_STAT_ZSWPOUT entry to the sysfs mTHP stats so that per-order mTHP folio ZSWAP stores can be accounted. Signed-off-by: Kanchana P Sridhar --- include/linux/huge_mm.h | 1 + mm/huge_memory.c | 3 +++ 2 files changed, 4 insertions(+) diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 4c32058cacfe..19d3e26eb276 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -118,6 +118,7 @@ enum mthp_stat_item { MTHP_STAT_ANON_FAULT_ALLOC, MTHP_STAT_ANON_FAULT_FALLBACK, MTHP_STAT_ANON_FAULT_FALLBACK_CHARGE, + MTHP_STAT_ZSWPOUT, MTHP_STAT_SWPOUT, MTHP_STAT_SWPOUT_FALLBACK, MTHP_STAT_SHMEM_ALLOC, diff --git a/mm/huge_memory.c b/mm/huge_memory.c index cf8e34f62976..73b8ad255d8b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -587,6 +587,7 @@ static struct kobj_attribute _name##_attr =3D __ATTR_RO= (_name) DEFINE_MTHP_STAT_ATTR(anon_fault_alloc, MTHP_STAT_ANON_FAULT_ALLOC); DEFINE_MTHP_STAT_ATTR(anon_fault_fallback, MTHP_STAT_ANON_FAULT_FALLBACK); DEFINE_MTHP_STAT_ATTR(anon_fault_fallback_charge, MTHP_STAT_ANON_FAULT_FAL= LBACK_CHARGE); +DEFINE_MTHP_STAT_ATTR(zswpout, MTHP_STAT_ZSWPOUT); DEFINE_MTHP_STAT_ATTR(swpout, MTHP_STAT_SWPOUT); DEFINE_MTHP_STAT_ATTR(swpout_fallback, MTHP_STAT_SWPOUT_FALLBACK); #ifdef CONFIG_SHMEM @@ -603,6 +604,7 @@ static struct attribute *anon_stats_attrs[] =3D { &anon_fault_fallback_attr.attr, &anon_fault_fallback_charge_attr.attr, #ifndef CONFIG_SHMEM + &zswpout_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endif @@ -633,6 +635,7 @@ static struct attribute_group file_stats_attr_grp =3D { =20 static struct attribute *any_stats_attrs[] =3D { #ifdef CONFIG_SHMEM + &zswpout_attr.attr, &swpout_attr.attr, &swpout_fallback_attr.attr, #endif --=20 2.27.0 From nobody Mon Feb 9 03:47:17 2026 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) (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 D966E26AD4 for ; Mon, 19 Aug 2024 02:16:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724033787; cv=none; b=fRjEePzycL3qTkJB28teVdxfEELCoZ62UBNZbXGegC0qMbtBk1PBNU6tssgwxQj7SrSB+WXyrk8t5POC11gAZu89pD/eY9r1fG8Bb/8Vf8N0q+Tv1flFW8qTIIuaHMYWNR5nenDDTkweOq5R8VR763+MaY1R2D/hOewe8i4Qfbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724033787; c=relaxed/simple; bh=e4dJeIMpZ7zVkmYhUNqheK2yMfNN01J1RMy+uwUX+JE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aFTcj5oY9LB8W6hOTh4puEjG9RTsMl01MFQUOK+WjgQwB68gkHeKfICAYK+AvYV5pjNYiMRz/3j86oj1F5D8jDn0+DCkhLTlAv4i8Om5Olu73wkgTZ3bpTJAOAvDpPf7W1TaITut6fSPIGs830MzQmLgiTRfcAXOV3JQGFKUBfU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lIO7JEjn; arc=none smtp.client-ip=198.175.65.9 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lIO7JEjn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1724033786; x=1755569786; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e4dJeIMpZ7zVkmYhUNqheK2yMfNN01J1RMy+uwUX+JE=; b=lIO7JEjnm750k6c7GH3uaWmUSTu2ei/6EquiJkp/Lyd1SksVFrApQksd 8q35E3JbcCyGkRuSGBzSC4fIJyxY8Z9B8YQxKCPJlUnC/ctkLn44i+HOP X9u9Q8jHzn1JqzpDOxICx+Oklc6A/NufVet1tzurGXqswlGCYEb9cY3gB 8A507nfT4PeMIt89XGW1agY2uJ80YNLJtxAmSyNJYhxSAhBwipemHBe85 pBTOVNAiL3DGf9uwJ7/cMKDC/fqs/bJn/Bxbo49h+BPej+vLfWaFI86o/ R38cqHSX4eK3DVp1eGXJF+BZAi9a/3v1l9XZfQPkJkpp5E6JJK2H4WNo+ g==; X-CSE-ConnectionGUID: ZZ5ckDFzRReN1XRpBU7yWA== X-CSE-MsgGUID: 5nDFCSFJSFiLCOzWIDOcDQ== X-IronPort-AV: E=McAfee;i="6700,10204,11168"; a="44782979" X-IronPort-AV: E=Sophos;i="6.10,158,1719903600"; d="scan'208";a="44782979" Received: from fmviesa005.fm.intel.com ([10.60.135.145]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Aug 2024 19:16:24 -0700 X-CSE-ConnectionGUID: Q7fqm6iGRiq5vh7mK/HcfA== X-CSE-MsgGUID: BTCZqOyyTrukqBfPvkuwiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,158,1719903600"; d="scan'208";a="64610280" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by fmviesa005.fm.intel.com with ESMTP; 18 Aug 2024 19:16:23 -0700 From: Kanchana P Sridhar To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, hannes@cmpxchg.org, yosryahmed@google.com, nphamcs@gmail.com, 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 v4 4/4] mm: swap: Count successful mTHP ZSWAP stores in sysfs mTHP stats. Date: Sun, 18 Aug 2024 19:16:21 -0700 Message-Id: <20240819021621.29125-5-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20240819021621.29125-1-kanchana.p.sridhar@intel.com> References: <20240819021621.29125-1-kanchana.p.sridhar@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If zswap_store() successfully swaps out an mTHP, it will be counted under the per-order sysfs "zswpout" stats: /sys/kernel/mm/transparent_hugepage/hugepages-*kB/stats/zswpout Other block dev/fs mTHP swap-out events will be counted under the existing sysfs "swpout" stats: /sys/kernel/mm/transparent_hugepage/hugepages-*kB/stats/swpout Based on changes made in commit 61e751c01466ffef5dc72cb64349454a691c6bfe ("mm: cleanup count_mthp_stat() definition"), this patch also moves the call to count_mthp_stat() in count_swpout_vm_event() to be outside the "ifdef CONFIG_TRANSPARENT_HUGEPAGE". Signed-off-by: Kanchana P Sridhar --- mm/page_io.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/page_io.c b/mm/page_io.c index a00e2f615118..ac5954149eb9 100644 --- a/mm/page_io.c +++ b/mm/page_io.c @@ -196,6 +196,7 @@ int swap_writepage(struct page *page, struct writeback_= control *wbc) return ret; } if (zswap_store(folio)) { + count_mthp_stat(folio_order(folio), MTHP_STAT_ZSWPOUT); folio_unlock(folio); return 0; } @@ -215,8 +216,8 @@ static inline void count_swpout_vm_event(struct folio *= folio) count_memcg_folio_events(folio, THP_SWPOUT, 1); count_vm_event(THP_SWPOUT); } - count_mthp_stat(folio_order(folio), MTHP_STAT_SWPOUT); #endif + count_mthp_stat(folio_order(folio), MTHP_STAT_SWPOUT); count_vm_events(PSWPOUT, folio_nr_pages(folio)); } =20 --=20 2.27.0