linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Baoquan He <baoquan.he@linux.dev>
To: Usama Arif <usama.arif@linux.dev>
Cc: linux-mm@kvack.org, akpm@linux-foundation.org, baohua@kernel.org,
	chrisl@kernel.org, kasong@tencent.com, nphamcs@gmail.com,
	shikemeng@huaweicloud.com, youngjun.park@lge.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/3] mm/swap: use swap_ops to register swap device's methods
Date: Wed, 15 Apr 2026 23:24:43 +0800	[thread overview]
Message-ID: <ad-tuwdq_AeVRuIr@MiWiFi-R3L-srv> (raw)
In-Reply-To: <20260415150550.3616172-1-usama.arif@linux.dev>

On 04/15/26 at 08:05am, Usama Arif wrote:
> On Wed, 15 Apr 2026 16:56:57 +0800 Baoquan He <baoquan.he@linux.dev> wrote:
> 
> > This simplifies codes and makes logic clearer. And also makes later any
> > new swap device type being added easier to handle.
> > 
> > Currently there are three types of swap devices: bdev_fs, bdev_sync
> > and bdev_async, and only operations read_folio and write_folio are
> > included. In the future, there could be more swap device types added
> > and more appropriate opeations adapted into swap_ops.
> 
> s/opeations/operations/

Good catch, thanks.

> 
> > 
> > Suggested-by: Chris Li <chrisl@kernel.org>
> > Co-developed-by: Barry Song <baohua@kernel.org>
> > Signed-off-by: Barry Song <baohua@kernel.org>
> > Signed-off-by: Baoquan He <baoquan.he@linux.dev>
> > ---
> >  include/linux/swap.h |   2 +
> >  mm/swap.h            |  10 ++++-
> >  mm/swap_io.c         | 102 +++++++++++++++++++++++++------------------
> >  mm/swapfile.c        |   5 +++
> >  mm/zswap.c           |   2 +-
> >  5 files changed, 76 insertions(+), 45 deletions(-)
> > 
...snip...
> > diff --git a/mm/swap_io.c b/mm/swap_io.c
> > index 4bf210bd677e..602e9b871b30 100644
> > --- a/mm/swap_io.c
> > +++ b/mm/swap_io.c
...snip...  
> > @@ -604,6 +588,44 @@ 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,
> > +};
> > +
> > +int init_swap_ops(struct swap_info_struct *sis)
> > +{
> > +	/*
> > +	 * ->flags can be updated non-atomically, but that will
> > +	 * never affect SWP_FS_OPS, so the data_race is safe.
> > +	 */
> > +	if (data_race(sis->flags & SWP_FS_OPS))
> > +		sis->ops = &bdev_fs_swap_ops;
> > +	/*
> > +	 * ->flags can be updated non-atomically, but that will
> > +	 * never affect SWP_SYNCHRONOUS_IO, so the data_race is safe.
> > +	 */
> > +	else if (data_race(sis->flags & SWP_SYNCHRONOUS_IO))
> > +		sis->ops = &bdev_sync_swap_ops;
> > +	else
> > +		sis->ops = &bdev_async_swap_ops;
> > +
> > +	if (sis->ops || sis->ops->read_folio || sis->ops->write_folio)
> > +		return -1;
> 
> sis->ops is always non-NULL, and you will return -1 here and
> swapon will always fail with -EINVAL.
> 
> You probably wanted?
> 
>       if (!sis->ops || !sis->ops->read_folio || !sis->ops->write_folio)
>           return -1;

You are right. Think one thing, write another. Will fix it in v4.
Thanks a lot for your careful reviewing.

> 
> > +
> > +	return 0;
> > +}
> > +
> >  void swap_read_folio(struct folio *folio, struct swap_iocb **plug)
> >  {
> >  	struct swap_info_struct *sis = __swap_entry_to_info(folio->swap);


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

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-15  8:56 [PATCH v3 0/3] " Baoquan He
2026-04-15  8:56 ` [PATCH v3 1/3] mm/swap: rename mm/page_io.c to mm/swap_io.c Baoquan He
2026-04-15  8:56 ` [PATCH v3 2/3] mm/swap: use swap_ops to register swap device's methods Baoquan He
2026-04-15 15:05   ` Usama Arif
2026-04-15 15:24     ` Baoquan He [this message]
2026-04-15  8:56 ` [PATCH v3 3/3] mm/swap_io.c: rename swap_writepage_* to swap_write_folio_* 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=ad-tuwdq_AeVRuIr@MiWiFi-R3L-srv \
    --to=baoquan.he@linux.dev \
    --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=usama.arif@linux.dev \
    --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