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 521BEC54E58 for ; Wed, 20 Mar 2024 06:34:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C19676B0098; Wed, 20 Mar 2024 02:34:36 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BC9D36B0099; Wed, 20 Mar 2024 02:34:36 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A91A86B009A; Wed, 20 Mar 2024 02:34:36 -0400 (EDT) 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 989936B0098 for ; Wed, 20 Mar 2024 02:34:36 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 6555E1A0BBF for ; Wed, 20 Mar 2024 06:34:36 +0000 (UTC) X-FDA: 81916453752.17.A33F144 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf04.hostedemail.com (Postfix) with ESMTP id 0329640010 for ; Wed, 20 Mar 2024 06:34:33 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=czpL0F2d; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of chrisl@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710916474; 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=oCWXQdf+IUUP11XZSalfvfImB6cqc43jSDmQ6B/rGT0=; b=4v2mCvgz3DArZ/th1hn6Q9Uzh1FcHciE/DfWo8tqZIqi4SGAZ/7UYivUU5NkV5XULp+ESA L+Twzv10FkaOjN8t/Keei0z9Tx904XypxPF1anoHYYo3oWMeoPscMT0QXeu6IWVGJu3qrG pbC+ZwjyH2wRZe+71iPIkBvW9TLAxEQ= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=czpL0F2d; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf04.hostedemail.com: domain of chrisl@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=chrisl@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710916474; a=rsa-sha256; cv=none; b=6ZoNc5h6H7WN0V6zmDY2U/sRq76RrAe0hFveOpzpJZFDYm2a+KTJrkCzAmwuM2s/adWF8J gXDYpSOM2Fy2XEVhgRJHKG13s3Lf6srTw2U2N5NJ2Mj5Yfi9HrsN8j8Zl2eJPkK17ca8xE G50d1UuCeEb1DrLcj28i+/FQ2DSxtps= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id A95D8CE1071 for ; Wed, 20 Mar 2024 06:34:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66B10C43330 for ; Wed, 20 Mar 2024 06:34:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710916465; bh=8YIsJhztsQo4cn+hAiQEWTFMgbIPhMPSRmYKdPK3qFA=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=czpL0F2d2Hd2etmc/VPeVMWnDVPTEXWI4QiUzE2meqhqN9m5J48bb8T6kpmbfS03g Xz7kChQeqPSj+Ros32TFCVxyaJNkt00pI6oo8KDSAli78foTkKFaFZidzuzEqaa0Ey bg8dO21QYVNTCcbRupximb8LT1PkpFWfIH0mLgDEhGd+QvWX9OT0vNoH6eMEYDMB3C tgNLbbyJsoXA6yAgBEnyWRKRZWncO6xfS6LkMS7hIoeoKmhdrL3uvr1TN6XdgUrsUA K2/IUAOZxnorlYWg1CCuDgdTSbXJgUk43SbJN7qZARuTyJ7CDeEgYJiK94SM4J13sZ j/Fji4eZokX7A== Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2d109e82bd0so85156031fa.3 for ; Tue, 19 Mar 2024 23:34:25 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCVzwgGd2nS8W8DDwRxOdVSjKXi7kfg5Qi63mAFbrZwNeCZU2uvbRosrZMpI7k7EgVSnteua3UXwUvDAcp7v5/YlJj4= X-Gm-Message-State: AOJu0YzbWUQGb2/liZ6+5LpoDcYmMVCD62Y8ypBUPyDkP5BXc1NF3zUG mJVUHIGkDNGo8ekrFxwEr9aVETaybvClvzQqbJYVQQdCmaWPlw9DxH2mqr8Fl3HQBp0Xko+sFfP 8zZ6FwV4DRDgRuK6DTEFyEwIaCA== X-Google-Smtp-Source: AGHT+IGJ6/WTNTLkpCgBE1HGeVyLIaTs55r9cXEfvXhnpD34wDATWmklKNEPBCa8Yb9gfgnWgEhFob9fbm3DOe0H41U= X-Received: by 2002:a2e:9093:0:b0:2d2:6608:3d05 with SMTP id l19-20020a2e9093000000b002d266083d05mr709889ljg.52.1710916463813; Tue, 19 Mar 2024 23:34:23 -0700 (PDT) MIME-Version: 1.0 References: <20240319-zswap-xarray-v7-1-e9a03a049e86@kernel.org> In-Reply-To: From: Chris Li Date: Tue, 19 Mar 2024 23:34:11 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v7] zswap: replace RB tree with xarray To: Yosry Ahmed Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Nhat Pham , Johannes Weiner , "Matthew Wilcox (Oracle)" , Chengming Zhou , Barry Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Queue-Id: 0329640010 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: nt6yongbc9jpenaeg8bdamept38pipep X-HE-Tag: 1710916473-102179 X-HE-Meta: U2FsdGVkX1+y2HXysXuvjsFLUfEabHR4PJdtZbdmtakSNW/ZrUphi8Aahif/RXj6QFBXCllY5VQ4TnurbPKokVta//Nlfn8NUNxC3vXrtEHBmoSesU/hnfNa1dobxLB6pc/QOSp0O9rPLVX1hstTNjqW0b/celE5HWwCBZWWpj1JtCFJ+01ZvlG6jQGtV8cZJku1E6DfflUUFpAUi7gTKfasauwnK/bbn5O1u3u7VDF6hKAekl3x5tbcIVkMuP27mctZ4ETg0U8/QZIHdGFXTxNusXXjA2JyEffdKFvMUouT11QtuzpvBZzW3u+fsvOXO57jrHRZ4LJ2AHFwus9KtQS1Od61u+eBCHUIujtyJ1aUtXc0giTeJvHRPpboFIT8UFMY7yiugrM+AOtQdWIfb6gymh67FJwcpEVNRfzrtE2o/rSsB8hngJp/KRm0tCtkqLDKQJuAMuhkaZhn9odYx2wdKPL6GrrZoD/09FQn/umtlbtdNQpdvhzm0YN3SqwDDcg7lR7v2p/VUUP0+HqjAXzMq+waP/SaTRgvacFPP2Atygw39PAQDyeNzVQeDz9oVuPg5ajNoXP6Hu9E7DxDU//ryNjNu0bhHKnKgjClWrYNY2AXpDMRJVnFlR+61Yj1Ihv8OYyqJuWqxYvvS3Hy/Bp8gD2cztb7TWMw5e9EoQ5X9Tdt/4lFskZCu3bOzZPsTdLVz4s4TupsjmAYZXfvAmLhl7jg/joI+tPYw4G9447Yd46zyf9a9bNy4uMqM6sqiDm243o1bP9UIZ/Vj+VMW3EzJzSKRLLLkV4zx0LewQn43rLHuhDN1XB8dJjTDSlWI8Xhxw7bZM0GOkoj7xfLuHBiokzgJCu5lGH/g7p+hPO+0OwUNG6YJzlB0MC81Mj3UeLJv5FRUq6jWlIKQL2il4PXk6EnMymG 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 Tue, Mar 19, 2024 at 11:13=E2=80=AFPM Yosry Ahmed wrote: > > On Tue, Mar 19, 2024 at 10:52:26PM -0700, Chris Li wrote: > > Very deep RB tree requires rebalance at times. That > > contributes to the zswap fault latencies. Xarray does not > > need to perform tree rebalance. Replacing RB tree to xarray > > can have some small performance gain. > > > > One small difference is that xarray insert might fail with > > ENOMEM, while RB tree insert does not allocate additional > > memory. > > > > The zswap_entry size will reduce a bit due to removing the > > RB node, which has two pointers and a color field. Xarray > > store the pointer in the xarray tree rather than the > > zswap_entry. Every entry has one pointer from the xarray > > tree. Overall, switching to xarray should save some memory, > > if the swap entries are densely packed. > > > > Notice the zswap_rb_search and zswap_rb_insert always > > followed by zswap_rb_erase. Use xa_erase and xa_store > > directly. That saves one tree lookup as well. > > > > Remove zswap_invalidate_entry due to no need to call > > zswap_rb_erase any more. Use zswap_free_entry instead. > > > > The "struct zswap_tree" has been replaced by "struct xarray". > > The tree spin lock has transferred to the xarray lock. > > > > Run the kernel build testing 10 times for each version, averages: > > (memory.max=3D2GB, zswap shrinker and writeback enabled, > > one 50GB swapfile, 24 HT core, 32 jobs) > > > > mm-unstable-a824831a082f xarray v7 > > user 3547.264 3541.509 > > sys 531.176 526.111 > > real 200.752 201.334 > > > > --- > > I believe there shouldn't be a separator before Rb and Sb below. Ack. > > > Reviewed-by: Nhat Pham > > > > Signed-off-by: Chris Li > > I have some comments below, with them addressed: > > Acked-by: Yosry Ahmed > > [..] > > @@ -1556,28 +1474,43 @@ bool zswap_store(struct folio *folio) > > insert_entry: > > entry->swpentry =3D swp; > > entry->objcg =3D objcg; > > + > > + old =3D xa_store(tree, offset, entry, GFP_KERNEL); > > + if (xa_is_err(old)) { > > + int err =3D xa_err(old); > > There should be a blank line after the declaration. > > > + WARN_ONCE(err !=3D -ENOMEM, "unexpected xarray error: %d\= n", err); > > + zswap_reject_alloc_fail++; > > + goto store_failed; > > + } > > + > > + /* > > + * We may have had an existing entry that became stale when > > + * the folio was redirtied and now the new version is being > > + * swapped out. Get rid of the old. > > + */ > > This comment is mis-indented. Ah, there is some space instead of a tab because the comment was copied from an email. Will fix it. > > checkpatch would have caught these btw. > > > + if (old) > > + zswap_entry_free(old); > > + > > if (objcg) { > > obj_cgroup_charge_zswap(objcg, entry->length); > > - /* Account before objcg ref is moved to tree */ > > count_objcg_event(objcg, ZSWPOUT); > > } > > > > - /* map */ > > - spin_lock(&tree->lock); > > /* > > - * The folio may have been dirtied again, invalidate the > > - * possibly stale entry before inserting the new entry. > > + * We finish initializing the entry while it's already in xarray. > > + * This is safe because: > > + * > > + * 1. Concurrent stores and invalidations are excluded by folio l= ock. > > + * > > + * 2. Writeback is excluded by the entry not being on the LRU yet= . > > + * The publishing order matters to prevent writeback from seei= ng > > + * an incoherent entry. > > As I mentioned before, writeback is also protected by the folio lock. > Concurrent writeback will find the folio in the swapcache and abort. The > fact that the entry is not on the LRU yet is just additional protection, > so I don't think the publishing order actually matters here. Right? Right. This comment is explaining why this publishing order does not matter. I think we are talking about the same thing here? Chris