Date: Fri, 19 Jan 2024 19:23:52 +0000
From: Yosry Ahmed <[email protected]>
To: Chris Li <[email protected]>
Cc: Andrew Morton <[email protected]>, [email protected],
[email protected], Wei =?utf-8?B?WHXvv7w=?= <[email protected]>, Yu Zhao <[email protected]>, Greg Thelen <[email protected]>, Chun-Tse Shao <[email protected]>,
Suren =?utf-8?B?QmFnaGRhc2FyeWFu77+8?= <[email protected]>, Brain Geffon <[email protected]>, Minchan Kim <[email protected]>, Michal Hocko <[email protected]>,
Mel Gorman <[email protected]>,
Huang Ying <[email protected]>, Nhat Pham <[email protected]>, Johannes Weiner <[email protected]>,
Kairui Song <[email protected]>,
Zhongkun He <[email protected]>,
Kemeng Shi <[email protected]>,
Barry Song <[email protected]>,
"Matthew Wilcox (Oracle)" <[email protected]>,
"Liam R. Howlett" <[email protected]>,
Joel Fernandes <[email protected]>,
Chengming Zhou <[email protected]>
Subject: Re: [PATCH 1/2] mm: zswap.c: add xarray tree to zswap
Message-ID: <[email protected]>
References: <[email protected]>
<[email protected]> <CAJD7tkYEx57CPBoaN9GW4M3Mx-+jEsOMWJ02nLKSKD-MLb-WPA@mail.gmail.com> <CAF8kJuO5tAqwyKQK7AasWgs3Ohfc2osD9oX0m8YAkfsAZsjjyQ@mail.gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
In-Reply-To: <CAF8kJuO5tAqwyKQK7AasWgs3Ohfc2osD9oX0m8YAkfsAZsjjyQ@mail.gmail.com>
Quoted 10 lines
Quoted 1 line
Quoted 1 line
-static struct
zswap_entry*zswap_rb_search(structrb_root*root,
pgoff_toffset)Quoted 1 line
Quoted 1 line
+static struct
zswap_entry*zswap_search(structzswap_tree*tree,
pgoff_toffset)Quoted 4 lines
Let's change the zswap_rb_* prefixes to zswap_tree_* instead of just zswap_*. Otherwise, it will be confusing to have both
zswap_storeandzswap_insert(as well aszswap_loadandzswap_search).How about zswap_xa_* ?
SGTM.
Quoted 37 lines
Quoted 13 lines
[..]
Quoted 11 lines
(quoted diff) +2
-1@@ -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;Quoted 10 lines
Review void zswap_swapon(int type) · line 1820
Quoted 4 lines
(quoted diff) +2
-0/* walk the tree and free everything */ spin_lock(&tree->lock); + + xas_for_each(&xas, e, ULONG_MAX)Why not use
xa_for_each?Quoted 3 lines
(quoted diff) +2
-0+ zswap_invalidate_entry(tree, e); + rbtree_postorder_for_each_entry_safe(entry, n, &tree->rbroot,rbnode)
Quoted 8 lines
Review void zswap_swapon(int type) · line 1801
Quoted 1 line
(quoted diff) +0
-1- zswap_free_entry(entry);Replacing
zswap_free_entry()withzswap_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.Quoted 4 lines
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 thenzswap_swapoff()is called freeing the zswap entry while writeback is still accessing it?
Quoted 7 lines
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 callzswap_erase()then free entry. I just thinkzswap_invalidate_entry()is more consistent with the rest of the code.
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.