From patchwork Wed Jan 17 09:23:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengming Zhou X-Patchwork-Id: 13521515 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 83867C47422 for ; Wed, 17 Jan 2024 09:23:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E961F6B00B1; Wed, 17 Jan 2024 04:23:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E45686B00B9; Wed, 17 Jan 2024 04:23:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D34026B00BA; Wed, 17 Jan 2024 04:23:49 -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 C46536B00B1 for ; Wed, 17 Jan 2024 04:23:49 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9EF931A066E for ; Wed, 17 Jan 2024 09:23:49 +0000 (UTC) X-FDA: 81688265778.28.D9AD827 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) by imf05.hostedemail.com (Postfix) with ESMTP id EE726100019 for ; Wed, 17 Jan 2024 09:23:46 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.172 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=1705483427; 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=hroLaptcH3VXrRGDJBO6nKpsPv+9ovgYkH9+DMMMuQE=; b=KEIxf1c0rtIQbLytFchTLY2c8dpaYni/1vBdc7JyZW+7cLvOjhbhH4H/Ac8/bCa3o+O33n rmYzJyzGH6dXjTLf8eTvZpMZqB0s/sXcE4Kg7U8mviGll6kbSGng6jtZppbOJmaatD+kF3 AnVju8GGqG1F8tSPhfPtKc8LmOQ4RPs= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1705483427; a=rsa-sha256; cv=none; b=aYNg8YKwbCuiUArT6rhbUKvbdUWnEvGKb5pS35ZPwccT+YL8hAwVMH6Czn0gBJI1nUQ06M R79gXWUfLN2IQXdDScczd6ZMeN4IvYwHCDOqUpfMCW6Ttrc7Bt1B1WI9JeJSRdvuh27S2M UTLa3+9gyzkZE//lmq2+ChXjshGoQq8= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=none; spf=pass (imf05.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.172 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) Subject: [PATCH 0/2] mm/zswap: optimize the scalability of zswap rb-tree MIME-Version: 1.0 X-b4-tracking: H4sIAIWcp2UC/w3LUQrDIAwA0KuUfDdgXEDYbdSGNcxpMe0GLb37/Hwf7wKTrmLwnC7o8lXTVgdoni Cvsb4EdRkG7zw7ooCJ8bRf3LC0/Ma27frRU5BZXKBMD/YBRk7RBFOPNa+j16OU+/4DWfTtvG0AAAA= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou Date: Wed, 17 Jan 2024 09:23:17 +0000 Message-Id: <20240117-b4-zswap-lock-optimize-v1-0-23f6effe5775@bytedance.com> To: Andrew Morton Cc: Yosry Ahmed , Chengming Zhou , linux-kernel@vger.kernel.org, Johannes Weiner , linux-mm@kvack.org, Chris Li , Nhat Pham X-Developer-Signature: v=1; a=ed25519-sha256; t=1705483421; l=1680; i=zhouchengming@bytedance.com; s=20231204; h=from:subject:message-id; bh=clwC7ehDjjgIdT3ugd8uEArThiV73YZzLeU9DE/pKIE=; b=HqTFINfUAwt7GkI4Tqp4Be3g6BZ2NL7GR/khpO5sbZCsMZ8N4CnC97mwpT5phVZk4V40/Nxzk S6xcqcZ4vpwCWp2BmFZbHEqJu+90vlYssIkCMSa/5vQg3dLfUoZAvwL X-Developer-Key: i=zhouchengming@bytedance.com; a=ed25519; pk=xFTmRtMG3vELGJBUiml7OYNdM393WOMv0iWWeQEVVdA= X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 6sd1tj4xmt8q6n5fte8sm6d9xr6nco4r X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: EE726100019 X-Rspam-User: X-Rspamd-Pre-Result: action=add header; module=dmarc; Action set by DMARC X-Rspam: Yes X-HE-Tag: 1705483426-954661 X-HE-Meta: U2FsdGVkX18Gldodme2N0aV1BYnjJu/QcBjn7vQmZdZ/U83Tjz+3ycYfgT8Zw7AixydqbQgIhMwaCgB5lb+FG6/QOtF3+ItslbL9uiz/4gAB6niJCzc8zYxTm5AsmRjaiW6m/9KoydAmvA0io7BaYg29p6y9VdI2bbErak9PqwG+UyaylY4/vFHyDdWTQAPyiBrCRE9futW6NoDq902CqCXgJ6D638/jyP9eD36UyxXd6QUxQzpZcnJN1LHA/7Mcd8fWj534L9HDJCRGYWw4sIAmCNAtBBYAe45TVcHvHC+BogGHMUsbo5FRFpf/Q8OKtGY3s0HujoZL7eMIsL84PuT6qEJ67QhUNzZPX7aEWiht7P/vL5Ij3h+UxZCauc8ArrmCAkJmWH7MNo+nop0uzbCX57mO7Wj61A2zKPtT8X3QO9R19jHqC6KqY2jVgMVUFdp+ZFy26gkXLDOhc5raL/SIDWctPJEuh96ob3MS6MYbZie/AS5BO9r5MYewsfia5oFHKw0iwxbs3oeJ/VYrRyhza3kOZAWvyXuPSZix2DiiKgB2akNZoy47nFjdrkKI5kwAOLHUgbCwxeOxKX6P6LjKrxr3nKpOPf+OeAV2gK6tj3W5yb9WKh6oaik/RUcpSoar9/89UoIyqUyeNnO3fqpEH3Fwe9M9Ezmi4BEsXd0uRaWniji04ynMUJbzE28rm4hkvOgBde5g+EWELOEAMZmPQg427uoWFKgIhoeIGGGhAFZ9iabvMbRkuryP3ryWUxfQEf8dE/PbvuHk5OAcMg2gzlH0d21NYrLaxmzaZnWIErfv294tzAr2/YYrMvhEBN8rccCg0HnDATBgfqAeM4gzvB1hZ+e5JhMLPiagXEMhHsBWCCay4PAOepf3pyZDGEY5MeY++5QoX2mknmPCqt4gP0SXL1pXiwiteQohHL+ayrV3mkYpm/i9Rw6lWS15Zggb7ETCcgbeJqJRd5C ac1upi59 v/RlG 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: 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 | 74 ++++++++++++++++++++++++++++++++------------------- 3 files changed, 59 insertions(+), 32 deletions(-) --- base-commit: ab27740f76654ed58dd32ac0ba0031c18a6dea3b change-id: 20240117-b4-zswap-lock-optimize-44e071c13427 Best regards,