From patchwork Wed Nov 6 19:21:02 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: 13865325 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 BC222D59F6B for ; Wed, 6 Nov 2024 19:21:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 785FF6B009A; Wed, 6 Nov 2024 14:21:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7272A6B009D; Wed, 6 Nov 2024 14:21:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B4176B009A; Wed, 6 Nov 2024 14:21:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 23FF36B009B for ; Wed, 6 Nov 2024 14:21:19 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id CD350121CCE for ; Wed, 6 Nov 2024 19:21:18 +0000 (UTC) X-FDA: 82756637082.08.94D3376 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by imf12.hostedemail.com (Postfix) with ESMTP id D2EDC4001D for ; Wed, 6 Nov 2024 19:21:00 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=G6HeRrHw; spf=pass (imf12.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.11 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=1730920691; 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=F/Uy7y3NcF6okk5WlByY6be1T9l4fQSEE1YVDAB/Rzs=; b=wJYrOOi6GuAhZetTgpFpchZoFXYIXZw2c4DiIO8HHRGHaQey2iKDNxSGnFOJElKHvYdOi3 VaBOVTbXw1MQBuof8dKrB8fNZLk7jjRt8EOj3uU2kmX8iz6qoP525eg+arJBYKse2X8gN4 Mb0iCSc+gYGRoqbzIMVW8a/tsia5fyI= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=G6HeRrHw; spf=pass (imf12.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.11 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=1730920691; a=rsa-sha256; cv=none; b=2wO/dUhfm+6rm8yy0TAKFNbqdNhejACt6muDUh52gOZvc8zS6htkjUeNkmXouK/KIlARoW 0U6lqq9XS5VqiOlMKyfio4Z50IgnajPf8VSRFARaSqzWea9A4bVYpDgouOFk3oQ3Wvlo/O OsC3p8dv6iF+gnHv1PaIe+pG9an413Y= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730920877; x=1762456877; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FAnZNiRqeUl7Ne2U4+z2H8Xn+OqrQ2UYadwz7Qe0Ap8=; b=G6HeRrHw86TOtV0MWO30bZo3sTq5CIZ0idzSQPgldGUjD3BhBb/Tr5wW 5o4qwqH6yPJ+HHAcUGYIRb3TAzEmMGqdoZgR2LdvrwYQZf/cWHcZst8MF hGl2URfpw5H4XjrEAbz02JYEhApTu+2TdCHMeI49hYeLjd8lqXe8uzJao mVuGcawHMCvuVs3UUOFdKYzOU+8LBOpnYkFa3BMfdrspJHppQ5+p1x0B3 N0NORNKAoP13ADui7fkpSvPD85d95bXgMW8fAdGw5rSoLMdWFteWQvr0/ kAghaOga0rnaJ2Axd4DD8mr4jnsmK573TRvN01qU3MrmyAONjCDGWdOUi g==; X-CSE-ConnectionGUID: hQLCDQrBQiOyInhVRwJl6w== X-CSE-MsgGUID: KVjK8+thTZSdhis+kJekag== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="41292049" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="41292049" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Nov 2024 11:21:13 -0800 X-CSE-ConnectionGUID: 6oXbOKZDRWiqdJfoYia+Yg== X-CSE-MsgGUID: 7yNp1XuCTqGZv0eIhDj5ZQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,263,1725346800"; d="scan'208";a="88695410" Received: from unknown (HELO JF5300-B11A338T.jf.intel.com) ([10.242.51.115]) by fmviesa003.fm.intel.com with ESMTP; 06 Nov 2024 11:21:12 -0800 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, ryan.roberts@arm.com, ying.huang@intel.com, 21cnbao@gmail.com, akpm@linux-foundation.org, linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au, davem@davemloft.net, clabbe@baylibre.com, ardb@kernel.org, ebiggers@google.com, surenb@google.com, kristen.c.accardi@intel.com, zanussi@kernel.org Cc: wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [PATCH v3 10/13] mm: zswap: Add a per-cpu "acomp_batch_ctx" to struct zswap_pool. Date: Wed, 6 Nov 2024 11:21:02 -0800 Message-Id: <20241106192105.6731-11-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20241106192105.6731-1-kanchana.p.sridhar@intel.com> References: <20241106192105.6731-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D2EDC4001D X-Stat-Signature: 6qsc49d39uh6yn97w7eqp47axrfkukpo X-Rspam-User: X-HE-Tag: 1730920860-367380 X-HE-Meta: U2FsdGVkX18ipfXYjNCNlf1q4rYxTkhFH064NdbioVaJRch9sRzb5wm2dsqPLIUlt5AuTu/dZ/KRbSNJ7wfna9DeoNo9UIfTLd+mv+RNSolj6QzNq/qzK2sw6bVDkoU9p5YvBqYsLhBlOhgpjVEzOvmUvt1fCXKJVwrQUp/HZttNaW5BgUuqYkWW8SKYJic6KzRs0SHVccD7TPQ4Jc5KEC97yh8fF4Uk2sYXBU5Btwl1dprH0QjCSGm5QbNswjxQ8vewzXpEE1T+uyeNg8QE9V9seOb3ywSokRLmtLIS0++KSyfI8sbtk1HUjvpnf2tbb1fn4jFSsBWUUJgDEQQecOZpT4sQCifj3yt2hRrTyrKenQb4WwAciAkmBqkA6uYT6o321SyNcbmE4280LiHGzpWG0Y1uyzZcQSH3ve8UZZ7mmVRuw7o8Ym7dWxndrjdP1c2HKGQYDhEsqvoKhmikgaZ5rA/o6oitTMwYUDfLOk+D5bio1j+nLv3o9aPNvNsLWYBHCg3h6oe9PpZ14QRkPHJC76zZk5dyu2spF9xYL52g837RGDf5gte5YQ7pmhOnsLKdwLFHOjjTN/Kfgi582RwZlejmKNb5Ofw0UCrWlTqH+ELOzmtiS4DMXxK7mN1cisOz79Ojreyp2QRdh6EwhY6H04diwU35Zzwz4yvm1AwcEtbb14Xpc0YNL7qJyxiKMnkuUOInOAFClba0yZE0hWAWmr2vnwqmdcaAi1c91Y/WgHKL221yUBxXrLvnfOVNt3h/29SlEMrbxkcLfTSRLQsUT4sXE0OaLFIxbXdGBY2L6nzD0fX1oKW8ah5Gr7VhNV1PwgKOv2vOyXdXAuRBefMhtw2wqMKn0UhFBrc/aQOKHpLJJLZcDlvILaKGVYS7UrKN0B9D5VZqeb/9QZHJMlb7nc8UOkjNMXsEqx5XEWYJyEOTBECiYu1JQLvuhespMOcv4C4yT83ny5Beyqb BCtHjzNB H1RVNpML9hWKFrVsE+UsBtFtPw29Ekpno94sR21qpev7ltRTgIjAK1smFYx7x8OJsVMM8DPRnv9aTmWYPZ8Pqn6b0SFH+SwhXiTY9UwJn2vk1QyD1WfEgKpBd8Iy2z2abPiMgf1DCPsuebzBXR7PYtBNQHtAR/JR+1sReyrQ1DhBr1i0vzxuMUsVGhFQSHKO8TlFf8udgFZtGQ9HVztodzIb+T3Cza638Iqelk16rE7wSr3XogVuQZABny8tL61NZryaS 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: This patch adds a separate per-cpu batching acomp context "acomp_batch_ctx" to the zswap_pool. The per-cpu acomp_batch_ctx pointer is allocated at pool creation time, but no per-cpu resources are allocated for it. The idea is to not incur the memory footprint cost of multiple acomp_reqs and buffers in the existing "acomp_ctx" for cases where compress batching is not possible; for instance, with software compressor algorithms, on systems without IAA, on systems with IAA that want to run the existing non-batching implementation of zswap_store() of large folios. By creating a separate acomp_batch_ctx, we have the ability to allocate additional memory per-cpu only if the zswap compressor supports batching, and if the user wants to enable the use of compress batching in zswap_store() to improve swapout performance of large folios. Suggested-by: Yosry Ahmed Signed-off-by: Kanchana P Sridhar --- mm/zswap.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/mm/zswap.c b/mm/zswap.c index 02e031122fdf..80a928cf0f7e 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -160,6 +160,7 @@ struct crypto_acomp_ctx { struct zswap_pool { struct zpool *zpool; struct crypto_acomp_ctx __percpu *acomp_ctx; + struct crypto_acomp_ctx __percpu *acomp_batch_ctx; struct percpu_ref ref; struct list_head list; struct work_struct release_work; @@ -287,10 +288,14 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor) pool->acomp_ctx = alloc_percpu(*pool->acomp_ctx); if (!pool->acomp_ctx) { - pr_err("percpu alloc failed\n"); + pr_err("percpu acomp_ctx alloc failed\n"); goto error; } + pool->acomp_batch_ctx = alloc_percpu(*pool->acomp_batch_ctx); + if (!pool->acomp_batch_ctx) + pr_err("percpu acomp_batch_ctx alloc failed\n"); + ret = cpuhp_state_add_instance(CPUHP_MM_ZSWP_POOL_PREPARE, &pool->node); if (ret) @@ -312,6 +317,8 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor) ref_fail: cpuhp_state_remove_instance(CPUHP_MM_ZSWP_POOL_PREPARE, &pool->node); error: + if (pool->acomp_batch_ctx) + free_percpu(pool->acomp_batch_ctx); if (pool->acomp_ctx) free_percpu(pool->acomp_ctx); if (pool->zpool) @@ -368,6 +375,8 @@ static void zswap_pool_destroy(struct zswap_pool *pool) cpuhp_state_remove_instance(CPUHP_MM_ZSWP_POOL_PREPARE, &pool->node); free_percpu(pool->acomp_ctx); + if (pool->acomp_batch_ctx) + free_percpu(pool->acomp_batch_ctx); zpool_destroy_pool(pool->zpool); kfree(pool); @@ -930,6 +939,11 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) struct zswap_pool *pool = hlist_entry(node, struct zswap_pool, node); struct crypto_acomp_ctx *acomp_ctx; + if (pool->acomp_batch_ctx) { + acomp_ctx = per_cpu_ptr(pool->acomp_batch_ctx, cpu); + acomp_ctx->nr_reqs = 0; + } + acomp_ctx = per_cpu_ptr(pool->acomp_ctx, cpu); return zswap_create_acomp_ctx(cpu, acomp_ctx, pool->tfm_name, 1); } @@ -939,6 +953,12 @@ static int zswap_cpu_comp_dead(unsigned int cpu, struct hlist_node *node) struct zswap_pool *pool = hlist_entry(node, struct zswap_pool, node); struct crypto_acomp_ctx *acomp_ctx; + if (pool->acomp_batch_ctx) { + acomp_ctx = per_cpu_ptr(pool->acomp_batch_ctx, cpu); + if (!IS_ERR_OR_NULL(acomp_ctx) && (acomp_ctx->nr_reqs > 0)) + zswap_delete_acomp_ctx(acomp_ctx); + } + acomp_ctx = per_cpu_ptr(pool->acomp_ctx, cpu); zswap_delete_acomp_ctx(acomp_ctx);