From patchwork Fri Oct 11 17:19:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13832769 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 588B9D0EE12 for ; Fri, 11 Oct 2024 17:20:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E031E6B00AF; Fri, 11 Oct 2024 13:20:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DB2D36B00B1; Fri, 11 Oct 2024 13:20:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C54096B00B4; Fri, 11 Oct 2024 13:20:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A7F486B00AF for ; Fri, 11 Oct 2024 13:20:10 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 36A571C7530 for ; Fri, 11 Oct 2024 17:20:05 +0000 (UTC) X-FDA: 82661984496.05.D274B7B Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf08.hostedemail.com (Postfix) with ESMTP id 6F46216000A for ; Fri, 11 Oct 2024 17:20:06 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PlqcR7xA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728667163; a=rsa-sha256; cv=none; b=w3Gk2h9FloM2P+Z3aYuzXEfVOOHFItCtD+R1Y5EBH9boGRhT+OUvm14hBpNLL0M1JkFN4U j079R592xDk+kmD3NFxewNijbp3wMIHpawOpgMthIVZQtJ3gu0xkU423t1G2jzL3TJ0l99 Xzt9wM6u/A7i+DZAizhlEOIausoSR1M= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PlqcR7xA; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=ryncsn@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728667163; h=from:from:sender:reply-to: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=YQYtUCIkke5YuOxMFaq1by907wGKV3qT5PaV1tICSB4=; b=FRWgFo0n2OqMZCqvRIGjGuV6jQpmfCW1jRer7vSIic/xud1xYk2wrf9/Qoo91bGUxJEXcY GLnyYuqfZLHLAfnC+Zoy0MvUDKFEf9Yc2oIllTkhdAVwD1uibGQhv8gS6IsA3PZvvbWhmz CcZUiJOPebTR4OGGj7yxgQTp15FHT8U= Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-20c9978a221so16298495ad.1 for ; Fri, 11 Oct 2024 10:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728667207; x=1729272007; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=YQYtUCIkke5YuOxMFaq1by907wGKV3qT5PaV1tICSB4=; b=PlqcR7xAclQInykXnlBbhh/iDFiXv4ReqsVnavCxrgGqf8PTxOoulckKml/Nvds7e1 Lu6Awj+RmrLBTUbeAMUcEx1xx3An64n4964efbOaehO+onlR1z6msDBnvgy6B0oZwMj6 oIu6UtVSymyyP8DyKHPhDMFhPGsvkotBaa61VTKGjyqCcsgvD0QjcnPA6mCyr8/4EImN ipV0nDfeOMULw64OPQoRCU1CVUdv8f6uKjnD1B3iyupPLjKpgDEnWUp8Deexqv2Q0p0N fnK8w77PrrpV+XUZIi4VhUhcVacltjVMMqnWdByYPjMgsWXFQDJ0HQOMJ/bLaNXd0735 WR/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728667207; x=1729272007; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YQYtUCIkke5YuOxMFaq1by907wGKV3qT5PaV1tICSB4=; b=GAkUuDZULssS62J3dn+mwN5BClsBHe7l67rO3dP+0JK0nhTO39z6bayIO/8aipLnr3 1kk/cetoxVhiQknqZvHgCfI5D5f4uM6J/jTce9fI3kDAnW3GzFDOcbhFUe5VghnZHIxD qDgsTPSgk+kbY6MKCnCaUcL7jhInDOV1lZ4OwsjgwTp5h9OYM5oDtkl0kypte9Q7p27n MQHIZVOMzJ/Dmfqoeq5YfZ3gVy8IkLfB3irLbEKUj2KbxAJpLm0BSKyv778JHsTZeCmQ KNE0WlbzPhMQOyMdqm9Sza8rTF5nnKbmMlUVO/hWaoM+NTjC7xd82IBRCNUogb800o1Q svtg== X-Gm-Message-State: AOJu0YyXEthPgITXDWo5sJ5KHNAAZkW3Fa/5aiOJOtPW2YyUJVqrxGYM GCPUtvuilxldxaxGcmxiyyJ4IBeJU2NepI15+Wplc6rcBymlvLjwGAfhRoILQfE= X-Google-Smtp-Source: AGHT+IHBsdoU7oMghfp0sELWyCGsJMkKemlLy3DN/8QD36ffs0C+vL7gZM9PkX65oj3sRxJ1slhUCw== X-Received: by 2002:a17:902:e845:b0:20c:7409:bd00 with SMTP id d9443c01a7336-20ca1429a4cmr50379765ad.5.1728667206624; Fri, 11 Oct 2024 10:20:06 -0700 (PDT) Received: from KASONG-MC4.tencent.com ([106.37.120.18]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20c8c348d6bsm25325705ad.287.2024.10.11.10.20.02 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 11 Oct 2024 10:20:06 -0700 (PDT) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Johannes Weiner , Yosry Ahmed , Nhat Pham , Chengming Zhou , Chris Li , Barry Song , "Huang, Ying" , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH] mm/zswap: avoid touching XArray for unnecessary invalidation Date: Sat, 12 Oct 2024 01:19:50 +0800 Message-ID: <20241011171950.62684-1-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.0 Reply-To: Kairui Song MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Queue-Id: 6F46216000A X-Rspamd-Server: rspam01 X-Stat-Signature: u9csntb35p57ktcndzq4sbt49uyywbqs X-HE-Tag: 1728667206-558388 X-HE-Meta: U2FsdGVkX1+moUyc7lhH3PuSeg5+aIaMG2afrhCGsUYglcM6mdTbvukQsMZqqTS+htZveAljsxEKJMf24CX7Sy6fk+Wizea/kUrV6vDJNsbOUQbfktFPfYPyRDTDxlEiOY5rZfoPRouSgxc9X+PUJJOelNMlSwhSBMknWvqpFKpi2fCj0rEpOFmGxA5WXVJR2HiPrdrRdIuKuToqj3cgiyCHqdfizHmgbKgMo2pXeqS3d5UddMrsNingQh5RvlF+m9z0TlknzYWqKBwkKGr+QoL0rPfWb2Kdw+Wf3I8FF1LvaYVk8zjKxP4zR8zO/vSfyro7iuGII2ELhJ2lfkw3XYHtbNa8itLf2l5Xd5cRLvppjKA/CvCWBTF3FCV+Ah3vmd7++lHD12/1aiIp0i06ZeekXkNLxyDbft50u5shKO4Uuue00rHHGd3YmeN4/6BFJiD5qQbLeQAcdBQg8R1lA2Jc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version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: 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. Using xa_empty rather than zswap_never_enabled is more helpful as it cover both case where zswap wes never used or the particular range doesn't have any zswap entry. And it's safe as the swap slot should be currently pinned by caller with HAS_CACHE. Sequential SWAP in/out tests with zswap disabled showed a minor performance gain, SWAP in of zero page with zswap enabled also showed a performance gain. (swapout is basically unchanged so only test one case): Swapout of 2G zero page using brd as SWAP, zswap disabled (total time, 4 testrun, +0.1%): Before: 1705013 us 1703119 us 1704335 us 1705848 us. After: 1703579 us 1710640 us 1703625 us 1708699 us. Swapin of 2G zero page using brd as SWAP, zswap disabled (total time, 4 testrun, -3.5%): Before: 1912312 us 1915692 us 1905837 us 1912706 us. After: 1845354 us 1849691 us 1845868 us 1841828 us. Swapin of 2G zero page using brd as SWAP, zswap enabled (total time, 4 testrun, -3.3%): Before: 1897994 us 1894681 us 1899982 us 1898333 us After: 1835894 us 1834113 us 1832047 us 1833125 us Swapin of 2G random page using brd as SWAP, zswap enabled (total time, 4 testrun, -0.1%): Before: 4519747 us 4431078 us 4430185 us 4439999 us After: 4492176 us 4437796 us 4434612 us 4434289 us And the performance is very slightly better or unchanged for build kernel test with zswap enabled or disabled. Build Linux Kernel with defconfig and -j32 in 1G memory cgroup, using brd SWAP, zswap disabled (sys time in seconds, 6 testrun, -0.1%): Before: 1648.83 1653.52 1666.34 1665.95 1663.06 1656.67 After: 1651.36 1661.89 1645.70 1657.45 1662.07 1652.83 Build Linux Kernel with defconfig and -j32 in 2G memory cgroup, using brd SWAP zswap enabled (sys time in seconds, 6 testrun, -0.3%): Before: 1240.25 1254.06 1246.77 1265.92 1244.23 1227.74 After: 1226.41 1218.21 1249.12 1249.13 1244.39 1233.01 Signed-off-by: Kairui Song Acked-by: Yosry Ahmed --- mm/zswap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/zswap.c b/mm/zswap.c index 7f00cc918e7c..f6316b66fb23 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -1641,6 +1641,9 @@ void zswap_invalidate(swp_entry_t swp) struct xarray *tree = swap_zswap_tree(swp); struct zswap_entry *entry; + if (xa_empty(tree)) + return; + entry = xa_erase(tree, offset); if (entry) zswap_entry_free(entry);