From patchwork Fri Jan 19 11:22:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13523671 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 9F6BCC4725D for ; Fri, 19 Jan 2024 11:22:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 051246B0085; Fri, 19 Jan 2024 06:22:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 001386B0087; Fri, 19 Jan 2024 06:22:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E32376B0088; Fri, 19 Jan 2024 06:22:34 -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 D11506B0085 for ; Fri, 19 Jan 2024 06:22:34 -0500 (EST) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 995DB1A0318 for ; Fri, 19 Jan 2024 11:22:34 +0000 (UTC) X-FDA: 81695822628.13.70DD60B Received: from out-177.mta1.migadu.com (out-177.mta1.migadu.com [95.215.58.177]) by imf12.hostedemail.com (Postfix) with ESMTP id BCC1C40005 for ; Fri, 19 Jan 2024 11:22:32 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1705663353; 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-type: content-transfer-encoding:content-transfer-encoding:in-reply-to: references; bh=ZDLWsRHxnQURDUvHZ0QJRAwFAeryd1hcqAsI9crMqa4=; b=BJQUYSXsXMyoAwrMG0LGup/IFzf6niyIYAPg84nk0j5W6nl5w+4Fc1TizXPN2BcKC5Wdzn BD38ttOQ9LnoHucyaQjYXwQPUSg0XzLHjLlSsKlvhV5U9too5huVdBuqM0NhjrlkfE/wF3 N5YOEF42iAHWHAqEfh+mvmxzjVtR3hk= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=pass (imf12.hostedemail.com: domain of chengming.zhou@linux.dev designates 95.215.58.177 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=fail reason="SPF not aligned (relaxed), No valid DKIM" header.from=bytedance.com (policy=quarantine) ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705663353; a=rsa-sha256; cv=none; b=FdY9Fe54YPU1CW1PKfcdD9Q+CUFX2Gki784q1l1p4moM9s2A+2DdtNF5VS404/rGEjVvFz aIUDx2S0rXdiRzabmaTT0ezsNvZGuJ/d83NUPEWZv3G7S1cInSkxX94WacxfIfTMLuiFFw f2euQietBYK9PsV8TO3m2uPoV4pfO0Q= Subject: [PATCH v2 0/2] mm/zswap: optimize the scalability of zswap rb-tree MIME-Version: 1.0 X-b4-tracking: H4sIAG1bqmUC/4WNQQ6CMBBFr0Jm7Zi2FJu48h7GRVsGmQgtaREDhLvbeAFXP+8n7/8dMiWmDNdqh0 QLZ46hgDpV4HsbnoTcFgYllBZSGnQat/yxEw7RvzBOM4+8EWpNwkgva60MFNnZTOiSDb4vengPQyl7 znNM6+9skSXuf3cXiQJV3V2o66gxprm5daa27NLZxxEex3F8AdSXtlPFAAAA X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Fri, 19 Jan 2024 11:22:21 +0000 Message-Id: <20240117-b4-zswap-lock-optimize-v2-0-b5cc55479090@bytedance.com> To: Andrew Morton Cc: Nhat Pham , Yosry Ahmed , Chris Li , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Johannes Weiner , Chengming Zhou X-Developer-Signature: v=1; a=ed25519-sha256; t=1705663348; l=1884; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=7VNhAqJoyAKSD/hQmtRytM/nCkvMMCR+Dhb06spZMzE=; b=akpgee1fXkr61CWEO40WVSuXwdZrA981o4Nml3McnVIZ+zr6NdpD3PGRLWNPhgGRQNVjyVdbh 3HfD7od0hZmCnhoGo15Elt10ueJlVkwt2zAVES5vITd8tjKnz2itDZA X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: BCC1C40005 X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam-User: X-Stat-Signature: z5kueb3kmrkk765649tjgr9dgrsgse4n X-Rspamd-Server: rspam01 X-Rspam: Yes X-HE-Tag: 1705663352-584569 X-HE-Meta: U2FsdGVkX19Sd4KaUAbwaNmnsf0K1QWnMYmwJrb0v69es5ZjrrNrd/Wl15b9/OkZrCrmNNebyVM6xXgD+Pu3zLpt4uG/CpN6hGGSNv4J8AmGcSjiqgKMiSuxPtmb9vltV4lqk7DRjPE0X03A71yfd4kHYSyNAZdHK6LA/eW3yz1/8R/3zLUvImczbvtH5mnm1/dv/YF0Q/5Y/742vm54Nvphwmvy+zBlfFOsxZr4A5dDZFY6n88m6wz6iQc/B1HSwURkNL9D/UCewRNZSoSLu5rjZ2AmGMhaO/JOaTurLwW4NcO/NvBuTYvJ0A7+hNYGrNrVXnJ0YLFM8467o4jUguEJOMBzjASIYJclj1VwkFfRaxNgeRRWJngrYLpsU8Lhc5d62wG/wsoTvcE24qm9zDyo/JhZKGaeq2Xj+SrnNUlNfFnyjh4WjbPtwNqxJrqFQfhch1lXsBGJlt3fsAD/reKBKFWsUgVmM7RgJZLDGOetsLhFIM66uyqbbJ/XMsh0eLjQ+A026de8cym3RDMR+Hhy7yUEt1hrAeYp/5ZTOn+korLvuUEcT8pSGmJLEpyG+zFh/WNrYr42rI+Wi9Qo/ycxXixwKAAqn9GTyxAK3OzA/sPRrnAT1d2U22RjZQc5f65ZdsEj7cItNtWojfNkET11S2X7b24fAXJMygptY1RuMVQCwAwchJQWjCfJFnmVsFTtA/syAU1OBNKxuEejCkdt6vaLuBquuNqJCllur2j1nl1tcOUtLI7U8ZWAqFNQSOFo8wfFkWIfoR6xvMruxj+xp/ya+xPzJPGPpT8rDifKWkz04eMts7Dsl1QYTZWz9rdnm9O176i0lSMkuqGZ5B6ylIv7WUvfooM09maDlPbLlI+ZiaCDK/CHKF624dAX3q9NyG8piS62KwECE+MtsEGUhdg8LaSYyBDVcpv8UteQYSMbGUAqBQ5YXLBh9G6Sdu2Uhr5g2mIJGLzqU5+ 97k5BYXU UsUoq 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: Changes in v2: - Change swap_zswap_tree() to static inline function. - Collect Acked-by tags. - Link to v1: https://lore.kernel.org/r/20240117-b4-zswap-lock-optimize-v1-0-23f6effe5775@bytedance.com When testing the zswap performance by using kernel build -j32 in a tmpfs directory, I found the scalability of zswap rb-tree is not good, which is protected by the only spinlock. That would cause heavy lock contention if multiple tasks zswap_store/load concurrently. So a simple solution is to split the only one zswap rb-tree into multiple rb-trees, each corresponds to SWAP_ADDRESS_SPACE_PAGES (64M). This idea is from the commit 4b3ef9daa4fc ("mm/swap: split swap cache into 64MB trunks"). Although this method can't solve the spinlock contention completely, it can mitigate much of that contention. Below is the results of kernel build in tmpfs with zswap shrinker enabled: linux-next zswap-lock-optimize real 1m9.181s 1m3.820s user 17m44.036s 17m40.100s sys 7m37.297s 4m54.622s So there are clearly improvements. And it's complementary with the ongoing zswap xarray conversion by Chris. Anyway, I think we can also merge this first, it's complementary IMHO. So I just refresh and resend this for further discussion. Thanks for review and comment! Signed-off-by: Chengming Zhou --- Chengming Zhou (2): mm/zswap: make sure each swapfile always have zswap rb-tree mm/zswap: split zswap rb-tree include/linux/zswap.h | 7 +++-- mm/swapfile.c | 10 +++++-- mm/zswap.c | 76 +++++++++++++++++++++++++++++++++------------------ 3 files changed, 61 insertions(+), 32 deletions(-) --- base-commit: ab27740f76654ed58dd32ac0ba0031c18a6dea3b change-id: 20240117-b4-zswap-lock-optimize-44e071c13427 Best regards,