From patchwork Sun Nov 3 03:21:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kanchana P Sridhar X-Patchwork-Id: 13860295 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 10133E6780A for ; Sun, 3 Nov 2024 03:21:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2126B6B0098; Sat, 2 Nov 2024 23:21:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A2046B009B; Sat, 2 Nov 2024 23:21:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F067D6B009C; Sat, 2 Nov 2024 23:21:25 -0400 (EDT) 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 AE5BD6B0095 for ; Sat, 2 Nov 2024 23:21:25 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 739AB80C4A for ; Sun, 3 Nov 2024 03:21:25 +0000 (UTC) X-FDA: 82743331692.09.1826F4A Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) by imf18.hostedemail.com (Postfix) with ESMTP id EE3BB1C0002 for ; Sun, 3 Nov 2024 03:21:09 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QmOm2ZFk; spf=pass (imf18.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.14 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=1730604036; 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=rKUHjlpACeorWIyRjTReOgDpl9w8z8tHSSWJcOBHH8k=; b=WD7W3PAgQ6lIw0FTRFARSKoxdLlMU8ThPb8gTu5ZH40WBTaCaysXQNAkjBesCItK94+834 Bn7JpOGkVWZ0Mf5PBf9hfeOIzgCJLSzne1HwLD98JAjz3pZaBMhMtDFPG0wjZFstnQCNJA fjDqeuRdbCrM6yTcIR+6jaGi/Y9xFno= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730604036; a=rsa-sha256; cv=none; b=PZz8FaQyruBl13x9YKf8zKbH9Ad5aS0qUARYV5B10eWTdw8SfscI6fTgMNGsBEY28JEj2I tLBS7So1hJaQ653gWJwIuGwSwlBpmPqdz0wHQEZVwz5tq2CzxAPfY2wPAzobEAGAaWu8Q5 3T+iUnEJ174s65DjMxEOpMb71zKfoBQ= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=QmOm2ZFk; spf=pass (imf18.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.14 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com; dmarc=pass (policy=none) header.from=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730604083; x=1762140083; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kNwqiK541Yzu6mxMdWRHQdBvyKOFfv8Kurpx7eomG3Q=; b=QmOm2ZFkOHgBctSV2XaXNywDQF+sbR7RUYGTAYfReanGt7mZJUFDWm/G sssWRKJmdnDf95zSAl0y+UBmvEnH2/l7XyNJDf57otml+rF9kf1ynwvFB Cn9MQAPTvYO37CLm6V/k0AUbT76xlmyKGCGqP2N9x0zY7mZSIFDxTkYi8 nkhPs8ILlSha/I66CTQfQXHjeduC1KfHfWE1pmnQvftB4J7cxUPs0H/hP 0NrcQSyAmbQAPMHF9ptQxvfJU+/7+iNvb7Pa/8gMGBXQt3U1a1T4K+cut dKSRyOqGUAF1x4E4xZ35TDfURGCI2Rl6jsYNgNzFph0gKK/Rs00Kj7kPh Q==; X-CSE-ConnectionGUID: 4z63fgDUSIOCG4HFrm6rKw== X-CSE-MsgGUID: pwtQKZupTw2zqHXGpHc+fQ== X-IronPort-AV: E=McAfee;i="6700,10204,11244"; a="30548339" X-IronPort-AV: E=Sophos;i="6.11,254,1725346800"; d="scan'208";a="30548339" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Nov 2024 20:21:14 -0700 X-CSE-ConnectionGUID: 9xQQE4tEQ9OqArTginJneA== X-CSE-MsgGUID: AHlf4kvqRIWS++X0cLkzHA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,254,1725346800"; d="scan'208";a="83451899" Received: from unknown (HELO JF5300-B11A338T.jf.intel.com) ([10.242.51.115]) by orviesa006.jf.intel.com with ESMTP; 02 Nov 2024 20:21:14 -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, 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 v2 10/13] mm: zswap: Add a per-cpu "acomp_batch_ctx" to struct zswap_pool. Date: Sat, 2 Nov 2024 20:21:08 -0700 Message-Id: <20241103032111.333282-11-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20241103032111.333282-1-kanchana.p.sridhar@intel.com> References: <20241103032111.333282-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Stat-Signature: ta3ptpw1pg45qyim7cexisdc5jg5hja7 X-Rspam-User: X-Rspamd-Queue-Id: EE3BB1C0002 X-Rspamd-Server: rspam02 X-HE-Tag: 1730604069-351312 X-HE-Meta: U2FsdGVkX18ZNUorjzFDmDXYw2hUNh4ItR/SFhjnXPX7mkPks0uqksU2DmjA7pDXei+gx9Owbj31yZ6qIOJVKxb/CEIFlTMnVrEh+FbwInWtwCemLp/S95uFUfeWMKn2vBYFW3r34pEbARFSA9dq+wTaXBDYiXGAuxHQ3v/zYNbdCqaH826jlJ0wmYAt3SJScx2XFTfsnvq1QwJlH9j8M+16jxpJ+GKpb+wQL7SOoBOA2q+jgdqerD28OMQZbSE7q9aDrH55Wfbfihll4VGp9zfWP7se3nGSvwmfg65LZKFzBbxRB8Ee94VGhwapIWAJnbATi31j62bPl0XSggQcVkGVyntLx7JzniYMTyxEE70XpKV3uISanWdFS4tfLmUb/yXC1lld270+VCal0AZHRPZgtHVOpKXbZVMC6HTrpQQPAyFQV4uDTH+7Q/8+pZ2eZtJtHAGsyfwvP7yIRnSjCbRSGQ22Lqy6IbBB1qO8npSfGYgBSnvbzQLa8g22fjguuoUdHKR8uV7RgI1G+YX1ZMfvgxO31QDpGF7XL1r0ZiOk/KoBdTTZFNNWA20Opy5GpqXOfBlFvTLDS6iwfAnxRBnHvA610zZ3WXUuY/COHZhl66iw7FvTi5SHIR9kZvF5YB/xddkp/NUGNX7NQplwT07p3qOj0Ao+jtqAWUqYYxeueLt/nBi2S1nSLMq0hUu1hYzXdNO9CPEE/Baxm5ucvAkyzBQDgS5lE9jFJbo5qmwGuTVF43FUi+liCtwl+2BSH5tHFCSZ8zOMEcyB34lyNqcaaASEInTpLEeC1OyN3HokRL6NDZZ47eN5EAh8gauXWLQxPJ1Th0Vk4lq6MlvKZLNoFNe5rUuUp28my1IgVvPOD5JGJYCsdmFLGnnpE4yEOhxEhIlLL1srQEkAS66aAU/N5m+mQnsIS+mcmZJX3/GOoIAZD9lwuhvp/1Hgub+PJclq7zLOiD9gU0kuMGe uQrOsW2J sFVKdZohKCGkXS5f/v1yqZ+bxED+9IN7T5d8jL66zNBY9Hc60wc+8Ipa6pPwHDNrB1zNYgyEkbyXWghmSm+o+0tl266wwpW+OTG1uKkkHvh2NhBVt0pOOM0gHXgHRMN+0r50BvUXtAEjDKG760HwhHpr4F+Lm7O7UZkBdzFP5LACCSjeVGtJssZz5gCbgbX/KPTa+6rIg2SaspVm/tzNr2KOCWp4g0Qowe8Zk93VhFYYtlacIPxqc7XE8PoCPO0k571Y9 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 f062c6dfcad4..3ad81ec0f262 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); @@ -924,6 +933,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); } @@ -933,6 +947,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);