From patchwork Fri Oct 18 06:40:52 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: 13841230 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 31AC8D3C54C for ; Fri, 18 Oct 2024 06:41:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6DA836B0089; Fri, 18 Oct 2024 02:41:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AD746B008A; Fri, 18 Oct 2024 02:41:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B2606B0093; Fri, 18 Oct 2024 02:41:09 -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 2EDF16B008A for ; Fri, 18 Oct 2024 02:41:09 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id B01B8811E5 for ; Fri, 18 Oct 2024 06:40:58 +0000 (UTC) X-FDA: 82685775732.14.D1687B2 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) by imf27.hostedemail.com (Postfix) with ESMTP id 0283A40005 for ; Fri, 18 Oct 2024 06:40:55 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Mb2gvK0R; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.15 as permitted sender) smtp.mailfrom=kanchana.p.sridhar@intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1729233548; a=rsa-sha256; cv=none; b=Q0JL4qtjNPRW4VQnZa3Z0vO4B0pRNNQeFB4D9wRD932gEHBE4NfmOoal3l9awvkgV50pHn wIofMXjsO0WIGlz2jmdNTFDlWNRmnc9YW6aH3XXge4xGbJ53wW7M+HyymZspCipPNonFc6 dQWVL87QdsLFTgNUhmV4wUztRpj2deE= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Mb2gvK0R; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf27.hostedemail.com: domain of kanchana.p.sridhar@intel.com designates 192.198.163.15 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=1729233548; 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=ojZCB3+cDbZulKZCRnF9Fc4yCfp7jxoYD47wlxBQ5kU=; b=6bzDlKDodjnMvtxFOQwoRcqPyIdIBA9m1X97O3LdXr/tOwWNHIxZOGoJh1Y+z/QXVt8Y8H pnypb1ElKC6tV1w/seIZWFT+G4Gdnxy0efdFTVK8pl89l/Tc7XRaKQcRnOcAKby0B4Q86X Py14bCzZGvxg/8n0aE8l2gJMDZTDCgM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729233667; x=1760769667; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gtInCloZyEBkd8uVBGAQIApykz7xeQMHHy5TXu53KaI=; b=Mb2gvK0RjAvMkQzGeLKoxIdurn4Db89JuGnLPssvKRCqJ4G/CHCdzNO0 n3/e8j+WgZ+wZ84KfOpvrh5kOjUc0Y41AN6a+cqOjebGWOhgvUxWwy3IT doAxYjqOHZqoXdTO7jW+yEFHhDyRS3T9uxdQzoA+rIzKxK5YUexH6S/xa 87GiE/daa3E1N5IZNjVyLB+Aop3M0M8BNu7nAWGivv4rEnfDKFtTKCIkb 2ED2ggUp5gt36rjjusvuKqfRRUTMybm9N28jRcjtidzMjt1iocbfxh4hQ squ3/9Jl/BICov7srpf8I/M9I+U1sdwRhDX4+fjaZ706I4cwPQXCM1G4k w==; X-CSE-ConnectionGUID: +WOUhZApQjy8hY9uDhw6eQ== X-CSE-MsgGUID: 9rR1rEHxQ2ymNtP4LlfqWw== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="28884827" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="28884827" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Oct 2024 23:41:02 -0700 X-CSE-ConnectionGUID: S5P7Z3aMRMezS5ESvvkKGg== X-CSE-MsgGUID: 95MDyyYsR9OFLjtcK6GVSw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="83607500" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by orviesa003.jf.intel.com with ESMTP; 17 Oct 2024 23:41:02 -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, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, mcgrof@kernel.org, kees@kernel.org, joel.granados@kernel.org, bfoster@redhat.com, willy@infradead.org, linux-fsdevel@vger.kernel.org Cc: wajdi.k.feghali@intel.com, vinodh.gopal@intel.com, kanchana.p.sridhar@intel.com Subject: [RFC PATCH v1 04/13] mm: zswap: zswap_compress()/decompress() can submit, then poll an acomp_req. Date: Thu, 17 Oct 2024 23:40:52 -0700 Message-Id: <20241018064101.336232-5-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20241018064101.336232-1-kanchana.p.sridhar@intel.com> References: <20241018064101.336232-1-kanchana.p.sridhar@intel.com> MIME-Version: 1.0 X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0283A40005 X-Stat-Signature: 8cr9h6uuntr3ruutah5zkuirdji6y8x1 X-Rspam-User: X-HE-Tag: 1729233655-48885 X-HE-Meta: U2FsdGVkX1+1+LpEm9Zq0T9bRmN3gvvEDhkmhUlNpOepcrDfJaL7FfIXaEOAlvO7XgYXDt9vV8YEiRvqqQ4VH/jPtjLrilsTWfLC1Qc8NiFgTDSWNHyt/HL81H2Y4UjGzUzkS34gQ7bFZc9uL4/2wOk8Gq6aq8T7CnoY7iaSqcw6pGPjn+Izf8KapxJ9tSZXj3b7deHfU0Qu5XfIWF6tO7zoxYBmCgyssd8WWv/bkidR4wtT3Y1QfpTtivE2XeGdQxKxVd/bV2ySuUq7Sw99CyyRvAedRGq1S/yrPT+P8RYvSLrCusdIaMrDpp8827T+de1a1DbaaJd0RblU1qt9ghQPKG6n3X8Ri+e4JBXjJ5k5JWXZg7BjsKKSPjVFm2YD9cxWe6kMFjmL+h2Dk5YaRqk87gU9WITYBOWWC5xffLfcZ15SzV0FBnhDnkZKT8uWHYQ2069NILxVKKG9nwo4Oy0ETebzpXTuTxJg0Ub+YcNmYLFftx8tKSlPr2+/3v6Gv8o7wk+m2KjzSQFMPFkf8QSABhDuXtFdO6YPagagthYp/ykr/IUutum+PQUf8zHuYqx5m3Uo83RZBMsd51qmz2StQkxuPIuNLXMLhpMjLUy2Yhqy6os9iXef1VjtnyWuBsn25+0savOhNbCJvhULO9hNgYzP3GzNmVsEDacEYgphWndErqUyiF2NAUREX0ScwJRnas85xr/2TeAFZcRa4DoWB+XY4QAQk+b7I2tbDOQuZ8dnsK1IoavH9eA80KCglpHjoha+3+waNJrbvVdpRdBSB0Nxmf3jS2bTvtHsvZFBe7J5qC/dfX3TUv9hJ+AHIT8PXHsDjMOwHkdXcH/3mMklKb7iL0aG2n7ILa3o+mb+1ei3y0NHBxWGhGwn72KmorT03NeoFDc1DYR4P70poPcFtPlmsqlkXLOV9VC34D9DH1QikZsLvoIQnpWcWGyXQvy64Ccenu22V/JgpZk n0T8bG5s c/uzZjBCos62RBRvN7lT6zjoxGjFbz7wirJEFV/dW+n/nCS5P/pyKkinabKOYYd2t25FJF3JijQtVIlZA6pFUdJoz8rqAtfDmnoJMqRB8QJGjwGGtgT0dHY2WUcBWH2QQhjAq+Hhq6o2/Wlw4XBLzSmTCzRaHcCF3S/LxL47Mm+BMtpXXm2yXlfOWVAg55C1KnclYEYIklM7vOx3EEzXBMnmokVkEpIrQPHh4F4T5yJH8du0= 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 crypto_acomp has a poll interface registered, zswap_compress() and zswap_decompress() will submit the acomp_req, and then poll() for a successful completion/error status in a busy-wait loop. This allows an asynchronous way to manage (potentially multiple) acomp_reqs without the use of interrupts, which is supported in the iaa_crypto driver. This enables us to implement batch submission of multiple compression/decompression jobs to the Intel IAA hardware accelerator, which will process them in parallel; followed by polling the batch's acomp_reqs for completion status. Signed-off-by: Kanchana P Sridhar --- mm/zswap.c | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index f6316b66fb23..948c9745ee57 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -910,18 +910,34 @@ static bool zswap_compress(struct page *page, struct zswap_entry *entry, acomp_request_set_params(acomp_ctx->req, &input, &output, PAGE_SIZE, dlen); /* - * it maybe looks a little bit silly that we send an asynchronous request, - * then wait for its completion synchronously. This makes the process look - * synchronous in fact. - * Theoretically, acomp supports users send multiple acomp requests in one - * acomp instance, then get those requests done simultaneously. but in this - * case, zswap actually does store and load page by page, there is no - * existing method to send the second page before the first page is done - * in one thread doing zwap. - * but in different threads running on different cpu, we have different - * acomp instance, so multiple threads can do (de)compression in parallel. + * If the crypto_acomp provides an asynchronous poll() interface, + * submit the descriptor and poll for a completion status. + * + * It maybe looks a little bit silly that we send an asynchronous + * request, then wait for its completion in a busy-wait poll loop, or, + * synchronously. This makes the process look synchronous in fact. + * Theoretically, acomp supports users send multiple acomp requests in + * one acomp instance, then get those requests done simultaneously. + * But in this case, zswap actually does store and load page by page, + * there is no existing method to send the second page before the + * first page is done in one thread doing zswap. + * But in different threads running on different cpu, we have different + * acomp instance, so multiple threads can do (de)compression in + * parallel. */ - comp_ret = crypto_wait_req(crypto_acomp_compress(acomp_ctx->req), &acomp_ctx->wait); + if (acomp_ctx->acomp->poll) { + comp_ret = crypto_acomp_compress(acomp_ctx->req); + if (comp_ret == -EINPROGRESS) { + do { + comp_ret = crypto_acomp_poll(acomp_ctx->req); + if (comp_ret && comp_ret != -EAGAIN) + break; + } while (comp_ret); + } + } else { + comp_ret = crypto_wait_req(crypto_acomp_compress(acomp_ctx->req), &acomp_ctx->wait); + } + dlen = acomp_ctx->req->dlen; if (comp_ret) goto unlock; @@ -959,6 +975,7 @@ static void zswap_decompress(struct zswap_entry *entry, struct folio *folio) struct scatterlist input, output; struct crypto_acomp_ctx *acomp_ctx; u8 *src; + int ret; acomp_ctx = raw_cpu_ptr(entry->pool->acomp_ctx); mutex_lock(&acomp_ctx->mutex); @@ -984,7 +1001,17 @@ static void zswap_decompress(struct zswap_entry *entry, struct folio *folio) sg_init_table(&output, 1); sg_set_folio(&output, folio, PAGE_SIZE, 0); acomp_request_set_params(acomp_ctx->req, &input, &output, entry->length, PAGE_SIZE); - BUG_ON(crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait)); + if (acomp_ctx->acomp->poll) { + ret = crypto_acomp_decompress(acomp_ctx->req); + if (ret == -EINPROGRESS) { + do { + ret = crypto_acomp_poll(acomp_ctx->req); + BUG_ON(ret && ret != -EAGAIN); + } while (ret); + } + } else { + BUG_ON(crypto_wait_req(crypto_acomp_decompress(acomp_ctx->req), &acomp_ctx->wait)); + } BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); mutex_unlock(&acomp_ctx->mutex);