linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Baoquan He <bhe@redhat.com>
To: Chris Li <chrisl@kernel.org>
Cc: Barry Song <21cnbao@gmail.com>,
	akpm@linux-foundation.org, linux-mm@kvack.org, baohua@kernel.org,
	kasong@tencent.com, nphamcs@gmail.com, shikemeng@huaweicloud.com,
	youngjun.park@lge.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] mm/swap: use swap_ops to register swap device's methods
Date: Wed, 8 Apr 2026 23:45:49 +0800	[thread overview]
Message-ID: <adZ4LehwC9KisuXf@MiWiFi-R3L-srv> (raw)
In-Reply-To: <CACePvbVwoqdOmMWkJUm=mqYQi=MgK+Q3NJu1Pxmmy9v61f4qEA@mail.gmail.com>

On 04/08/26 at 02:26am, Chris Li wrote:
> On Tue, Apr 7, 2026 at 11:11 PM Baoquan He <bhe@redhat.com> wrote:
> >
> > On 03/30/26 at 08:30pm, Chris Li wrote:
> > ......
> > > > @@ -608,6 +593,39 @@ static void swap_read_folio_bdev_async(struct folio *folio,
> > > >         submit_bio(bio);
> > > >  }
> > > >
> > > > +static const struct swap_ops bdev_fs_swap_ops = {
> > > > +       .read_folio = swap_read_folio_fs,
> > > > +       .write_folio = swap_writepage_fs,
> > > > +};
> > > > +
> > > > +static const struct swap_ops bdev_sync_swap_ops = {
> > > > +       .read_folio = swap_read_folio_bdev_sync,
> > > > +       .write_folio = swap_writepage_bdev_sync,
> > > > +};
> > > > +
> > > > +static const struct swap_ops bdev_async_swap_ops = {
> > > > +       .read_folio = swap_read_folio_bdev_async,
> > > > +       .write_folio = swap_writepage_bdev_async,
> > > > +};
> > > > +
> > > > +void setup_swap_ops(struct swap_info_struct *sis)
> > >
> > > setup_swap_ops()` needs to return an indication of an error.
> > > The error is that sis->ops is NULL or op->read_folio == NULL or
> > > op->write_folio == NULL.
> > > If there is an error, we should fail the swapon.
> >
> > Thanks for your comments.
> >
> > In the current patches, there's no chance any of these happens:
> >   sis->ops is NULL or
> >   op->read_folio == NULL or
> >   op->write_folio == NULL
> 
> I am aware of that. Adding the check in setup_swap_ops() responds to
> the WARN_ONCE check on op->write_folio() feedback.
> In fact, we should never have a case where op->read_folio or
> op->write_folio is NULL. However, I can see that other future swap ops
> can be NULL. e.g. Notify swap entry free. It is hard to enforce that
> some fields can be NULL and others can't. So having code safeguard it
> is fine.
> 
> > Because it's a if-else logic in setup_swap_ops(), adding an error
> > checking looks a little weird. I think it's worth adding the error
> > checking in setup_swap_ops() later when we have new swap_ops added
> > and there's potential any of above three cases could happen.
> 
> Adding the check in setup_swap_ops() is to remove the useless warning
> check on the caller side of op->read_folio(). If you think the check
> is not needed setup_swap_ops(), then it is not needed in
> op->read_folio() either.
> The WARN_ONCE() then kernel panic on reading op->read_folio does not
> make sense. The check was added due to one of the feedback that what
> if this call back is NULL.
> 
> I prefer to keep the `setup_swap_ops()` function responsible for the
> NULL check, due to the discussion history surrounding it.
> I'm also fine with adding the NULL check later. However, the NULL
> check needs to be consistent across the patch series. The other NULL
> check inside WARN_ONCE before the caller site op->read_folio()  and
> op->write_folio() needs to be removed.
> 
> Does that make sense?

Both is fine to me. I will change to do the checking in
setup_swap_ops(). By the way, I tend to rename setup_swap_ops() as
init_swap_ops(), is it OK to you?

Thanks
Baoquan



  reply	other threads:[~2026-04-08 15:46 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-28  7:58 [PATCH v2 0/3] " Barry Song
2026-03-28  7:58 ` [PATCH v2 1/3] mm/swap: rename mm/page_io.c to mm/swap_io.c Barry Song
2026-03-29 14:31   ` Chris Li
2026-03-28  7:58 ` [PATCH v2 2/3] mm/swap: use swap_ops to register swap device's methods Barry Song
2026-03-29 10:49   ` kernel test robot
2026-03-29 11:44     ` Barry Song
2026-03-29 11:10   ` kernel test robot
2026-03-31  3:30   ` Chris Li
2026-03-31  9:21     ` Barry Song
2026-03-31 16:10       ` Chris Li
2026-04-08  6:11     ` Baoquan He
2026-04-08  9:26       ` Chris Li
2026-04-08 15:45         ` Baoquan He [this message]
2026-04-08 16:27           ` Chris Li
2026-03-28  7:58 ` [PATCH v2 3/3] mm/swap_io.c: rename swap_writepage_* to swap_write_folio_* Barry Song
2026-03-29 14:31   ` Chris Li
2026-03-30  0:54 ` [PATCH v2 0/3] mm/swap: use swap_ops to register swap device's methods Baoquan He

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=adZ4LehwC9KisuXf@MiWiFi-R3L-srv \
    --to=bhe@redhat.com \
    --cc=21cnbao@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=baohua@kernel.org \
    --cc=chrisl@kernel.org \
    --cc=kasong@tencent.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=nphamcs@gmail.com \
    --cc=shikemeng@huaweicloud.com \
    --cc=youngjun.park@lge.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