linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Yosry Ahmed <yosryahmed@google.com>
To: Chris Li <chrisl@kernel.org>
Cc: "Andrew Morton" <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	"Wei Xu" <weixugc@google.com>, "Yu Zhao" <yuzhao@google.com>,
	"Greg Thelen" <gthelen@google.com>,
	"Chun-Tse Shao" <ctshao@google.com>,
	"Suren Baghdasaryan" <surenb@google.com>,
	"Brain Geffon" <bgeffon@google.com>,
	"Minchan Kim" <minchan@kernel.org>,
	"Michal Hocko" <mhocko@suse.com>,
	"Mel Gorman" <mgorman@techsingularity.net>,
	"Huang Ying" <ying.huang@intel.com>,
	"Nhat Pham" <nphamcs@gmail.com>,
	"Johannes Weiner" <hannes@cmpxchg.org>,
	"Kairui Song" <kasong@tencent.com>,
	"Zhongkun He" <hezhongkun.hzk@bytedance.com>,
	"Kemeng Shi" <shikemeng@huaweicloud.com>,
	"Barry Song" <v-songbaohua@oppo.com>,
	"Matthew Wilcox (Oracle)" <willy@infradead.org>,
	"Liam R. Howlett" <Liam.Howlett@oracle.com>,
	"Joel Fernandes" <joel@joelfernandes.org>,
	"Chengming Zhou" <zhouchengming@bytedance.com>
Subject: Re: [PATCH 1/2] mm: zswap.c: add xarray tree to zswap
Date: Fri, 19 Jan 2024 11:29:42 -0800	[thread overview]
Message-ID: <CAJD7tkY6K8q1t-nzZ7oJu-f3OgS654PiOcQgU=E6f+0joYSzPA@mail.gmail.com> (raw)
In-Reply-To: <CAF8kJuO5tAqwyKQK7AasWgs3Ohfc2osD9oX0m8YAkfsAZsjjyQ@mail.gmail.com>

My previous email got messed up, sorry.

> > > @@ -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_* ?

SGTM.

> >
> > [..]
> > > @@ -1790,15 +1808,21 @@ void zswap_swapon(int type)
> > >  void zswap_swapoff(int type)
> > >  {
> > >         struct zswap_tree *tree = 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, rbnode)
> > > -               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.

I see, but it's not clear to me if the xarray is being properly
cleaned up in this case.

Do we have to call xa_destroy() anyway to make sure everything is
cleaned up in the xarray? In that case, we can just do that after the
loop.


  reply	other threads:[~2024-01-19 19:30 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-18  3:05 [PATCH 0/2] RFC: zswap tree use xarray instead of RB tree Chris Li
2024-01-18  3:05 ` [PATCH 1/2] mm: zswap.c: add xarray tree to zswap Chris Li
2024-01-18  6:20   ` Yosry Ahmed
2024-01-18 13:52     ` Matthew Wilcox
2024-01-18 16:59       ` Yosry Ahmed
2024-01-18 18:25         ` Matthew Wilcox
2024-01-19  5:28           ` Chris Li
2024-01-19 19:30             ` Yosry Ahmed
2024-01-19  5:24     ` Chris Li
2024-01-19 19:29       ` Yosry Ahmed [this message]
2024-01-19 20:04         ` Matthew Wilcox
2024-01-19 21:41           ` Yosry Ahmed
2024-01-19 22:05             ` Chris Li
2024-01-19 22:08               ` Yosry Ahmed
2024-01-18  3:05 ` [PATCH 2/2] mm: zswap.c: remove RB tree Chris Li
2024-01-18  6:35   ` Yosry Ahmed
2024-01-18 19:35     ` Yosry Ahmed
2024-01-19  5:49       ` Chris Li
2024-01-19 19:37         ` Yosry Ahmed
2024-01-19  5:43     ` Chris Li
2024-01-19 19:36       ` Yosry Ahmed
2024-01-19 21:31         ` Chris Li
2024-01-19 21:44           ` Yosry Ahmed
2024-01-18  6:01 ` [PATCH 0/2] RFC: zswap tree use xarray instead of " Yosry Ahmed
2024-01-18  6:39   ` Yosry Ahmed
2024-01-18  6:57     ` Chengming Zhou
2024-01-18  7:02       ` Yosry Ahmed
2024-01-18  7:19         ` Chris Li
2024-01-18  7:35           ` Chengming Zhou
2024-01-19  4:59             ` Chris Li
2024-01-19  6:18               ` Chengming Zhou
2024-01-19 10:26                 ` Chris Li
2024-01-19 11:12                   ` Chengming Zhou
2024-01-19 11:59                     ` Chris Li
2024-01-18  6:48   ` Christopher Li
2024-01-18  7:05     ` Yosry Ahmed
2024-01-18  7:28       ` Chris Li
2024-01-18 17:14         ` Yosry Ahmed
2024-01-18 14:48       ` Johannes Weiner
2024-01-18 18:59     ` Liam R. Howlett
2024-01-19  5:13       ` Chris Li
2024-01-18 18:01 ` Nhat Pham
2024-01-19  5:14   ` Chris Li

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAJD7tkY6K8q1t-nzZ7oJu-f3OgS654PiOcQgU=E6f+0joYSzPA@mail.gmail.com' \
    --to=yosryahmed@google.com \
    --cc=Liam.Howlett@oracle.com \
    --cc=akpm@linux-foundation.org \
    --cc=bgeffon@google.com \
    --cc=chrisl@kernel.org \
    --cc=ctshao@google.com \
    --cc=gthelen@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=hezhongkun.hzk@bytedance.com \
    --cc=joel@joelfernandes.org \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mgorman@techsingularity.net \
    --cc=mhocko@suse.com \
    --cc=minchan@kernel.org \
    --cc=nphamcs@gmail.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=surenb@google.com \
    --cc=v-songbaohua@oppo.com \
    --cc=weixugc@google.com \
    --cc=willy@infradead.org \
    --cc=ying.huang@intel.com \
    --cc=yuzhao@google.com \
    --cc=zhouchengming@bytedance.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox