From: Christoph Hellwig <hch@lst.de>
To: Andrew Morton <akpm@linux-foundation.org>,
Chris Li <chrisl@kernel.org>, Kairui Song <kasong@tencent.com>
Cc: Christian Brauner <brauner@kernel.org>,
"Darrick J . Wong " <djwong@kernel.org>,
Jens Axboe <axboe@kernel.dk>, David Sterba <dsterba@suse.com>,
"Theodore Ts'o" <tytso@mit.edu>, Jaegeuk Kim <jaegeuk@kernel.org>,
Chao Yu <chao@kernel.org>, Trond Myklebust <trondmy@kernel.org>,
Anna Schumaker <anna@kernel.org>,
Namjae Jeon <linkinjeon@kernel.org>,
Hyunchul Lee <hyc.lee@gmail.com>,
Steve French <sfrench@samba.org>,
Paulo Alcantara <pc@manguebit.org>,
Carlos Maiolino <cem@kernel.org>,
Damien Le Moal <dlemoal@kernel.org>,
Naohiro Aota <naohiro.aota@wdc.com>,
linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-doc@vger.kernel.org, linux-mm@kvack.org,
linux-block@vger.kernel.org, linux-btrfs@vger.kernel.org,
linux-ext4@vger.kernel.org,
linux-f2fs-devel@lists.sourceforge.net,
linux-nfs@vger.kernel.org, linux-cifs@vger.kernel.org
Subject: [PATCH 10/12] swap: add a swap_activate_fs_ops helper
Date: Tue, 12 May 2026 07:35:26 +0200 [thread overview]
Message-ID: <20260512053625.2950900-11-hch@lst.de> (raw)
In-Reply-To: <20260512053625.2950900-1-hch@lst.de>
Add a helper abstracting away the low-level details of enabling
fs_ops-based swapping. This prepares for taking swap_info_struct
private.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
fs/nfs/file.c | 4 +---
fs/smb/client/file.c | 3 +--
include/linux/swap.h | 5 +++++
mm/swapfile.c | 7 +++++++
4 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 10ab2a923835..ce4d860c4e7a 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -588,7 +588,7 @@ int nfs_swap_activate(struct file *file, struct swap_info_struct *sis)
ret = rpc_clnt_swap_activate(clnt);
if (ret)
return ret;
- ret = add_swap_extent(sis, sis->max, NULL, 0);
+ ret = swap_activate_fs_ops(sis);
if (ret < 0) {
rpc_clnt_swap_deactivate(clnt);
return ret;
@@ -596,8 +596,6 @@ int nfs_swap_activate(struct file *file, struct swap_info_struct *sis)
if (cl->rpc_ops->enable_swap)
cl->rpc_ops->enable_swap(inode);
-
- sis->flags |= SWP_FS_OPS;
return 0;
}
EXPORT_SYMBOL_GPL(nfs_swap_activate);
diff --git a/fs/smb/client/file.c b/fs/smb/client/file.c
index e1bbc65ce7f3..e11065be1e64 100644
--- a/fs/smb/client/file.c
+++ b/fs/smb/client/file.c
@@ -3326,8 +3326,7 @@ int cifs_swap_activate(struct file *swap_file, struct swap_info_struct *sis)
* from reading or writing the file
*/
- sis->flags |= SWP_FS_OPS;
- return add_swap_extent(sis, sis->max, NULL, 0);
+ return swap_activate_fs_ops(sis);
}
void cifs_swap_deactivate(struct file *file)
diff --git a/include/linux/swap.h b/include/linux/swap.h
index b1cbb67ddd8e..916889738f08 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -406,6 +406,7 @@ extern void __meminit kswapd_stop(int nid);
int add_swap_extent(struct swap_info_struct *sis, unsigned long nr_pages,
struct block_device *bdev, sector_t start_block);
int generic_swap_activate(struct file *swap_file, struct swap_info_struct *sis);
+int swap_activate_fs_ops(struct swap_info_struct *sis);
static inline unsigned long total_swapcache_pages(void)
{
@@ -532,6 +533,10 @@ static inline int add_swap_extent(struct swap_info_struct *sis,
{
return -EINVAL;
}
+static inline int swap_activate_fs_ops(struct swap_info_struct *sis)
+{
+ return -EINVAL;
+}
#endif /* CONFIG_SWAP */
#ifdef CONFIG_MEMCG
static inline int mem_cgroup_swappiness(struct mem_cgroup *memcg)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 2c9d2af736c4..26852c2ad36e 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -2757,6 +2757,13 @@ add_swap_extent(struct swap_info_struct *sis, unsigned long nr_pages,
}
EXPORT_SYMBOL_GPL(add_swap_extent);
+int swap_activate_fs_ops(struct swap_info_struct *sis)
+{
+ sis->flags |= SWP_FS_OPS;
+ return add_swap_extent(sis, sis->max, NULL, 0);
+}
+EXPORT_SYMBOL_GPL(swap_activate_fs_ops);
+
/*
* A `swap extent' is a simple thing which maps a contiguous range of pages
* onto a contiguous range of disk blocks. A rbtree of swap extents is
--
2.53.0
next prev parent reply other threads:[~2026-05-12 5:37 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 5:35 improve the swap_activate interface Christoph Hellwig
2026-05-12 5:35 ` [PATCH 01/12] swap: remove the maxpages variable in sys_swapon Christoph Hellwig
2026-05-12 7:08 ` Damien Le Moal
2026-05-12 7:20 ` Christoph Hellwig
2026-05-12 14:19 ` Hannes Reinecke
2026-05-12 16:14 ` Darrick J. Wong
2026-05-12 5:35 ` [PATCH 02/12] swap: move boilerplate code into the core swap code Christoph Hellwig
2026-05-12 7:11 ` Damien Le Moal
2026-05-12 16:33 ` Darrick J. Wong
2026-05-12 5:35 ` [PATCH 03/12] swap,fs: move swapfile operations to struct file_operations Christoph Hellwig
2026-05-12 7:16 ` Damien Le Moal
2026-05-12 16:41 ` Darrick J. Wong
2026-05-12 5:35 ` [PATCH 04/12] swap: restrict to regular files or block devices Christoph Hellwig
2026-05-12 7:17 ` Damien Le Moal
2026-05-12 16:42 ` Darrick J. Wong
2026-05-12 5:35 ` [PATCH 05/12] swap: cleanup setup_swap_extents Christoph Hellwig
2026-05-12 7:18 ` Damien Le Moal
2026-05-12 16:43 ` Darrick J. Wong
2026-05-13 5:56 ` Christoph Hellwig
2026-05-12 5:35 ` [PATCH 06/12] swap,block: move the block device swapon code into block/fops.c Christoph Hellwig
2026-05-12 7:20 ` Damien Le Moal
2026-05-12 16:44 ` Darrick J. Wong
2026-05-12 5:35 ` [PATCH 07/12] swap,block: limit swap file size to device size Christoph Hellwig
2026-05-12 7:21 ` Damien Le Moal
2026-05-12 7:23 ` Christoph Hellwig
2026-05-12 16:45 ` Darrick J. Wong
2026-05-12 5:35 ` [PATCH 08/12] swap,iomap: simplify iomap_swapfile_iter Christoph Hellwig
2026-05-12 7:31 ` Damien Le Moal
2026-05-12 17:02 ` Darrick J. Wong
2026-05-13 6:56 ` Christoph Hellwig
2026-05-12 5:35 ` [PATCH 09/12] swap: push down setting sis->bdev into ->swap_activate Christoph Hellwig
2026-05-12 7:34 ` Damien Le Moal
2026-05-12 17:08 ` Darrick J. Wong
2026-05-13 5:58 ` Christoph Hellwig
2026-05-13 7:44 ` Damien Le Moal
2026-05-13 7:46 ` Christoph Hellwig
2026-05-13 7:58 ` Damien Le Moal
2026-05-12 5:35 ` Christoph Hellwig [this message]
2026-05-12 7:36 ` [PATCH 10/12] swap: add a swap_activate_fs_ops helper Damien Le Moal
2026-05-12 17:09 ` Darrick J. Wong
2026-05-12 5:35 ` [PATCH 11/12] swap: move struct swap_extent to swapfile.c Christoph Hellwig
2026-05-12 7:36 ` Damien Le Moal
2026-05-12 17:09 ` Darrick J. Wong
2026-05-12 5:35 ` [PATCH 12/12] swap: move swap_info_struct to mm/swap.h Christoph Hellwig
2026-05-12 7:41 ` Damien Le Moal
2026-05-12 17:10 ` Darrick J. Wong
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=20260512053625.2950900-11-hch@lst.de \
--to=hch@lst.de \
--cc=akpm@linux-foundation.org \
--cc=anna@kernel.org \
--cc=axboe@kernel.dk \
--cc=brauner@kernel.org \
--cc=cem@kernel.org \
--cc=chao@kernel.org \
--cc=chrisl@kernel.org \
--cc=djwong@kernel.org \
--cc=dlemoal@kernel.org \
--cc=dsterba@suse.com \
--cc=hyc.lee@gmail.com \
--cc=jaegeuk@kernel.org \
--cc=kasong@tencent.com \
--cc=linkinjeon@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-cifs@vger.kernel.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-nfs@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=naohiro.aota@wdc.com \
--cc=pc@manguebit.org \
--cc=sfrench@samba.org \
--cc=trondmy@kernel.org \
--cc=tytso@mit.edu \
/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