From: Johannes Weiner <hannes@cmpxchg.org>
To: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
Cc: vitaly.wool@konsulko.com, minchan@kernel.org,
senozhatsky@chromium.org, yosryahmed@google.com,
linux-mm@kvack.org, ddstreet@ieee.org, sjenning@redhat.com,
nphamcs@gmail.com, akpm@linux-foundation.org,
linux-kernel@vger.kernel.org, kernel-team@meta.com
Subject: Re: [RFC PATCH v2 6/7] mm: zswap: simplify writeback function
Date: Thu, 8 Jun 2023 12:48:44 -0400 [thread overview]
Message-ID: <20230608164844.GF352940@cmpxchg.org> (raw)
In-Reply-To: <20230606145611.704392-7-cerasuolodomenico@gmail.com>
Hi Domenico,
On Tue, Jun 06, 2023 at 04:56:10PM +0200, Domenico Cerasuolo wrote:
> Previously, in zswap, the writeback function was passed to zpool drivers
> for their usage in calling the writeback operation. However, since the
> drivers did not possess references to entries and the function was
> specifically designed to work with handles, the writeback process has
> been modified to occur directly within zswap.
I'm having trouble parsing this sentence.
> Consequently, this change allows for some simplification of the
> writeback function, taking into account the updated workflow.
How about:
zswap_writeback_entry() used to be a callback for the backends, which
don't know about struct zswap_entry.
Now that the only user is the generic zswap LRU reclaimer, it can be
simplified: pass the pinned zswap_entry directly, and consolidate the
refcount management in the shrink function.
> Signed-off-by: Domenico Cerasuolo <cerasuolodomenico@gmail.com>
> ---
> mm/zswap.c | 69 ++++++++++++++----------------------------------------
> 1 file changed, 17 insertions(+), 52 deletions(-)
>
> diff --git a/mm/zswap.c b/mm/zswap.c
> index 2831bf56b168..ef8604812352 100644
> --- a/mm/zswap.c
> +++ b/mm/zswap.c
> @@ -250,7 +250,8 @@ static bool zswap_has_pool;
> pr_debug("%s pool %s/%s\n", msg, (p)->tfm_name, \
> zpool_get_type((p)->zpool))
>
> -static int zswap_writeback_entry(struct zpool *pool, unsigned long handle);
> +static int zswap_writeback_entry(struct zswap_entry *entry, struct zswap_header *zhdr,
> + struct zswap_tree *tree);
> static int zswap_pool_get(struct zswap_pool *pool);
> static void zswap_pool_put(struct zswap_pool *pool);
>
> @@ -632,15 +633,21 @@ static int zswap_shrink(struct zswap_pool *pool)
> }
> spin_unlock(&tree->lock);
>
> - ret = zswap_writeback_entry(pool->zpool, lru_entry->handle);
> + ret = zswap_writeback_entry(lru_entry, zhdr, tree);
>
> spin_lock(&tree->lock);
> if (ret) {
> spin_lock(&pool->lru_lock);
> list_move(&lru_entry->lru, &pool->lru);
> spin_unlock(&pool->lru_lock);
This could use a comment.
/* Writeback failed, put entry back on LRU */
> + zswap_entry_put(tree, tree_entry);
This put is a common factor in both branches, so you can consolidate.
> + } else {
> + /* free the local reference */
> + zswap_entry_put(tree, tree_entry);
> + /* free the entry if it's not been invalidated*/
Missing space between text and */
> + if (lru_entry == zswap_rb_search(&tree->rbroot, swpoffset))
> + zswap_entry_put(tree, tree_entry);
> }
> - zswap_entry_put(tree, tree_entry);
> spin_unlock(&tree->lock);
The success path freeing (hopefully the common path) is now
unfortunately hidden in fairly deep indentation. I think this would be
better with a goto for the error case.
All together, something like this?
if (ret) {
/* Writeback failed, put entry back on LRU */
...
goto put_unlock;
}
/*
* Writeback started successfully, the page now belongs to the
* swapcache. Drop the base ref from the tree - unless invalidate
* already took it out while we had the tree->lock released for IO.
*/
if (lru_entry == zswap_rb_search(&tree->rb_root, swpoffset))
zswap_entry_put(tree, entry);
put_unlock:
/* Drop local reference */
zswap_entry_put(tree, tree_entry);
spin_unlock(&tree->lock);
return ret ? -EAGAIN : 0;
Btw, it's unsettling that we drop the tree reference without
explicitly removing the entry for the tree. We rely on the final put
that frees the entry to do tree removal, but this doesn't happen if
somebody else is holding a reference; the entry can remain in the tree
long after we've officially handed over ownership of the data to
swapcache. TTBOMK there are currently no bugs because of that, but
it's a data corruption waiting to happen.
This should be:
/*
* 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->rb_root, swpoffset))
zswap_invalidate_entry(tree, entry);
Would you care to send a follow-up patch?
next prev parent reply other threads:[~2023-06-08 16:48 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230606145611.704392-1-cerasuolodomenico@gmail.com>
[not found] ` <20230606145611.704392-2-cerasuolodomenico@gmail.com>
2023-06-07 8:14 ` [RFC PATCH v2 1/7] mm: zswap: add pool shrinking mechanism Yosry Ahmed
2023-06-07 9:22 ` Domenico Cerasuolo
2023-06-07 9:31 ` Yosry Ahmed
2023-06-07 21:39 ` Nhat Pham
2023-06-08 15:58 ` Johannes Weiner
2023-06-08 16:52 ` Johannes Weiner
2023-06-08 17:04 ` Johannes Weiner
2023-06-08 18:45 ` Johannes Weiner
2023-06-09 8:39 ` Domenico Cerasuolo
2023-06-07 9:16 ` [RFC PATCH v2 0/7] mm: zswap: move writeback LRU from zpool to zswap Yosry Ahmed
2023-06-07 9:23 ` Domenico Cerasuolo
2023-06-07 9:32 ` Yosry Ahmed
[not found] ` <20230606145611.704392-8-cerasuolodomenico@gmail.com>
2023-06-07 9:30 ` [RFC PATCH v2 7/7] mm: zswap: remove zswap_header Yosry Ahmed
2023-06-09 16:10 ` Domenico Cerasuolo
2023-06-09 17:13 ` Yosry Ahmed
[not found] ` <20230606145611.704392-5-cerasuolodomenico@gmail.com>
2023-06-07 17:23 ` [RFC PATCH v2 4/7] mm: zswap: remove page reclaim logic from zsmalloc Nhat Pham
2023-06-07 17:45 ` Minchan Kim
2023-06-08 16:07 ` Johannes Weiner
[not found] ` <20230606145611.704392-3-cerasuolodomenico@gmail.com>
2023-06-08 16:02 ` [RFC PATCH v2 2/7] mm: zswap: remove page reclaim logic from zbud Johannes Weiner
[not found] ` <20230606145611.704392-4-cerasuolodomenico@gmail.com>
2023-06-08 16:05 ` [RFC PATCH v2 3/7] mm: zswap: remove page reclaim logic from z3fold Johannes Weiner
[not found] ` <20230606145611.704392-6-cerasuolodomenico@gmail.com>
2023-06-07 9:19 ` [RFC PATCH v2 5/7] mm: zswap: remove shrink from zpool interface Yosry Ahmed
2023-06-08 16:10 ` Johannes Weiner
2023-06-08 17:51 ` Nhat Pham
[not found] ` <20230606145611.704392-7-cerasuolodomenico@gmail.com>
2023-06-07 9:26 ` [RFC PATCH v2 6/7] mm: zswap: simplify writeback function Yosry Ahmed
2023-06-09 10:23 ` Domenico Cerasuolo
2023-06-09 11:01 ` Yosry Ahmed
2023-06-08 16:48 ` Johannes Weiner [this message]
2023-06-09 11:05 ` Domenico Cerasuolo
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=20230608164844.GF352940@cmpxchg.org \
--to=hannes@cmpxchg.org \
--cc=akpm@linux-foundation.org \
--cc=cerasuolodomenico@gmail.com \
--cc=ddstreet@ieee.org \
--cc=kernel-team@meta.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=minchan@kernel.org \
--cc=nphamcs@gmail.com \
--cc=senozhatsky@chromium.org \
--cc=sjenning@redhat.com \
--cc=vitaly.wool@konsulko.com \
--cc=yosryahmed@google.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