The patch titled Subject: mm: zswap: invaldiate entry after writeback has been added to the -mm mm-unstable branch. Its filename is mm-zswap-invaldiate-entry-after-writeback.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-zswap-invaldiate-entry-after-writeback.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via the mm-everything branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there every 2-3 working days ------------------------------------------------------ From: Domenico Cerasuolo <cerasuolodomenico@xxxxxxxxx> Subject: mm: zswap: invaldiate entry after writeback Date: Wed, 14 Jun 2023 16:31:22 +0200 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" + commit f090b7949768("mm: zswap: support exclusive loads"). Link: https://lkml.kernel.org/r/20230614143122.74471-1-cerasuolodomenico@xxxxxxxxx Signed-off-by: Domenico Cerasuolo <cerasuolodomenico@xxxxxxxxx> Suggested-by: Johannes Weiner <hannes@xxxxxxxxxxx> Acked-by: Johannes Weiner <hannes@xxxxxxxxxxx> Cc: Dan Streetman <ddstreet@xxxxxxxx> Cc: Nhat Pham <nphamcs@xxxxxxxxx> Cc: Seth Jennings <sjenning@xxxxxxxxxx> Cc: Vitaly Wool <vitaly.wool@xxxxxxxxxxxx> Cc: Yosry Ahmed <yosryahmed@xxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- mm/zswap.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) --- a/mm/zswap.c~mm-zswap-invaldiate-entry-after-writeback +++ a/mm/zswap.c @@ -599,6 +599,16 @@ static struct zswap_pool *zswap_pool_fin 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 zs 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 */ @@ -1383,16 +1394,6 @@ shrink: 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 _ Patches currently in -mm which might be from cerasuolodomenico@xxxxxxxxx are mm-zswap-add-pool-shrinking-mechanism.patch mm-zswap-remove-page-reclaim-logic-from-zbud.patch mm-zswap-remove-page-reclaim-logic-from-z3fold.patch mm-zswap-remove-page-reclaim-logic-from-zsmalloc.patch mm-zswap-remove-shrink-from-zpool-interface.patch mm-zswap-simplify-writeback-function.patch mm-zswap-remove-zswap_header.patch mm-zswap-invaldiate-entry-after-writeback.patch