From mboxrd@z Thu Jan 1 00:00:00 1970 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 7D7D4D1A42F for ; Sat, 12 Oct 2024 03:33:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 038F96B00A0; Fri, 11 Oct 2024 23:33:33 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2B5C6B00A1; Fri, 11 Oct 2024 23:33:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DF3576B00A3; Fri, 11 Oct 2024 23:33:32 -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 BCDBC6B00A0 for ; Fri, 11 Oct 2024 23:33:32 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0B9C11613F4 for ; Sat, 12 Oct 2024 03:33:27 +0000 (UTC) X-FDA: 82663530222.29.A02F83F Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) by imf28.hostedemail.com (Postfix) with ESMTP id B8088C0004 for ; Sat, 12 Oct 2024 03:33:27 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=jtv7DbvR; spf=pass (imf28.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728703940; 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:in-reply-to:references:references:dkim-signature; bh=8o81ePbu8o7fPin68TehE+eOoRAm92NK36NqF94NSOw=; b=dbZxBwCt+mWKRkimykLepgCZJiy3HPWPz8l/8dtVV4x7qSo1ju/+fmmIti6nkz/Zulxzhc gcDV+zMEFNXHgKX3jOizEIil/TTbuflmRh1otDxlQosFPGZxctTA9sCHYbZuifiQE87tjN 84k1ODYj1qq0aJt9Qnwz9tBEsubno7Q= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=jtv7DbvR; spf=pass (imf28.hostedemail.com: domain of chengming.zhou@linux.dev designates 91.218.175.174 as permitted sender) smtp.mailfrom=chengming.zhou@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728703940; a=rsa-sha256; cv=none; b=l1iaKkPO5uPO1j97iH2AIThGzP8MTIIE1jH3mbq2OCfyBXeCbGon9k+iHmIU6r7KdWV6nj cHQodN58dvUNRXhmdHAKmMO9dMQIcCWm0jpguewuJP2QPRypqnoApD03yC2VBf2bXLIj2c mz3AmndC0/XDKo1Pmn+UCUfw3w0BadQ= Message-ID: <5fa01666-51d4-4ccb-bcd4-3b3620dd2e2b@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1728704007; h=from:from: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:in-reply-to:references:references; bh=8o81ePbu8o7fPin68TehE+eOoRAm92NK36NqF94NSOw=; b=jtv7DbvRM5F36XrUR/X3xquqMv0NN2DQ/WXCOrLff6JzXHvEbu2XYngbkDYjX1KuXjQkeX 0WuvB5vq5AyXn1z3+edejD/7no+cZ/2jt7MvYdMVBpOUBPtjYtLfpCzeTw3rcc9ePNa3ZE vb3IyatJNWzs+XXIY75XIwQJSfpN7Tw= Date: Sat, 12 Oct 2024 11:33:14 +0800 MIME-Version: 1.0 Subject: Re: [PATCH] mm/zswap: avoid touching XArray for unnecessary invalidation To: Kairui Song , Johannes Weiner Cc: Yosry Ahmed , linux-mm@kvack.org, Andrew Morton , Nhat Pham , Chris Li , Barry Song , "Huang, Ying" , LKML References: <20241011171950.62684-1-ryncsn@gmail.com> <20241011182831.GC351101@cmpxchg.org> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: B8088C0004 X-Stat-Signature: 86sg6hhh8pyuu9sbjpqwwneageny6s8m X-HE-Tag: 1728704007-62542 X-HE-Meta: U2FsdGVkX1/rUKQAWHBZL5WSwxnlhEW5slyzVuCB9QZ1XMZHGzwr87nFua9TkXn7gpjGCs/tlf2+IyyiK8ra164mCuXAsNdeIK1UAAYBlVUd2tDzFoNmZqouqUnFuqc0Ze0QkU4VlQy+ahP4FRyjo4ihDKzN9uCcLooNDevUxrGnIwyf7tvjdCmeq/tkbrCvUzu3Yb1kLiCSEh9+8VhJAljqT5U/VpJTXZyU2ZUTfCo2LxX3zsU7GIpHk9KcessbjckHrG/Y2V6+UEZzVOuvWXc2Ei9LuELFl5DtyL6nN8a2NqTSpCcNYHE26G5F2OrVornUT24S6IPeZ08FtROWVzek3r3l9M3LzOcXD278SVwcz6vB9rHICi0ctRwiJoXNEqffRarZGw5ezhkqKb9U2K+cBtz67Yt/YgIY71iQdIqhBf6GbeeuQPIL6KJi05EWJFXNtbrEAOlY4me9zjGv8i6wiokiWAGQ5SD2oZUlifrtUa3DoY+AMCYAf1eh2BEH8d4RgKNn+HJVGqhBPpSPwpwuC1v39WEeMtWNAZbqL9rHHcLO0uwq8G55iJQFW8EEpMZzNasmcvVduYc9xP88svA9BBPSsTX+5YuPuIoHIDiSQl3kvDOLwbwgKjQQDUjgHT1WlQbjsb2gNoPU3GOqLYAbgVb2skzApYYMNrK3yTB+DC/E07ual2hi6mmp77RPnuxvBncQlCa4sXM2tzcJfMhv3pHhO60Ips2iX251uy5jIaJyhQlLlbpEoIcp088dSucBCSnPhhsUiRbxc5oua3zgAJD5ANmpUsx8YUmMz5o/3BqLwFQWIYZVq7nVwF8F/sYEkbnvtKv0HODni2WZ8bwvILdjHg39m7z1P+VIPFOMJM1eYs4Q6XBuAFrGBPdDymgSi76+mq5PakilFmVtMehWhlI9ZLfGxcZH966Na2cXivdyPACU+WaFfYmO4MNaEdAlcJYiVSs80lNM62/ 4T6qAb/8 K0oEbZjJxmUwsIZ6u6+Y26BFartkSadU84s82KiD22D6af7Og8HfZibsrwO7RxEKsj4Xdq84T/9zzkYGdOmXY0hqSAi1oN1dG++23YPjtq6vksq1mwg8VOYy7Q6gebwJPSi/lRst8L10HcJNvutB1J0HJGJOTJdQAdItlEpT66jNPEutLu31rRlA7bNIyDlPDZuYtzfYuxEILIlQjzrOtx+fogqNpnNIDxoxIkOLNLt+CvQ1fpi7Ox3qYM+gDRlosPrsptfh7yXOXuTeECIFhzPRylQ== 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: On 2024/10/12 11:04, Kairui Song wrote: > Johannes Weiner 于 2024年10月12日周六 02:28写道: >> >> On Fri, Oct 11, 2024 at 10:53:31AM -0700, Yosry Ahmed wrote: >>> On Fri, Oct 11, 2024 at 10:20 AM Kairui Song wrote: >>>> >>>> From: Kairui Song >>>> >>>> zswap_invalidation simply calls xa_erase, which acquires the Xarray >>>> lock first, then does a look up. This has a higher overhead even if >>>> zswap is not used or the tree is empty. >>>> >>>> So instead, do a very lightweight xa_empty check first, if there is >>>> nothing to erase, don't touch the lock or the tree. >> >> Great idea! >> >>> XA_STATE(xas, ..); >>> >>> rcu_read_lock(); >>> entry = xas_load(&xas); >>> if (entry) { >>> xas_lock(&xas); >>> WARN_ON_ONCE(xas_reload(&xas) != entry); >>> xas_store(&xas, NULL); >>> xas_unlock(&xas); >>> } >>> rcu_read_unlock(): >> >> This does the optimization more reliably, and I think we should go >> with this version. > > Hi Yosry and Johannes, > > This is a good idea. But xa_empty is just much lighweighter, it's just > a inlined ( == NULL ) check, so unsurprising it has better performance > than xas_load. > > And surprisingly it's faster than zswap_never_enabled. So I think it Do you have CONFIG_ZSWAP_DEFAULT_ON enabled? In your case, CPU will go to the unlikely branch of static_key every time, which maybe the cause. > could be doable to introduce something like zswap_may_have_swpentry as > Yosry suggested. > > So how about a combined version with xas_load and xa_empty? Check > xa_empty first as a faster path, then xas_load, then xas_store. Yeah, I also think this combined version is better. Thanks. > > Here is the benchmark result (time of swapin 2G zero pages in us): > > Before: 1908944 1905870 1905322 1905627 1901667 > xa_empty: 1835343 1827367 1828402 1831841 1832719 > z.._enabled: 1838428 1831162 1838205 1837287 1840980 > xas_load: 1874606 1878971 1870182 1875852 1873403 > combined: 1845309 1832919 1831904 1836455 1842570 > > `combined` is xa_empty + xas_load.