From patchwork Fri Oct 18 06:40:48 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: 13841227 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 9DF0BD3C550 for ; Fri, 18 Oct 2024 06:41:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 17F2E6B0082; Fri, 18 Oct 2024 02:41:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 12F9F6B0085; Fri, 18 Oct 2024 02:41:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EEAE56B0089; Fri, 18 Oct 2024 02:41:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C8AE06B0082 for ; Fri, 18 Oct 2024 02:41:06 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id F076EA1590 for ; Fri, 18 Oct 2024 06:40:44 +0000 (UTC) X-FDA: 82685775438.12.A4DF280 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) by imf24.hostedemail.com (Postfix) with ESMTP id 3A3D918001D for ; Fri, 18 Oct 2024 06:41:00 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Tpoeo2l6; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.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=1729233557; a=rsa-sha256; cv=none; b=DHyu3oG9GOV8LjZd4uI1dlhPEaUdWxHQq7kO1B8Srdg67ZgIMfVP5h99777xsHl81ew925 Uj3Qcmt0NoIm78ec8NG0zxh1KC0Tsrx/gGVLUdj57eEokc+F2WK+vRdOXyXgWxIr1eYkwo S0z4NU+LDeqaJXq6s/yOeO7Owvkbx/g= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=Tpoeo2l6; dmarc=pass (policy=none) header.from=intel.com; spf=pass (imf24.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=1729233557; 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:references:dkim-signature; bh=rcFVAaRmVRKJZmVWa6uoOusyVPCx68JC+YP9HlXSvHU=; b=3951tVxRVSHBZCL0M5s/bBrczGI2dps9cieK2MZzIPtx+TN31jRz7lZdpijdKhCPUgocRQ 5g0BduO1spgV+6ZpEF6SrtM9xdqJd8Rl1Wpc2Qyj6gYOXfEJwGoJrVMoxObPMY3LoCvKMf MDyyTq14/Y8t3NTEqA80j1XWTLVCCuI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729233663; x=1760769663; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=SnQFoT2demFuoVOQR3h9+M/hryMmXEj3QJ9+DnUr3Gw=; b=Tpoeo2l6YJHJ0PdmN2tQdupSdZeFpoO+1Gp+XVnoYDp73JhdFkavxFu0 R8MAHcZ2PwR32Nni5E50F8FiczlycoGtZbyvG+qKOdFOfrEvKabDMZnld lLOh+BmT92eagIUBJqVqipSFCmCC5ZOQo/bMB/HcUMBU1MZMdufXUfdE4 SXvSsfoQpv1fNJ47/F+ogUpETBg+UQ2ir1gQAzETikOFBD0wL7Q1WykDE emN6/bNDcb/gB/LMrzwYz01yhRF+58sNFAc4vSUZdNR1hGerjgs4r7ZI2 yS4cVtweRRvd5hYlvjG4MSlQTv/QhCM6o3rRFefuwZv10UXCMGYYRn1MT w==; X-CSE-ConnectionGUID: l5rECjQ9R1W/TN2+ZqN2og== X-CSE-MsgGUID: R7xeAU6vRkSkQfS/4bGehw== X-IronPort-AV: E=McAfee;i="6700,10204,11228"; a="28884767" X-IronPort-AV: E=Sophos;i="6.11,212,1725346800"; d="scan'208";a="28884767" 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:01 -0700 X-CSE-ConnectionGUID: 3n8C6713RaSdtr+PYw3ypw== X-CSE-MsgGUID: 7O0Ti20bSgedmSmh4MdRkQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,199,1725346800"; d="scan'208";a="83607485" Received: from jf5300-b11a338t.jf.intel.com ([10.242.51.6]) by orviesa003.jf.intel.com with ESMTP; 17 Oct 2024 23:41:01 -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 00/13] zswap IAA compress batching Date: Thu, 17 Oct 2024 23:40:48 -0700 Message-Id: <20241018064101.336232-1-kanchana.p.sridhar@intel.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 3A3D918001D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: drrtamwrge494pdhyfotyha45gips4gr X-HE-Tag: 1729233660-794637 X-HE-Meta: U2FsdGVkX18YANs6wYVX5eg4T5pHgKuqKH3R178+CLvkRLv+w0vqekJVHr9QW0nLuIkRKfbBvmgf3s6qfAbVec3QKDI6k3E+mRrgSu5IALJE85/ez+UOlWJuVmGoS8qUvPW+sjWDYWp9P85XczfQUobDKWBsgHM0ay/K7ZJ6InSAL8vSd5k1eOebyPzEPyqwi9CDiqiZ/94b/QSQW+NcQueSZYaYat1ofHulrCTOL81VWjLi9rs8lneacAorJEu0tI6nDB7nFM+5BqZIPvAJe5ZbWc6LBXTEbXosPXzVMQ7+Xhr8vCRMbHJZrM9UJJ8ZJuFOC/sKmAlMROEO63Ous/5rU5jR+rKGp5lxmcgEU+QB0alV90XcVl9ESzgSLm2z8C+Yc3meSgjlZqEi4AD3utelHh8SMsdb/UjtYeIy+Z70/7gOZylzrgEderEV2jZFv5H0krP/XT5re9N0IyMF8aWlbGgxerPk7z/aHKYehUqxihfCYEzlItOQpZ8NU03Duhr8y3Ta3AIH+WOw8bthj6tROwRPqaNVlkVUncd4iSXxaoq0mBDh0W2+NsQTmAGj75mVr2YoVpE79l0IBK7dMYiVT9Jag3UPxx0sAHCdKHU6hpbVwgzbRAJumw7K+ZHtJiTmTvtBnvOdag19jg4n+obkLm6o1uo8kPjpTuBKJ/cWCrN61FspsmeH1J1KtupEIkOxzhzIdocdH6Do4tJJS5+za9QtKwhL7Af2i9EJd/80MoJt4RmYP4wx2GguiCrCldUjmCKu9ajYIdkZ1AfwuYDSEe7h2cv//DpZJ8H2mX+yo4c6+KF9ikASBgVAJ/L0/Zb6ExjzQcw3JTzW7YJzenqwQ8PeDTkULaPEkwXfVH/YBc0FobbyvQD4KCDwi6XDeh1z94NJztomWJ85dt7rUD5oxBOPN8CgxvnVrFvGndsyvBQsMPK+6CEd+r9htiZisy6/zHettsaPHeLbDlu q9KYNPOW KTkDPCcWOY1XpJzYZBlxY9FgAfgZvjfEa+G4EpNE4L/qoT4ewyHwXtFCul634WYUtDMgNJyWqiGFUbsw8BcLoLZ/ScB52z8ba3CqUy5b6qNwdX4OzVJ+fcoLQooKofsG7LiRdupOrZ8OxCZ8Z/fUffAT7/g== 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: IAA Compression Batching: ========================= This RFC patch-series introduces the use of the Intel Analytics Accelerator (IAA) for parallel compression of pages in a folio, and for batched reclaim of hybrid any-order batches of folios in shrink_folio_list(). The patch-series is organized as follows: 1) iaa_crypto driver enablers for batching: Relevant patches are tagged with "crypto:" in the subject: a) async poll crypto_acomp interface without interrupts. b) crypto testmgr acomp poll support. c) Modifying the default sync_mode to "async" and disabling verify_compress by default, to facilitate users to run IAA easily for comparison with software compressors. d) Changing the cpu-to-iaa mappings to more evenly balance cores to IAA devices. e) Addition of a "global_wq" per IAA, which can be used as a global resource for the socket. If the user configures 2WQs per IAA device, the driver will distribute compress jobs from all cores on the socket to the "global_wqs" of all the IAA devices on that socket, in a round-robin manner. This can be used to improve compression throughput for workloads that see a lot of swapout activity. 2) Migrating zswap to use async poll in zswap_compress()/decompress(). 3) A centralized batch compression API that can be used by swap modules. 4) IAA compress batching within large folio zswap stores. 5) IAA compress batching of any-order hybrid folios in shrink_folio_list(). The newly added "sysctl vm.compress-batchsize" parameter can be used to configure the number of folios in [1, 32] to be reclaimed using compress batching. IAA compress batching can be enabled only on platforms that have IAA, by setting this config variable: CONFIG_ZSWAP_STORE_BATCHING_ENABLED="y" The performance testing data with usemem 30 instances shows throughput gains of up to 40%, elapsed time reduction of up to 22% and sys time reduction of up to 30% with IAA compression batching. Our internal validation of IAA compress/decompress batching in highly contended Sapphire Rapids server setups with workloads running on 72 cores for ~25 minutes under stringent memory limit constraints have shown up to 50% reduction in sys time and 3.5% reduction in workload run time as compared to software compressors. System setup for testing: ========================= Testing of this patch-series was done with mm-unstable as of 10-16-2024, commit 817952b8be34, without and with this patch-series. Data was gathered on an Intel Sapphire Rapids server, dual-socket 56 cores per socket, 4 IAA devices per socket, 503 GiB RAM and 525G SSD disk partition swap. Core frequency was fixed at 2500MHz. The vm-scalability "usemem" test was run in a cgroup whose memory.high was fixed at 150G. The is no swap limit set for the cgroup. 30 usemem processes were run, each allocating and writing 10G of memory, and sleeping for 10 sec before exiting: usemem --init-time -w -O -s 10 -n 30 10g Other kernel configuration parameters: zswap compressor : deflate-iaa zswap allocator : zsmalloc vm.page-cluster : 2,4 IAA "compression verification" is disabled and the async poll acomp interface is used in the iaa_crypto driver (the defaults with this series). Performance testing (usemem30): =============================== 4K folios: deflate-iaa: ======================= ------------------------------------------------------------------------------- mm-unstable-10-16-2024 shrink_folio_list() shrink_folio_list() batching of folios batching of folios ------------------------------------------------------------------------------- zswap compressor deflate-iaa deflate-iaa deflate-iaa vm.compress-batchsize n/a 1 32 vm.page-cluster 2 2 2 ------------------------------------------------------------------------------- Total throughput 4,470,466 5,770,824 6,363,045 (KB/s) Average throughput 149,015 192,360 212,101 (KB/s) elapsed time 119.24 100.96 92.99 (sec) sys time (sec) 2,819.29 2,168.08 1,970.79 ------------------------------------------------------------------------------- memcg_high 668,185 646,357 613,421 memcg_swap_fail 0 0 0 zswpout 62,991,796 58,275,673 53,070,201 zswpin 431 415 396 pswpout 0 0 0 pswpin 0 0 0 thp_swpout 0 0 0 thp_swpout_fallback 0 0 0 pgmajfault 3,137 3,085 3,440 swap_ra 99 100 95 swap_ra_hit 42 44 45 ------------------------------------------------------------------------------- 16k/32/64k folios: deflate-iaa: =============================== All three large folio sizes 16k/32/64k were enabled to "always". ------------------------------------------------------------------------------- mm-unstable- zswap_store() + shrink_folio_list() 10-16-2024 batching of batching of folios pages in large folios ------------------------------------------------------------------------------- zswap compr deflate-iaa deflate-iaa deflate-iaa vm.compress- n/a n/a 4 8 16 batchsize vm.page- 2 2 2 2 2 cluster ------------------------------------------------------------------------------- Total throughput 7,182,198 8,448,994 8,584,728 8,729,643 8,775,944 (KB/s) Avg throughput 239,406 281,633 286,157 290,988 292,531 (KB/s) elapsed time 85.04 77.84 77.03 75.18 74.98 (sec) sys time (sec) 1,730.77 1,527.40 1,528.52 1,473.76 1,465.97 ------------------------------------------------------------------------------- memcg_high 648,125 694,188 696,004 699,728 724,887 memcg_swap_fail 1,550 2,540 1,627 1,577 1,517 zswpout 57,606,876 56,624,450 56,125,082 55,999,42 57,352,204 zswpin 421 406 422 400 437 pswpout 0 0 0 0 0 pswpin 0 0 0 0 0 thp_swpout 0 0 0 0 0 thp_swpout_fallback 0 0 0 0 0 16kB-mthp_swpout_ 0 0 0 0 0 fallback 32kB-mthp_swpout_ 0 0 0 0 0 fallback 64kB-mthp_swpout_ 1,550 2,539 1,627 1,577 1,517 fallback pgmajfault 3,102 3,126 3,473 3,454 3,134 swap_ra 107 144 109 124 181 swap_ra_hit 51 88 45 66 107 ZSWPOUT-16kB 2 3 4 4 3 ZSWPOUT-32kB 0 2 1 1 0 ZSWPOUT-64kB 3,598,889 3,536,556 3,506,134 3,498,324 3,582,921 SWPOUT-16kB 0 0 0 0 0 SWPOUT-32kB 0 0 0 0 0 SWPOUT-64kB 0 0 0 0 0 ------------------------------------------------------------------------------- 2M folios: deflate-iaa: ======================= ------------------------------------------------------------------------------- mm-unstable-10-16-2024 zswap_store() batching of pages in pmd-mappable folios ------------------------------------------------------------------------------- zswap compressor deflate-iaa deflate-iaa vm.compress-batchsize n/a n/a vm.page-cluster 2 2 ------------------------------------------------------------------------------- Total throughput 7,444,592 8,916,349 (KB/s) Average throughput 248,153 297,211 (KB/s) elapsed time 86.29 73.44 (sec) sys time (sec) 1,833.21 1,418.58 ------------------------------------------------------------------------------- memcg_high 81,786 89,905 memcg_swap_fail 82 395 zswpout 58,874,092 57,721,884 zswpin 422 458 pswpout 0 0 pswpin 0 0 thp_swpout 0 0 thp_swpout_fallback 82 394 pgmajfault 14,864 21,544 swap_ra 34,953 53,751 swap_ra_hit 34,895 53,660 ZSWPOUT-2048kB 114,815 112,269 SWPOUT-2048kB 0 0 ------------------------------------------------------------------------------- Since 4K folios account for ~0.4% of all zswapouts when pmd-mappable folios are enabled for usemem30, we cannot expect much improvement from reclaim batching. Performance testing (Kernel compilation): ========================================= As mentioned earlier, for workloads that see a lot of swapout activity, we can benefit from configuring 2 WQs per IAA device, with compress jobs from all same-socket cores being distributed toothe wq.1 of all IAAs on the socket, with the "global_wq" developed in this patch-series. Although this data includes IAA decompress batching, which will be submitted as a separate RFC patch-series, I am listing it here to quantify the benefit of distributing compress jobs among all IAAs. The kernel compilation test with "allmodconfig" is able to quantify this well: 4K folios: deflate-iaa: kernel compilation to quantify crypto patches ===================================================================== ------------------------------------------------------------------------------ IAA shrink_folio_list() compress batching and swapin_readahead() decompress batching 1WQ 2WQ (distribute compress jobs) 1 local WQ (wq.0) 1 local WQ (wq.0) + per IAA 1 global WQ (wq.1) per IAA ------------------------------------------------------------------------------ zswap compressor deflate-iaa deflate-iaa vm.compress-batchsize 32 32 vm.page-cluster 4 4 ------------------------------------------------------------------------------ real_sec 746.77 745.42 user_sec 15,732.66 15,738.85 sys_sec 5,384.14 5,247.86 Max_Res_Set_Size_KB 1,874,432 1,872,640 ------------------------------------------------------------------------------ zswpout 101,648,460 104,882,982 zswpin 27,418,319 29,428,515 pswpout 213 22 pswpin 207 6 pgmajfault 21,896,616 23,629,768 swap_ra 6,054,409 6,385,080 swap_ra_hit 3,791,628 3,985,141 ------------------------------------------------------------------------------ The iaa_crypto wq stats will show almost the same number of compress calls for wq.1 of all IAA devices. wq.0 will handle decompress calls exclusively. We see a latency reduction of 2.5% by distributing compress jobs among all IAA devices on the socket. I would greatly appreciate code review comments for the iaa_crypto driver and mm patches included in this series! Thanks, Kanchana Kanchana P Sridhar (13): crypto: acomp - Add a poll() operation to acomp_alg and acomp_req crypto: iaa - Add support for irq-less crypto async interface crypto: testmgr - Add crypto testmgr acomp poll support. mm: zswap: zswap_compress()/decompress() can submit, then poll an acomp_req. crypto: iaa - Make async mode the default. crypto: iaa - Disable iaa_verify_compress by default. crypto: iaa - Change cpu-to-iaa mappings to evenly balance cores to IAAs. crypto: iaa - Distribute compress jobs to all IAA devices on a NUMA node. mm: zswap: Config variable to enable compress batching in zswap_store(). mm: zswap: Create multiple reqs/buffers in crypto_acomp_ctx if platform has IAA. mm: swap: Add IAA batch compression API swap_crypto_acomp_compress_batch(). mm: zswap: Compress batching with Intel IAA in zswap_store() of large folios. mm: vmscan, swap, zswap: Compress batching of folios in shrink_folio_list(). crypto/acompress.c | 1 + crypto/testmgr.c | 70 +- drivers/crypto/intel/iaa/iaa_crypto_main.c | 467 +++++++++++-- include/crypto/acompress.h | 18 + include/crypto/internal/acompress.h | 1 + include/linux/fs.h | 2 + include/linux/mm.h | 8 + include/linux/writeback.h | 5 + include/linux/zswap.h | 106 +++ kernel/sysctl.c | 9 + mm/Kconfig | 12 + mm/page_io.c | 152 +++- mm/swap.c | 15 + mm/swap.h | 96 +++ mm/swap_state.c | 115 +++ mm/vmscan.c | 154 +++- mm/zswap.c | 771 +++++++++++++++++++-- 17 files changed, 1870 insertions(+), 132 deletions(-) base-commit: 817952b8be34aad40e07f6832fb9d1fc08961550