From patchwork Wed Nov 6 19:21:03 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: 13865326 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 D8CEFD59F6D for ; Wed, 6 Nov 2024 19:21:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EB18B6B009D; Wed, 6 Nov 2024 14:21:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E5F686B009E; Wed, 6 Nov 2024 14:21:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA67E6B009F; Wed, 6 Nov 2024 14:21:20 -0500 (EST) 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 A7FC36B009D for ; Wed, 6 Nov 2024 14:21:20 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5B549C109F for ; Wed, 6 Nov 2024 19:21:20 +0000 (UTC) X-FDA: 82756637166.08.D82E9F7 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.11]) by imf23.hostedemail.com (Postfix) with ESMTP id 91572140017 for ; Wed, 6 Nov 2024 19:20:55 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=GRJ2qCys; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf23.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.11 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730920819; a=rsa-sha256; cv=none; b=iY7WUKRe8jWZkQ+Hky4wqhCjWXpSyDXE9PvEC1W0Ta+U9e6C8COH9t2gwd+AkuR8juNBVW Ekwb5cAM8dl39y36Skg1UFuY9O5LLm9MxY1p05hRk2ulUvjX3BRSidj97xY7ZhDXLfmXtG OIyL0ZugjsjcEOjZ2liXE9ymy45hd4o= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=GRJ2qCys; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf23.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 198.175.65.11 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=1730920819; 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=HmtlXH4iAJI0KGsE9A/FwBYg8OH5mCluZRrs/ikqQMM=; b=mFEYe9G/xAGJVpq60hb0Hj0AqS+V1kMpTulZg9a8iKmbhKJNL4zoIJ+m269kkc9+yu9PUH ItS3GjFvz5iQCOsqHoTA8ExpAikAs9USKp1TaDKeQfZcTlbVHGoHgJH0APPqzMBbZcTD8n s/NYp/afyhSet5dlAlLG0uxcZmH1bUI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1730920879; x=1762456879; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SK7AuRma8nAYQQn2EcAOmsROSQ044juQI+TJ7g6xS7U=; b=GRJ2qCysNXOVMVjA7pCL/t53ha+vVbGrFnRJ21qfR71b1o4CrZRjfoBG /svYIX4aJbnd3P+N7b852HLU1HtejNwbADAqUf/BLwQwb3wMVb1sJwsSX Eg1cQlTeC01sUwFyAVy4xEKlU3OsP+pHK3BISg5ysgT9WJBZfLs8LfvO/ IwHV41lDcxewMjBClVfewDGvTPKi1U8pKxKYAvh20gKxbcFUyOveaXfiH cB1GPXDhpOMYf81ZzCbjEHq8fs/WYSFTw3iRVtjDm0JmrY3KYkb3z5rFy +9zTU/9iigNkwRupuXeFlZne9sN4nYCUNNCb3W0X1QJZriu+Gcl2T9Dka g==; X-CSE-ConnectionGUID: oqJOkQq+QpuKkehB8s4fFQ== X-CSE-MsgGUID: a0K+V9VWRqG2kRihP4gnbw== X-IronPort-AV: E=McAfee;i="6700,10204,11222"; a="41292061" X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="41292061" 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:14 -0800 X-CSE-ConnectionGUID: ClMLUI8HQiKSghkT7rDUWg== X-CSE-MsgGUID: EuVmJ52UQjmumLK5h0SBhQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,263,1725346800"; d="scan'208";a="88695416" 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:13 -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 11/13] mm: zswap: Allocate acomp_batch_ctx resources for a given zswap_pool. Date: Wed, 6 Nov 2024 11:21:03 -0800 Message-Id: <20241106192105.6731-12-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-Rspam-User: X-Rspamd-Queue-Id: 91572140017 X-Rspamd-Server: rspam11 X-Stat-Signature: ot7uc5mum1hyx96a75ctsjooadgu3hzt X-HE-Tag: 1730920855-207991 X-HE-Meta: U2FsdGVkX1/s7qY12IZOeJGyyuJbAixmZVZlFSuIeHxNtb3HdXAulYfjzl+SaUCUl01xdtwfqYfUwz55sg6khpfMh4UFXTrYIbx3X7EsAG2tNaZat2xfWsEwCey82euTp5wjddZleAvewkOwKNV580N28YpgvFhI7nlTOUK1d0rLMnkBT/8BTkFW+iRZD00BbMGQkaOc6pZYHqV4lcRbpgfjanp5xGOKAYhreRsPd45tdQ38BAkRZ84/IpHQbWRupM0BuYFuBXCL5++KTfOX9zQpK66ya7ygSCz3Bo60HxcT7TzPnbjx7ZL7B5icl+e0FNeOnXKiWXL9vA8a3usGbq71b9qJizsUrHCvCjdqGh+ij1Iqas+V2brc3/mfRq3IozzLr4d7UTXc6BLmU5u+7cZ420Pqi7Euj2ogIWlC1NPlFP63yFL+Q5yyMjgUNbEmnk+d3VFv1Krpot4um/YnQR4Jy/IN/K0MSA2ok2AYHTPQxPs2T7NgAkKCI/zur1ZrVVB4oZzWz7Ex3MazQssrmRBlamZKrQqWVcTFfq3BZ7ydDnLSm8Vm6d6xjudPMsFTa8K8kGAokjv8JGqcodJe+jJU06kyqTuNZo2WZxH05LehhZgysNO7vYWoC72nhM2RtHMFX22j+go+dJPoO5aXv/+dlge1j1MzWCS3Me0AcA8CI/ThCZZg0Wn89HKUu02Bq+1H8ZOvOvzOo0X5E2OddXOf+ThlG2VHUlJGdtKTe8dHkLTMZsm3Kao7mqjGNOePI6CfC/KfG0svJ7ho4Pi/so8yc3U0upkb+wFSXRA0FkKPCkuZBwMAvbcfXGCR1fed/yfR54rAAvgA0a1VRpGEC/b8fbmjsZULVfdDe6hkxhvLTqNxnmCTal7ZhV+UTcaEBV1UXmjvJp3Ml/2nitxysUfnj1RzlMAw1wPsiKiuCSc+9eLKLZdjBUodTY3GYEedtUA+0PJJ4vArM5+l7lx FXHkCOIp y0td3/tH/+8hBERYhzlsdH16bUYicZMYqfCeC877ykP9DNkpntxACojo2qY6CzGAZ1Qul9yiZ8ngk6XEjhqGpfWLRq/D14o8HysxWmLaJhXDH8tIEDxASlBkr7fGE4M/mP9/IceN7Fo55dT+Qksh8W0j5fDXXz4VT3QPZO13H4Zl1qthuoAqLB1NojH8BnzmxifUjOLcoDGZf7oiYzEaQVTx5Pbn+piFyEdSpvBrwC18QgUsEw7gg8OfPKWgcYEh+nj9p 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: If the zswap_pool is associated with an acomp_alg/crypto_acomp that has registered batch_compress() and batch_decompress() API, we can allocate the necessary batching resources for the pool's acomp_batch_ctx. This patch makes the above determination on incurring the per-cpu memory footprint cost for batching, and if so, goes ahead and allocates SWAP_CRYPTO_BATCH_SIZE (i.e. 8) acomp_reqs/buffers for the pool->acomp_batch_ctx on that specific cpu. It also "remembers" the pool's batching readiness as a result of the above, through a new enum batch_comp_status can_batch_comp; member added to struct zswap_pool, for fast retrieval during zswap_store(). This allows us a way to only incur the memory footprint cost of the pool->acomp_batch_ctx resources for a given cpu on which zswap_store() needs to process a large folio. Suggested-by: Yosry Ahmed Suggested-by: Ying Huang Signed-off-by: Kanchana P Sridhar --- include/linux/zswap.h | 7 ++++++ mm/zswap.c | 52 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/linux/zswap.h b/include/linux/zswap.h index d961ead91bf1..9ad27ab3d222 100644 --- a/include/linux/zswap.h +++ b/include/linux/zswap.h @@ -7,6 +7,13 @@ struct lruvec; +/* + * For IAA compression batching: + * Maximum number of IAA acomp compress requests that will be processed + * in a batch: in parallel, if iaa_crypto async/no irq mode is enabled + * (the default); else sequentially, if iaa_crypto sync mode is in effect. + */ +#define SWAP_CRYPTO_BATCH_SIZE 8UL extern atomic_long_t zswap_stored_pages; #ifdef CONFIG_ZSWAP diff --git a/mm/zswap.c b/mm/zswap.c index 80a928cf0f7e..2af736e38213 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -151,6 +151,12 @@ struct crypto_acomp_ctx { bool is_sleepable; }; +enum batch_comp_status { + UNINIT_BATCH_COMP = -1, + CANNOT_BATCH_COMP = 0, + BATCH_COMP_ENABLED = 1, +}; + /* * The lock ordering is zswap_tree.lock -> zswap_pool.lru_lock. * The only case where lru_lock is not acquired while holding tree.lock is @@ -159,6 +165,7 @@ struct crypto_acomp_ctx { */ struct zswap_pool { struct zpool *zpool; + enum batch_comp_status can_batch_comp; struct crypto_acomp_ctx __percpu *acomp_ctx; struct crypto_acomp_ctx __percpu *acomp_batch_ctx; struct percpu_ref ref; @@ -310,6 +317,7 @@ static struct zswap_pool *zswap_pool_create(char *type, char *compressor) goto ref_fail; INIT_LIST_HEAD(&pool->list); + pool->can_batch_comp = UNINIT_BATCH_COMP; zswap_pool_debug("created", pool); return pool; @@ -695,6 +703,39 @@ static int zswap_enabled_param_set(const char *val, return ret; } +/* Called only if sysctl vm.compress-batching is set to "1". */ +static __always_inline bool zswap_pool_can_batch(struct zswap_pool *pool) +{ + struct crypto_acomp_ctx *acomp_ctx; + + if ((pool->can_batch_comp == BATCH_COMP_ENABLED) && + !IS_ERR_OR_NULL((acomp_ctx = raw_cpu_ptr(pool->acomp_batch_ctx))) && + (acomp_ctx->nr_reqs == SWAP_CRYPTO_BATCH_SIZE)) + return true; + + if (pool->can_batch_comp == CANNOT_BATCH_COMP) + return false; + + if ((pool->can_batch_comp == UNINIT_BATCH_COMP) && pool->acomp_batch_ctx) { + acomp_ctx = raw_cpu_ptr(pool->acomp_batch_ctx); + + if (!IS_ERR_OR_NULL(acomp_ctx)) { + if ((acomp_ctx->nr_reqs == SWAP_CRYPTO_BATCH_SIZE) || + (!acomp_ctx->nr_reqs && + !zswap_create_acomp_ctx(raw_smp_processor_id(), + acomp_ctx, + pool->tfm_name, + SWAP_CRYPTO_BATCH_SIZE))) { + pool->can_batch_comp = BATCH_COMP_ENABLED; + return true; + } + } + } + + pool->can_batch_comp = CANNOT_BATCH_COMP; + return false; +} + /********************************* * lru functions **********************************/ @@ -850,6 +891,17 @@ static int zswap_create_acomp_ctx(unsigned int cpu, acomp_ctx->acomp = acomp; acomp_ctx->is_sleepable = acomp_is_async(acomp); + /* + * Cannot create a batching ctx without the crypto acomp alg supporting + * batch_compress and batch_decompress API. + */ + if ((nr_reqs > 1) && (!acomp->batch_compress || !acomp->batch_decompress)) { + WARN_ONCE(1, "Cannot alloc acomp_ctx with %d reqs since crypto acomp %s\nhas not registered batch_compress() and/or batch_decompress()\n", + nr_reqs, tfm_name); + ret = -ENODEV; + goto buf_fail; + } + acomp_ctx->buffers = kmalloc_node(nr_reqs * sizeof(u8 *), GFP_KERNEL, cpu_to_node(cpu)); if (!acomp_ctx->buffers)