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 CAB38D1A42F for ; Sat, 12 Oct 2024 03:27:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C8DC6B009A; Fri, 11 Oct 2024 23:27:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 478906B009F; Fri, 11 Oct 2024 23:27:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33FA86B00A0; Fri, 11 Oct 2024 23:27:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 1723E6B009A for ; Fri, 11 Oct 2024 23:27:15 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 58631AD133 for ; Sat, 12 Oct 2024 03:27:04 +0000 (UTC) X-FDA: 82663514304.19.DDF7D85 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) by imf03.hostedemail.com (Postfix) with ESMTP id D51D920002 for ; Sat, 12 Oct 2024 03:27:10 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=OHDb367J; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.48 as permitted sender) smtp.mailfrom=yosryahmed@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728703479; 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=nWTezJHR9Vq4+Q9HVaoXpPlGXcBP8rtz9ZwlcdC9EN4=; b=zzxOBYeil5+eirmKng7vlQ3fydDDsS95mU8nH6gwBdOesF6j5xzbOlYa13TNO9dVpv/if/ ZRmanphOgtpcXwj81o/lTz60wztH/MgqGqxml4ioQjnNZyBWM3mir4gb2n1AruoY3og7Fe Mm9fjNfNNFr5ANL4XpJ2kuhQLTLhqaU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728703479; a=rsa-sha256; cv=none; b=0EJnrbuFbQy23iz+3Oe6Po7mXY1V55lkoGj4m1/Rz2CTXUmEPbXXU2DGDWdaDV5X/CO+qx zOn/bwUrnI8sRHYyiycVYjln3qXzKUb5MgFIOgznNzFNjkqDSNusblId3glZ+5tQ5uf7hC mnYcRfn2VVydYH9BoieIwiccDJEcFUs= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=OHDb367J; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf03.hostedemail.com: domain of yosryahmed@google.com designates 209.85.218.48 as permitted sender) smtp.mailfrom=yosryahmed@google.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a99b1f43aceso311316466b.0 for ; Fri, 11 Oct 2024 20:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728703631; x=1729308431; 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=nWTezJHR9Vq4+Q9HVaoXpPlGXcBP8rtz9ZwlcdC9EN4=; b=OHDb367JHLR7ErpJ7v4aJfGdC8Ke02CnE76I19qZE8AhJL0qv88pg36K6JogKDBmrR WHZnimrC9/BWO4kgdwiUN3vM1rwpUrU4c9PsZ06UiHUJsXrH/WcUdnUUBr5e2WufFoUq f9yRjiV31ZasNbztWC/EbYKs2Oth3rE6W5Gz4cLLAwGIrx/Yntzx1M6hz5XSvR3hOKXn PBUnfq+a1kGfRhw9IUt9M88oLxrW+nYrC++dzWfjZ4My+BOvmXyTGYqhNsRLj6EaYZud vqVxsdvU/h38XYN9S8zMlshOyZVj470uSC9cyZmQsy7lLuaDZ7cEiYRIrC08iIMTGreb 8/qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728703631; x=1729308431; 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=nWTezJHR9Vq4+Q9HVaoXpPlGXcBP8rtz9ZwlcdC9EN4=; b=OGpCjt0ggU4TaHFTTrmWrdPZhxalta8RF/R+xPK2dU8DqQugryIlSCFU60Rkp+57EN LRaJHpu4QwrU27e1rCERhw1elIVMGibHLyK1KmQobwEYsFKg+NffqKaieKxzRDQmpKYD NInk7ocWsyCpcCyvMKaAauC5oD3ivGfrP3re2C0i51j5q6b6eY+NkE6KMdVSDILrBCiM yJ0/X4nZ08UccHU+rARBNfsk+PfAjWAhk4QR984m/ewJs7EPDd9y0eITMK8RLSAA5Ahb SJcKQSBJbB0epqDrdTz6zANyc9WBt6d+z+BdMbFxlSpUWl/+Iih+ly/SdWtIM8L6uitu 3EmQ== X-Forwarded-Encrypted: i=1; AJvYcCULsIPuU4Iro8vL6z6jTpnr91nXaD53W7MGnw01QtyKPKGCiM+a82gp+dExiMsnRwK376EK/H0FgA==@kvack.org X-Gm-Message-State: AOJu0Ywq5Th9hYlnxGjk1MbA7j9NxVbyAHb/KX1veFT7Zp/iNAS6JwKG JhWEyoJ8YNt2xY+CPQPE/msKy1Y4WBAihEFxUafY7wWJ/+1kcF5bLkxBRMcvhkydLD353TNyr3Y myS08iMn3K7aW5dyZNUqcqGjiz1K9dPH/18QC X-Google-Smtp-Source: AGHT+IFTZZoruKvDa4wWJWY4hwy38IqKlTFgrtJMgUvabVxU/vEEAu7T75+M5mSUOo9XTzDZeNZFdKP//gpGOey5wNc= X-Received: by 2002:a17:907:3e14:b0:a99:f209:cea3 with SMTP id a640c23a62f3a-a99f209cf34mr6850166b.11.1728703630697; Fri, 11 Oct 2024 20:27:10 -0700 (PDT) MIME-Version: 1.0 References: <20241011171950.62684-1-ryncsn@gmail.com> <20241011182831.GC351101@cmpxchg.org> In-Reply-To: From: Yosry Ahmed Date: Fri, 11 Oct 2024 20:26:33 -0700 Message-ID: Subject: Re: [PATCH] mm/zswap: avoid touching XArray for unnecessary invalidation To: Kairui Song 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-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: D51D920002 X-Stat-Signature: ftk8cpbwjsmwnsimmaqp8y7re6ztgbws X-Rspam-User: X-HE-Tag: 1728703630-944194 X-HE-Meta: U2FsdGVkX194cjxdkU/ldp8wdmYz4eMNSKdYJTgbZqqgAA+gcFM6CUemJKz+DKfuUlx5zOx3vZrWR5bS4kaqe+S+0I3nNrUJ95Pp6JkAwTBzqQ/QCylbLkgVtX8gIQGP6QLFkuimWtpui9VmrcZ6Z2eVTVl3ngW7xWK5emdDGnnRjuAuVvMS487M4hPKRF6BcY2Vx+EBL6upMJ0V51GWocJs7aQdCHZsiHN8wFqQHM6umCUXnsP5dCz70GkYOPnRMdTaI474PZgunGcGlZkdZfagA2v2WpFPmxtzz9fTuR4gFsj7Z1ivmfhczct1Lspd8n7sgrLPcpO6v0NWy6VrTlu5ICAfR78xev+hCtIHRnSeDzJq1DMEdwxBh1GR+AptRnIoh9EVENoGoXM4UYPbB9wUsQBFmMuos2XL+0N+x6mZM/VRd03z16Qs72eI3s0hnOGvqNkLHzAKSl07y5i+LmiQdRba96VU22k5RQ4Cc2pSwZnTw5LPQgcjxrmrBm381FEux6cxUFDxuUNmizW6u2EbjkqU8fXaVtooBqGbqex/DGvtHBCNfZZ3+7z4Yo/jYsZTE/49es8nptgbWB+VT3aKQGD8TpFQNxRUmE0FP2C3nRxVOQyAfOq7955QdlQDs8UuRt0/lIKwc+IJ1nWfLikyE9a96z+LZhVi4uiVPuqENQ2tYtFaRrdTi7toyWx/AQXwmGn6UbTaUTVSNYdcmT9KuNiBo5xLptka8u6cRr+UPNO43CTsZxLrZgH6eDJbS66s4adTC0GHdrdrAmsVBqCIdzBnTIsFI122pftx7ULsgOm5V60h6geR3Tz+eSzbFSCefYO2vEwzGGCj7rbU2naW8+RClMfZzheygu9dnrnVf54TuIk4R5iHLvJ7JcW5oS5/Gwi/HkjF9LVsdGG8aTGv1ZuAdtVVkhumCg+cB3T8i4lh+nepH3J3URdT9/9Z6vf0HbunyTcHQuFs3V4 2p1vMfQU FR4FZIpsM3VKuKMIZ/M40QvDTOZ+2tBWw6BszQ/GknLOuhY2du3CeKPCcM4plcpyZ54FxOZK9B6DbEf3YbP2WSSOkVHPP8IYNkPNlSqE8YYRyp1TpyBGLk/bx8CEMzZIwoKL2gC4g62UkoeU0etr98dfiprKIu/Zfw3TKoTDTQL0yktOoJrNrO/TsLvq//LIanVONOSs5/mDz+ZIxM84CbSNMC2OhUupSNFqhwHKpLmCLc+gcQ79eMZsX0k+3M4VJDsD1Cs6LxCuCYlvMvTQHewVVoQ0fzhLu5/9mCZqadNsco5Q= 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 Fri, Oct 11, 2024 at 8:05=E2=80=AFPM Kairui Song wrot= e: > > Johannes Weiner =E4=BA=8E 2024=E5=B9=B410=E6=9C=8812= =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 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 =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 performanc= e > 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 fin= e. > > 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).