Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp789708rdb; Thu, 18 Jan 2024 21:24:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IESnouxrJLnBayeQpBqOa/sD2wQ7k6HgHvIFl697OanZMDKD6+6v3Q2tz6M8vdgSpAAC7FR X-Received: by 2002:a17:902:a38c:b0:1d4:814a:1cf5 with SMTP id x12-20020a170902a38c00b001d4814a1cf5mr1754332pla.133.1705641876843; Thu, 18 Jan 2024 21:24:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705641876; cv=pass; d=google.com; s=arc-20160816; b=WSGbTsZ6oCz/LotE5PzZ4Wfi/CsbDPrhI1lUj1DUcap62jturEUaxtk/aCXaZOgiiF HrzlLuq7jl+ZXpWPWgUd69Y9AW2fEi8vCA2LLwzM8YZ44uzhw5EkLiOzjdnwpF+STj0M zurSHGUmtEFwWYSCdRzK+vClxLq8hrdlXc5gyRlyEIMKalmVAi14V6v/K4CcIceFe3n5 zFE3s9vN9mYd2kIMowizrQQZyya6Mq5x9RRjCM6uWDK5ntiMJ9gcY5qAf3H9+CX8FjDl HEIdqqC3xq96PYewAVFVcVW2MDT0iFN9JUJUoHU13Ept3TQmogk56fzmoYM1sk9aYIZW hbQw== 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=KteYCQ1LJOjfYMpx1yHyXYywQeCphWRgAkGfNYm82As=; fh=3G+LrlaXkaxjxsos+peGn2UxPridobGTAuxKHlBj55Y=; b=irfft/dTGpQGdjXYL5DICY94+f921Hz0P3PE42QBUMVYyPUJua7EVPbm4meeqgs2LW uLZzM6Ib4fvKkcKdWPHdGIgsOTDOQGjaDB5+zJoR4qsD8wzMSieNhbj6VenXFQKRyutd 6g7zlawOvfANTbjkrvEOzcaM2G4CV9mmgaHb3wX2wmCBmDhXJs4bbQgXumCGMHD/Ir+W F9z/W/P8loyNVGtkSKbRTzGTx/Y0A6m8F5H8Me9nlUlbwnUChAAigkdePeSpqKAt/ylw cTbMkXzBJNMKVggGxKdaEcGyYq8Tl55ld/OHvNq2CeqomjHIC56VAr5E5ESLmvG+6UhT Vtyg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=cQLfISwg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-30773-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30773-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 h6-20020a170902748600b001d5f25f90d4si2636954pll.72.2024.01.18.21.24.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 21:24:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30773-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=cQLfISwg; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-30773-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30773-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 75C05284F31 for ; Fri, 19 Jan 2024 05:24:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 096EF4A12; Fri, 19 Jan 2024 05:24:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="cQLfISwg" 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 27506469E for ; Fri, 19 Jan 2024 05:24:28 +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=1705641869; cv=none; b=Nq3hzhyzAYM2jqnwbJGwAL31+99ycR3CjJ4PBA8lth8G26VcnfF5HBg7DQHdznGGu3L/tBAVqzIqhq5TdzWDLPmzsLOZ71FqfDPCsa5HFpJId7hkwmSBRKvL5FbJSS0xlQXms1oxLz0sedaVhlIF1ldKpykQIZfjtX6U3luPj+U= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705641869; c=relaxed/simple; bh=GZXH9M4vRYlIBKd2B1NBqugB5mUzmY+xYn4wpQol9Co=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=N7gQBZxlr5JcQklUJiYL7+SHnkFi5zsSJitgBaZRUl1QyKt1Gj3+O/0W/W7RvbpGdhT/mdiivQJhPNr97/djKghnQVG+FmFjecLUtqHb76WEhSdnQ9I/QwIBjofnwovx3+h0da0GIz/9lOp0s9zUXkRQAp4bVJbWq5i3rk6Ep6Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=cQLfISwg; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6CBEFC43609 for ; Fri, 19 Jan 2024 05:24:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705641868; bh=GZXH9M4vRYlIBKd2B1NBqugB5mUzmY+xYn4wpQol9Co=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=cQLfISwggyTHG7Wu7DGoNQtD4oeFqTAFtiDX8sdQzlDop8PZp5eUSB8mtNCV9TgOy 1KaUFy7UBDl4XFXk4VexgOhn+3+I2EfbYWX/+NfgLmaPhSmY53iCbttzrlrWYSwLbP tZ4ATuPP+jZSKRLtwp4NCqYAF/Xf2LTWilQEWQdVwU/ZHhpLX1jjAfTGIlisnDB970 sZkSyD+wq7i9oLMMS62pMM5hJhWHQHgiwKFRNPS1CbjTNra6wJWLQ/sS3jXrO+dyaa 9KT5V/KjK9dQHR20MtdtCATT93x1H3aK6ohSB9GrkKRlTtSZ66AVk5x2bcknAv7uoe liC2DbrXA7NOg== Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-28e724d9c47so310886a91.2 for ; Thu, 18 Jan 2024 21:24:28 -0800 (PST) X-Gm-Message-State: AOJu0YyWLOj91twBa7UrqfQHjIrRlf1SLLcIwA5pPBO2lg2PqkzNJE3/ JfYvKjOHozslbPsJJvOxIj/SemDyDskkh2rQmunjcJHbR48mtJX6iWd6mD/rdmFGw2iS+hEmt3t 7pHYILsgp2VTGAfARTiAOz6yXcfsGATZKWoM3 X-Received: by 2002:a17:90a:b00c:b0:28c:a722:c587 with SMTP id x12-20020a17090ab00c00b0028ca722c587mr1638769pjq.42.1705641867801; Thu, 18 Jan 2024 21:24:27 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240117-zswap-xarray-v1-0-6daa86c08fae@kernel.org> <20240117-zswap-xarray-v1-1-6daa86c08fae@kernel.org> In-Reply-To: From: Chris Li Date: Thu, 18 Jan 2024 21:24:16 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] mm: zswap.c: add xarray tree to zswap To: Yosry Ahmed Cc: Andrew Morton , linux-kernel@vger.kernel.org, linux-mm@kvack.org, =?UTF-8?B?V2VpIFh177+8?= , Yu Zhao , Greg Thelen , Chun-Tse Shao , =?UTF-8?Q?Suren_Baghdasaryan=EF=BF=BC?= , Brain Geffon , Minchan Kim , Michal Hocko , Mel Gorman , Huang Ying , Nhat Pham , Johannes Weiner , Kairui Song , Zhongkun He , Kemeng Shi , Barry Song , "Matthew Wilcox (Oracle)" , "Liam R. Howlett" , Joel Fernandes , Chengming Zhou Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Yosry, On Wed, Jan 17, 2024 at 10:21=E2=80=AFPM Yosry Ahmed wrote: > > On Wed, Jan 17, 2024 at 7:06=E2=80=AFPM Chris Li wrot= e: > > > > The xarray tree is added alongside the zswap RB tree. > > Checks for the xarray get the same result as the RB tree operations. > > > > Rename the zswap RB tree function to a more generic function > > name without the RB part. > > As I mentioned in the cover letter, I believe this should be squashed > into the second patch. I have some comments below as well on the parts > that should remain after the squash. > > [..] > > > > @@ -462,9 +463,9 @@ static void zswap_lru_putback(struct list_lru *list= _lru, > > /********************************* > > * rbtree functions > > **********************************/ > > -static struct zswap_entry *zswap_rb_search(struct rb_root *root, pgoff= _t offset) > > +static struct zswap_entry *zswap_search(struct zswap_tree *tree, pgoff= _t offset) > > Let's change the zswap_rb_* prefixes to zswap_tree_* instead of just > zswap_*. Otherwise, it will be confusing to have both zswap_store and > zswap_insert (as well as zswap_load and zswap_search). How about zswap_xa_* ? > > [..] > > @@ -1790,15 +1808,21 @@ void zswap_swapon(int type) > > void zswap_swapoff(int type) > > { > > struct zswap_tree *tree =3D zswap_trees[type]; > > - struct zswap_entry *entry, *n; > > + struct zswap_entry *entry, *e, *n; > > + XA_STATE(xas, tree ? &tree->xarray : NULL, 0); > > > > if (!tree) > > return; > > > > /* walk the tree and free everything */ > > spin_lock(&tree->lock); > > + > > + xas_for_each(&xas, e, ULONG_MAX) > > Why not use xa_for_each? > > > + zswap_invalidate_entry(tree, e); > > + > > rbtree_postorder_for_each_entry_safe(entry, n, &tree->rbroot, r= bnode) > > - zswap_free_entry(entry); > > Replacing zswap_free_entry() with zswap_invalidate_entry() is a > behavioral change that should be done separate from this series, but I > am wondering why it's needed. IIUC, the swapoff code should be making > sure there are no ongoing swapin/swapout operations, and there are no > pages left in zswap to writeback. > > Is it the case that swapoff may race with writeback, such that > writeback is holding the last remaining ref after zswap_invalidate() > is called, and then zswap_swapoff() is called freeing the zswap entry > while writeback is still accessing it? For the RB tree the mapping is stored in the zswap entry as RB node. That is different from xarray. Xarry stores the mapping outside of zswap entry. Just freeing the entry does not remove the mapping from xarray. Therefore it needs to call zswap_invalidate_entry() to remove the entry from the xarray. I could call zswap_erase() then free entry. I just think zswap_invalidate_entry() is more consistent with the rest of the code. Chris