Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp1330498lqt; Tue, 19 Mar 2024 23:34:32 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXHEH2BTnI1TIOzxbBjPhCzpAepdxj5VUrtZujgLOYm1pxdiQly+5iuMLXVMpWvyTYfhnbLGzUQLbI8KMZjDlEUkLn/SaT/zGfiutRqIw== X-Google-Smtp-Source: AGHT+IHWiwxhV8Vc7zS77MuEjQLzT7voZmNcd75wlgbkn7uEDgxBiOJGlzx8Y5jB4ENEu04ihLd1 X-Received: by 2002:a05:6a21:7883:b0:1a3:52a6:4054 with SMTP id bf3-20020a056a21788300b001a352a64054mr6000058pzc.0.1710916472424; Tue, 19 Mar 2024 23:34:32 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710916472; cv=pass; d=google.com; s=arc-20160816; b=0xZupEgr+Zpqc29zCzKTtiyVRNAxZ/S554rFhrEkPrOMtQynChQg0mjuuZtgvB7GjR OqBC9+pUyLkYrs9iGVce+B18Iqpj4sM8ooCuHqKiyWRmr0WKfwb0i8epn6tVkY6HsdnI 7bxe2m5v1OFhqQttWCd5G4KFzjj8oZmRDnO5R1OQKvWBNPXSYtkhi+OUVavg/u7mPIug fW/L2GWaiXoXh4omGsI29UpCJMGZ8B++DjxwSEVi+Mk3cudP6ZqwUcjn/9TOUuvV8Kps FmugT7rtWpA7bskxezPJvPGa1dD+JCMfVdbncARAmIRxbNv7MkBs2+USZPRO9JvcBwQe l3hg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=oCWXQdf+IUUP11XZSalfvfImB6cqc43jSDmQ6B/rGT0=; fh=gkDZCtfqnm8QgM/pA+8T8wJOPBiDMmZ8+j0mGpzhrvw=; b=t2NpnW0rHXa0SDNwPT6T/hDuGChpvW+pu+tUkNAXPL4xraXTUu49H+sY03OoxCzXns T3UKOJxV6RApAgcUZqXvQShc1oZnFtzgRFabf/gUa6Og2pKqD/taxSmwsEOLAg9xM/Kd zJ8ZMRqSjVWXcaTWeJbojQENYhWQ4y9BINJqceIPH7DURVC3ZP4tq8GPADV71I/NVa3M EPkUDm0nT6IZXZgulERUuq0r2tV5SEFI2gij7GyBqnYmt1sP0DLnasIoPdUXlagLakaX DhFV1MQwQpqZr1P9/2bp3oX/WGHP2gkAWOHFOcezubkRO3PaE2f2JiwscmnMqOUtBSgx Ab3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=czpL0F2d; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108498-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108498-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id hi15-20020a17090b30cf00b0029c74535d74si819830pjb.35.2024.03.19.23.34.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 23:34:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-108498-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=czpL0F2d; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-108498-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-108498-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0FE1D28387A for ; Wed, 20 Mar 2024 06:34:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83E12ED0; Wed, 20 Mar 2024 06:34:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="czpL0F2d" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 98C157FB for ; Wed, 20 Mar 2024 06:34:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710916465; cv=none; b=Q7nk6XUCD/w35MQZMRL+XwIaIn+g5aYOYefcWIZn97DKDmlnFS1qoxe5nRPdRXYO8BpxVh1i9u6IH5qUS01qGqrUIDxkJTnFu/3zQWvempz/CxrA26vr5p9lfXup5UnzjCCBc7oJsPp5KLXdoqquYdkRRIbhfcArSbjgJ7Sa3Xc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710916465; c=relaxed/simple; bh=8YIsJhztsQo4cn+hAiQEWTFMgbIPhMPSRmYKdPK3qFA=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=LrqkVzs3yfK/AtqUFdh9NWul7q0QwGIl7v3M/0HSSeRXfVj8Li1F4e1DTkKbM0VJ+Xk+ObScTzQ/DJe9O9RG2cESX/eoeIDI17t3DnJhnSYk8PbAJmFEyR8XbD1I2eBeHr/vRIeMDhVdNsKbg+b1hXIn6XqxU1RCAOSreeG7eNc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=czpL0F2d; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 383C1C433C7 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-f177.google.com with SMTP id 38308e7fff4ca-2d109e82bd0so85156051fa.3 for ; Tue, 19 Mar 2024 23:34:25 -0700 (PDT) X-Forwarded-Encrypted: i=1; AJvYcCXCsAJxSFQ5o1rJ6cUvyjPCOB9HT8Nnc8npAkwOfbO6VCnGLLnksRXWn3PISjBvPYKgOu5xU8nOB3E7VA6sNdt2rjhW2hAQIDcNM4cG X-Gm-Message-State: AOJu0YyO+BaprA0v1JOsE/s7N3cHlsgrT6LBkAPCvL4hIMf6Q6kvd5tD ywgu0Z+dFXIsXF4YhpKoQqc/JLQVWRF4QXpJCptvcDiimjOTzvaycn+9mp8620S/i8tNQXr60QN Du7EDY7f4ZUnvwpYn4UeFMZw63w== 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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