* [PATCH] mm: zswap: invaldiate entry after writeback
@ 2023-06-14 14:31 Domenico Cerasuolo
2023-06-14 14:35 ` Johannes Weiner
0 siblings, 1 reply; 2+ messages in thread
From: Domenico Cerasuolo @ 2023-06-14 14:31 UTC (permalink / raw)
To: sjenning, ddstreet, vitaly.wool
Cc: yosryahmed, hannes, nphamcs, akpm, linux-mm, linux-kernel,
kernel-team, Domenico Cerasuolo
When an entry started writeback, it used to be invalidated with ref
count logic alone, meaning that it would stay on the tree until all
references were put. The problem with this behavior is that as soon as
the writeback started, the ownership of the data held by the entry is
passed to the swapcache and should not be left in zswap too.
Currently there are no known issues because of this, but this change
explicitly invalidates an entry that started writeback to reduce
opportunities for future bugs.
This patch is a follow up on the series titled "mm: zswap: move
writeback LRU from zpool to zswap" with message id
<20230612093815.133504-1-cerasuolodomenico@gmail.com> in mm-unstable +
commit f090b7949768("mm: zswap: support exclusive loads") that's in
mm-unstable as well.
Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
---
mm/zswap.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/mm/zswap.c b/mm/zswap.c
index 02d0a6f46f4a..c122f042a49d 100644
--- a/mm/zswap.c
+++ b/mm/zswap.c
@@ -599,6 +599,16 @@ static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
return NULL;
}
+static void zswap_invalidate_entry(struct zswap_tree *tree,
+ struct zswap_entry *entry)
+{
+ /* remove from rbtree */
+ zswap_rb_erase(&tree->rbroot, entry);
+
+ /* drop the initial reference from entry creation */
+ zswap_entry_put(tree, entry);
+}
+
static int zswap_reclaim_entry(struct zswap_pool *pool)
{
struct zswap_entry *entry;
@@ -644,12 +654,13 @@ static int zswap_reclaim_entry(struct zswap_pool *pool)
goto put_unlock;
}
- /* Check for invalidate() race */
- if (entry != zswap_rb_search(&tree->rbroot, swpoffset))
- goto put_unlock;
-
- /* Drop base reference */
- zswap_entry_put(tree, entry);
+ /*
+ * Writeback started successfully, the page now belongs to the
+ * swapcache. Drop the entry from zswap - unless invalidate already
+ * took it out while we had the tree->lock released for IO.
+ */
+ if (entry == zswap_rb_search(&tree->rbroot, swpoffset))
+ zswap_invalidate_entry(tree, entry);
put_unlock:
/* Drop local reference */
@@ -1376,16 +1387,6 @@ static int zswap_frontswap_store(unsigned type, pgoff_t offset,
goto reject;
}
-static void zswap_invalidate_entry(struct zswap_tree *tree,
- struct zswap_entry *entry)
-{
- /* remove from rbtree */
- zswap_rb_erase(&tree->rbroot, entry);
-
- /* drop the initial reference from entry creation */
- zswap_entry_put(tree, entry);
-}
-
/*
* returns 0 if the page was successfully decompressed
* return -1 on entry not found or error
--
2.34.1
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mm: zswap: invaldiate entry after writeback
2023-06-14 14:31 [PATCH] mm: zswap: invaldiate entry after writeback Domenico Cerasuolo
@ 2023-06-14 14:35 ` Johannes Weiner
0 siblings, 0 replies; 2+ messages in thread
From: Johannes Weiner @ 2023-06-14 14:35 UTC (permalink / raw)
To: Domenico Cerasuolo
Cc: sjenning, ddstreet, vitaly.wool, yosryahmed, nphamcs, akpm,
linux-mm, linux-kernel, kernel-team
On Wed, Jun 14, 2023 at 04:31:22PM +0200, Domenico Cerasuolo wrote:
> When an entry started writeback, it used to be invalidated with ref
> count logic alone, meaning that it would stay on the tree until all
> references were put. The problem with this behavior is that as soon as
> the writeback started, the ownership of the data held by the entry is
> passed to the swapcache and should not be left in zswap too.
> Currently there are no known issues because of this, but this change
> explicitly invalidates an entry that started writeback to reduce
> opportunities for future bugs.
>
> This patch is a follow up on the series titled "mm: zswap: move
> writeback LRU from zpool to zswap" with message id
> <20230612093815.133504-1-cerasuolodomenico@gmail.com> in mm-unstable +
> commit f090b7949768("mm: zswap: support exclusive loads") that's in
> mm-unstable as well.
>
> Suggested-by: Johannes Weiner <hannes@cmpxchg.org>
> Signed-off-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
Acked-by: Johannes Weiner <hannes@cmpxchg.org>
Thanks Domenico!
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-14 14:36 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-14 14:31 [PATCH] mm: zswap: invaldiate entry after writeback Domenico Cerasuolo
2023-06-14 14:35 ` Johannes Weiner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox