From: Yosry Ahmed <yosryahmed@google.com>
To: Kairui Song <ryncsn@gmail.com>
Cc: Barry Song <21cnbao@gmail.com>,
akpm@linux-foundation.org, chengming.zhou@linux.dev,
chrisl@kernel.org, hannes@cmpxchg.org,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
nphamcs@gmail.com, ryan.roberts@arm.com,
syzbot+ce6029250d7fd4d0476d@syzkaller.appspotmail.com,
syzkaller-bugs@googlegroups.com, ying.huang@intel.com
Subject: Re: [syzbot] [mm?] WARNING in zswap_swapoff
Date: Tue, 3 Sep 2024 11:21:56 -0700 [thread overview]
Message-ID: <CAJD7tkamz0RHzv3yy7833GhhhBzGB1ozRo085wB4xZjXppEBWg@mail.gmail.com> (raw)
In-Reply-To: <CAJD7tkYxAUVhvb_khBngRg5d504-KYVbW-v=GNfUPR-6_f-rVQ@mail.gmail.com>
[..]
> > > > > > I am not closely following the latest changes so I am not sure. CCing
> > > > > > folks who have done work in that area recently.
> > > > > >
> > > > > > I am starting to think maybe it would be more reliable to just call
> > > > > > zswap_invalidate() for all freed swap entries anyway. Would that be
> > > > > > too expensive? We used to do that before the zswap_invalidate() call
> > > > > > was moved by commit 0827a1fb143f ("mm/zswap: invalidate zswap entry
> > > > > > when swap entry free"), and that was before we started using the
> > > > > > xarray (so it was arguably worse than it would be now).
> > > > > >
> > > > >
> > > > > That might be a good idea, I suggest moving zswap_invalidate to
> > > > > swap_range_free and call it for every freed slot.
> > > > >
> > > > > Below patch can be squash into or put before "mm: attempt to batch
> > > > > free swap entries for zap_pte_range()".
> > > >
> > > > Hmm, on second thought, the commit message in the attachment commit
> > > > might be not suitable, current zswap_invalidate is also designed to
> > > > only work for order 0 ZSWAP, so things are not clean even after this.
> > >
> > > Kairui, what about the below? we don't touch the path of __try_to_reclaim_swap() where
> > > you have one folio backed?
> > >
> > > diff --git a/mm/swapfile.c b/mm/swapfile.c
> > > index c1638a009113..8ff58be40544 100644
> > > --- a/mm/swapfile.c
> > > +++ b/mm/swapfile.c
> > > @@ -1514,6 +1514,8 @@ static bool __swap_entries_free(struct swap_info_struct *si,
> > > unlock_cluster_or_swap_info(si, ci);
> > >
> > > if (!has_cache) {
> > > + for (i = 0; i < nr; i++)
> > > + zswap_invalidate(swp_entry(si->type, offset + i));
> > > spin_lock(&si->lock);
> > > swap_entry_range_free(si, entry, nr);
> > > spin_unlock(&si->lock);
> > >
> >
> > Hi Barry,
> >
> > Thanks for updating this thread, I'm thinking maybe something will
> > better be done at the zswap side?
> >
> > The concern of using zswap_invalidate is that it calls xa_erase which
> > requires the xa spin lock. But if we are calling zswap_invalidate in
> > swap_entry_range_free, and ensure the slot is HAS_CACHE pinned, doing
> > a lockless read first with xa_load should be OK for checking if the
> > slot needs a ZSWAP invalidation. The performance cost will be minimal
> > and we only need to call zswap_invalidate in one place, something like
> > this (haven't tested, comments are welcome). Also ZSWAP mthp will
> > still store entried in order 0 so this should be OK for future.
>
>
> While I do agree with this change on a high level, it's essentially
> reverting commit 0827a1fb143f ("mm/zswap: invalidate zswap entry when
> swap entry free") which fixed a small problem with zswap writeback.
> I'd prefer that we don't if possible.
>
> One thing that I always wanted to do is to pull some of the work done
> in swap_entry_range_free() and swap_range_free() before the slots
> caching layer. The memcg uncharging, clearing shadow entries from the
> swap cache, arch invalidation, zswap invalidation, etc. If we can have
> a hook for these pre-free callbacks we can call it for single entries
> before we add them to the slots cache, and call them for the clusters
> as we do today. This should also reduce the amount of work done under
> the lock, and move more work to where the freeing is actually
> happening vs. the cache draining.
>
> I remember discussing this briefly with Ying before. Anyone have any thoughts?
Kairui, Barry, any thoughts on this? Any preferences on how to make
sure zswap_invalidate() is being called in all possible swap freeing
paths?
next prev parent reply other threads:[~2024-09-03 18:22 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-16 19:52 [syzbot] [mm?] WARNING in zswap_swapoff syzbot
2024-08-19 20:12 ` Yosry Ahmed
2024-08-20 8:47 ` Kairui Song
2024-08-20 9:02 ` Kairui Song
2024-08-21 5:49 ` Barry Song
2024-08-21 6:42 ` Kairui Song
2024-08-21 7:38 ` Barry Song
2024-08-21 17:33 ` Kairui Song
2024-08-21 20:59 ` Barry Song
2024-08-22 18:12 ` Yosry Ahmed
2024-08-22 20:16 ` Chris Li
2024-08-22 20:20 ` Yosry Ahmed
2024-08-22 21:44 ` Chris Li
2024-09-03 18:21 ` Yosry Ahmed [this message]
2024-09-03 18:50 ` Kairui Song
2024-09-03 19:41 ` Yosry Ahmed
2024-08-20 9:22 ` Barry Song
2024-08-20 9:29 ` Kairui Song
2024-08-20 9:53 ` Barry Song
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=CAJD7tkamz0RHzv3yy7833GhhhBzGB1ozRo085wB4xZjXppEBWg@mail.gmail.com \
--to=yosryahmed@google.com \
--cc=21cnbao@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=chengming.zhou@linux.dev \
--cc=chrisl@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=nphamcs@gmail.com \
--cc=ryan.roberts@arm.com \
--cc=ryncsn@gmail.com \
--cc=syzbot+ce6029250d7fd4d0476d@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=ying.huang@intel.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;
as well as URLs for NNTP newsgroup(s).