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 585FBD1A431 for ; Sat, 12 Oct 2024 05:08:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A45EB6B0096; Sat, 12 Oct 2024 01:08:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F57F6B0099; Sat, 12 Oct 2024 01:08:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8BD106B009A; Sat, 12 Oct 2024 01:08:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6E0A06B0096 for ; Sat, 12 Oct 2024 01:08:56 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CAC551407C4 for ; Sat, 12 Oct 2024 05:08:48 +0000 (UTC) X-FDA: 82663770504.15.9DC8E06 Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by imf02.hostedemail.com (Postfix) with ESMTP id E2FFF80004 for ; Sat, 12 Oct 2024 05:08:45 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZPW4GXXe; spf=pass (imf02.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728709660; a=rsa-sha256; cv=none; b=Qck5ifVeJNmMOz0cyFBSz0EsIhGvk8cN6Qu8nNFDrV9EzAfhWl1+1McpRrQbz/qIdiU9X7 79WKhKap9jONNBY2BMBpHJyuPntQjEvF0vMGEQnK3PDpjo7BnOs8jyaMSU5n+ar2WNJYY8 cWst9MYLNkaEVM5d9TYQarOAA/yfn+A= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ZPW4GXXe; spf=pass (imf02.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.208.176 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728709660; 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=JNtdbvyx4u7PmRsUXDr0pbN27HikJwX4DWxT/0fngAg=; b=E8Tw4kLkjkNqpy+N+3zxkM3oveprh5MdV/VmunOLGX8UFdD+MWCgbYoHhhaBDTEurVVJvl OKjCmV4CMY7liYb5wKWfk6uDMYwmFyUa2v1GFJ22e0EBcG2K3qO08guLecABrhT4s5MgtH WPo1gq9GHc6aRZACDFRmOMXdgiZVEVc= Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2fad75b46a3so26231201fa.2 for ; Fri, 11 Oct 2024 22:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728709730; x=1729314530; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=JNtdbvyx4u7PmRsUXDr0pbN27HikJwX4DWxT/0fngAg=; b=ZPW4GXXekyBDJMqR8Xyttu1xXC7VlBB8kh1fdkRJLzBpkn4LH2DEdU2anHko85Nudo 6/KzjHQGQFDPBACnmn63j2dpu95qgVAVrCsPXLVYZJ+gT62DGK4Ju+HXaaw0UfLy/w64 tESkfqvx3fFFYvSvvOG+9z+tc16SiV7xCV4LBwh3W834DY8eFAQYJ65OtrfjuEBMXS99 NrMPjQ7S7jQA1sMAfCYiEuxU7x0r8zWvCGb4eitj3R8R4NFsKPeiIHu5T5XGweUNDq7q AyrfBquRCVdEOYeVRblj17fOa0WoNgeXx7kKnqxDrd838yVMnCnNKfUyFdp4OFZO4X+Q Ifyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728709730; x=1729314530; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JNtdbvyx4u7PmRsUXDr0pbN27HikJwX4DWxT/0fngAg=; b=lO6kmApkOU+yT7DINVFH4/gVAPLvvRsq+hpc4UiGxRfeBqrTSpvcBUfL/W2YadHMYY jt5w2e+CWhQFFthazClpXSA9Y5lG2Lw6qx9ERNBQnoX9fa/PpLzjXFDwSCHCLGQl9Z+w YZ51G8EkswMuDJgzB+fnZAND8LI3Gg3RBH2g/c3uL4rrRjDbZ7fZaeDsEHjhKVrnCuM0 rni6UhGXSWRqzVv9ydpwbHvoWi2rnBw2dc0ZnhOvcrPvByyQt7mz99FAcxtB57/6pCSr uHMt0YhpEcVkEDj5Kks6C/w28VTFFD95o22TmpX0naKKA2ANcXkm4i8KgFUF7bg1grCm h9pw== X-Forwarded-Encrypted: i=1; AJvYcCX11d6FEx5Nb0aPtiWTAcl4Ur92JEGIbY4Q1dTdJHggE6YYrdws59+AgPGvqZ6cVjR7aYrfgnspnQ==@kvack.org X-Gm-Message-State: AOJu0YzWZprAkdlTBXTUD1Wy+sM4FdDr5g+FZXlyi/rMz3RNkcWtlHWo DCC+Ua4VivU9MhzNNPnfENcImq0a4vybtE7jFGQQV1YtEJbMtsH84NNnZce8UMwa3g2g6M5m1u2 NVEgeFe2I7bsJAS4GSnk2oH/z6LI= X-Google-Smtp-Source: AGHT+IGrs/xVb53uh/iaB0+AM1qJ9DJ+UtjgSlB1WMXrx+bbJdDfv0kPbGzsYVBhu2SEMs+6REzBiNgrUsGDNQG6kqo= X-Received: by 2002:a05:651c:b29:b0:2f7:4e8c:9bfa with SMTP id 38308e7fff4ca-2fb329a79bfmr19302571fa.33.1728709730030; Fri, 11 Oct 2024 22:08:50 -0700 (PDT) MIME-Version: 1.0 References: <20241011171950.62684-1-ryncsn@gmail.com> <20241011182831.GC351101@cmpxchg.org> In-Reply-To: From: Kairui Song Date: Sat, 12 Oct 2024 13:08:33 +0800 Message-ID: Subject: Re: [PATCH] mm/zswap: avoid touching XArray for unnecessary invalidation To: Yosry Ahmed Cc: Johannes Weiner , linux-mm@kvack.org, Andrew Morton , Nhat Pham , Chengming Zhou , Chris Li , Barry Song , "Huang, Ying" , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: shh8f9dnmy1xk71qkjxy4mtfcayrskdw X-Rspamd-Queue-Id: E2FFF80004 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1728709725-753423 X-HE-Meta: U2FsdGVkX192apYCJpoRzfT8SfbxbhE15fL/yOJiCUmM65j3aJYmaO92/f+Q+2C++fwSQbxefJ2KK6p1syWsyieghCCLLMApb3rwNWI4WkygZpUO8p4xsvzt0mOd3i6i0DEnBo5tuRgr8mYBtbQ+8uwZBWtZxa5B5+bZGPjz4V4bDjz4B6YrdNA7uvqjmKM3MYVhYmK0GLi+SL6E/jCba6ujhSmc1YxshVcE1wFr2boMqQFo6Wfs11acZBgeE5eZ24lZRjkv4hfrPNe1Xo3C2UmaexG0kmoqHOLfCQaULgMo0lwM7gCT3bhXJg7rw+QwIQCQ8MOKZj5j5CaLxf0cypF1dATi/+I9wqEFqoXeLP8Bg1a0VWwJPTZbpYA5JAAGy98EzwZER2xB21aLP1/xVT0Xu9gSMW8lXCGEJbiuFp3XM826sHQx7orw7nTG2ujo0pm4MUokhDI4SkNGcw6/e2yN/4GnL2oPvVgi3x+tIJ4UBBUAAT2cOfCadrOA+Ql5n7Gsd2RIechR8dbPPnfe1yi2aa4Orj3+wgyaao5I0h3HGpBt6tjNkNEMrTinIWLcnv9SGB884grNvwgs1WwFpRk2lruyejtQ9+7hDcmNyvtnq6HK/zlkmhB41qLFdyfAG8Yu1P61IQL74LabDI+Mlk9lYVsNrwqJ+bFLo1d+4D7wYaGYHGzjbYMMOzlFye06uEj0IjUTAqA6/zKtl4OWhxboYPTO6bv417Z8LBvTBDT05zcj8+Knk612Y4uKtkaIKZameYp+pj0FDH7lS1iBaJ635+flz0Q81af5EWxC5ly1XJdYgVLfnzbgl0jUhvyps1h2zE8cQMh3cLEMRrUbuCzsZ4C8HnfSzdPwSlxhVu6ycYcoguHR99KuFiQWB2xoaEYPC8G+YJ5W7jXuYDwLvql3VngZnry496KEAcGEqW0ewVD7kGhj+XlvOS+jQ/3WJr84nxnf1Q5ywXOhJTq sDyBNqc4 k2G8JnIW5BhAhaenAb1B5VBQ6bkwavA/V+J/28ZBc55L43Ak3cF5CK1lk5i7Ta4JetI+1OcR/l9ZRCeeVpTZImPhMCwGrsLXVHxtCPX5Sdn7cP4oXZW4JIg4Y3lT92pawkK6+IgywGuh8IBPQxtXDymY7LgP7mx94kxCb0YXdAnsLEIawktKSym7wsrbLwlUDSAlYbVOSSS2muy4OQJ+2XR+aQvVWZbGlmCxFTHooMvzrvKWt+DGkWxHMCkTgterrZ/Ywfm25bzy8rGIDG4p9DnqGV42DsQYKOa2ZORvAP9eGGokg/3X69DX/IMjhaxopwsUbWyzp4MEMVMaMYb5oW2XzQR08ngPFhj1VIm53m6De7u9GgJ/s5dxrdaplsxtiGlRqNGetQxvTkAO92M8rD3PQQEcCJWnTqD0sG4Oe5+UeMW8Tao7hFPrpxClbPfhNL6B+ 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 Sat, Oct 12, 2024 at 11:27=E2=80=AFAM Yosry Ahmed wrote: > > On Fri, Oct 11, 2024 at 8:05=E2=80=AFPM Kairui Song wr= ote: > > > > Johannes Weiner =E4=BA=8E 2024=E5=B9=B410=E6=9C=88= 12=E6=97=A5=E5=91=A8=E5=85=AD 02:28=E5=86=99=E9=81=93=EF=BC=9A > > > > > > On Fri, Oct 11, 2024 at 10:53:31AM -0700, Yosry Ahmed wrote: > > > > On Fri, Oct 11, 2024 at 10:20=E2=80=AFAM Kairui Song wrote: > > > > > > > > > > From: Kairui Song > > > > > > > > > > zswap_invalidation simply calls xa_erase, which acquires the Xarr= ay > > > > > 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 =3D xas_load(&xas); > > > > if (entry) { > > > > xas_lock(&xas); > > > > WARN_ON_ONCE(xas_reload(&xas) !=3D 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 ( =3D=3D NULL ) check, so unsurprising it has better performa= nce > > than xas_load. > > > > And surprisingly it's faster than zswap_never_enabled. So I think it > > could be doable to introduce something like zswap_may_have_swpentry as > > Yosry suggested. > > That is surprising indeed, but it is cleaner anyway to use the xarray > check than the static key. > > > > > 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 think having an additional xa_empty() check before xas_load() is f= ine. > > > > > 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. > > Is this with SSD swap? If you are using brd, it bypasses the swapcache > so the benefit from the xas_load() optimization won't be much visible > (see my earlier email as well as Johannes's). Hi, I'm using brd indeed. This test is trying to show the zswap disabled case, so I think swap cache has no effect here? For the zswap enabled case I do believe xas_load will work better, I'll add some test info in the combined V2, will test some other workload with the brd SYNC flag removed, sequential swapin with zswap enabled have almost no performance change with this commit.