* [PATCH] swapfile: disable swapon for bs > ps devices
@ 2025-05-02 23:13 Luis Chamberlain
2025-05-05 6:25 ` Christoph Hellwig
2025-05-05 14:21 ` Christian Brauner
0 siblings, 2 replies; 6+ messages in thread
From: Luis Chamberlain @ 2025-05-02 23:13 UTC (permalink / raw)
To: brauner, akpm
Cc: linux-fsdevel, linux-block, linux-mm, gost.dev, p.raghav,
da.gomez, mcgrof
Devices which have a requirement for bs > ps cannot be supported for
swap as swap still needs work. Now that the block device cache sets the
min order for block devices we need this stop gap otherwise all
swap operations are rejected.
Without this you'll end up with errors on these devices as the swap
code still needs much love to support min order.
# cat /sys/block/nvme3n1/queue/logical_block_size 16384
# mkswap /dev/nvme3n1
mkswap: /dev/nvme3n1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 100 GiB (107374178304 bytes)
no label, UUID=6af76b5c-7e7b-4902-b7f7-4c24dde6fa36
# swapon /dev/nvme3n1
swapon: /dev/nvme3n1: swapon failed: Invalid argument
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
I had posted an RFC about a heads up about us needing this less than a year
ago [0] and well, we now need it for v6.15 since swap code is just not ready.
Christian, this should probably go through your tree.
I tested it on a LBS device where the logical block size is 16 KiB on
x86_64 and confirm that while mkswap would swapon would be rejected.
[0] https://lore.kernel.org/all/20240627000924.2074949-1-mcgrof@kernel.org/T/#u
mm/swapfile.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 2eff8b51a945..c24ec16dfc7a 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3322,6 +3322,11 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
goto bad_swap_unlock_inode;
}
+ if (mapping_min_folio_order(mapping) > 0) {
+ error = -EINVAL;
+ goto bad_swap_unlock_inode;
+ }
+
/*
* Read the swap header.
*/
--
2.47.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] swapfile: disable swapon for bs > ps devices
2025-05-02 23:13 [PATCH] swapfile: disable swapon for bs > ps devices Luis Chamberlain
@ 2025-05-05 6:25 ` Christoph Hellwig
2025-05-05 14:40 ` Matthew Wilcox
2025-05-05 14:21 ` Christian Brauner
1 sibling, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2025-05-05 6:25 UTC (permalink / raw)
To: Luis Chamberlain
Cc: brauner, akpm, linux-fsdevel, linux-block, linux-mm, gost.dev,
p.raghav, da.gomez
On Fri, May 02, 2025 at 04:13:09PM -0700, Luis Chamberlain wrote:
> Devices which have a requirement for bs > ps cannot be supported for
> swap as swap still needs work.
This should work just fine for swap through intelligent enough file
systems not using the generic ->bmap based swap path, although
performance would still be horrible.
So no argument against the check, but please add a detailed comment
for it instead of just placing an undocumented check there.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] swapfile: disable swapon for bs > ps devices
2025-05-05 6:25 ` Christoph Hellwig
@ 2025-05-05 14:40 ` Matthew Wilcox
0 siblings, 0 replies; 6+ messages in thread
From: Matthew Wilcox @ 2025-05-05 14:40 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Luis Chamberlain, brauner, akpm, linux-fsdevel, linux-block,
linux-mm, gost.dev, p.raghav, da.gomez
On Sun, May 04, 2025 at 11:25:11PM -0700, Christoph Hellwig wrote:
> On Fri, May 02, 2025 at 04:13:09PM -0700, Luis Chamberlain wrote:
> > Devices which have a requirement for bs > ps cannot be supported for
> > swap as swap still needs work.
>
> This should work just fine for swap through intelligent enough file
> systems not using the generic ->bmap based swap path, although
> performance would still be horrible.
"intelligent enough" is doing a lot of heavy lifting there. Setting
aside that only netfs (nfs and cifs) implement ->swap_rw today, a
block fs which wanted to support sub-block-size swap accesses would
need to pad writes (not a huge problem), but on reads, it'd need to
either discard the extra data somewhere or (better) bring the other
pages into the swap cache.
Really, I think it needs a major rethink of the swap system, which is
happening anyway.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] swapfile: disable swapon for bs > ps devices
2025-05-02 23:13 [PATCH] swapfile: disable swapon for bs > ps devices Luis Chamberlain
2025-05-05 6:25 ` Christoph Hellwig
@ 2025-05-05 14:21 ` Christian Brauner
2025-05-05 19:35 ` [PATCH v2] " Luis Chamberlain
1 sibling, 1 reply; 6+ messages in thread
From: Christian Brauner @ 2025-05-05 14:21 UTC (permalink / raw)
To: Luis Chamberlain
Cc: akpm, linux-fsdevel, linux-block, linux-mm, gost.dev, p.raghav,
da.gomez
On Fri, May 02, 2025 at 04:13:09PM -0700, Luis Chamberlain wrote:
> Devices which have a requirement for bs > ps cannot be supported for
> swap as swap still needs work. Now that the block device cache sets the
> min order for block devices we need this stop gap otherwise all
> swap operations are rejected.
>
> Without this you'll end up with errors on these devices as the swap
> code still needs much love to support min order.
>
> # cat /sys/block/nvme3n1/queue/logical_block_size 16384
> # mkswap /dev/nvme3n1
> mkswap: /dev/nvme3n1: warning: wiping old swap signature.
> Setting up swapspace version 1, size = 100 GiB (107374178304 bytes)
> no label, UUID=6af76b5c-7e7b-4902-b7f7-4c24dde6fa36
> # swapon /dev/nvme3n1
> swapon: /dev/nvme3n1: swapon failed: Invalid argument
>
> Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
> ---
>
> I had posted an RFC about a heads up about us needing this less than a year
> ago [0] and well, we now need it for v6.15 since swap code is just not ready.
>
> Christian, this should probably go through your tree.
>
> I tested it on a LBS device where the logical block size is 16 KiB on
> x86_64 and confirm that while mkswap would swapon would be rejected.
>
> [0] https://lore.kernel.org/all/20240627000924.2074949-1-mcgrof@kernel.org/T/#u
Thanks Luis! Did you plan on adding the comment that Christoph requested?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH v2] swapfile: disable swapon for bs > ps devices
2025-05-05 14:21 ` Christian Brauner
@ 2025-05-05 19:35 ` Luis Chamberlain
2025-05-06 8:46 ` Christian Brauner
0 siblings, 1 reply; 6+ messages in thread
From: Luis Chamberlain @ 2025-05-05 19:35 UTC (permalink / raw)
To: Christian Brauner
Cc: akpm, linux-fsdevel, linux-block, linux-mm, gost.dev, p.raghav,
da.gomez
Devices which have a requirement for bs > ps cannot be supported for
swap as swap still needs work. Now that the block device cache sets the
min order for block devices we need this stop gap otherwise all
swap operations are rejected.
Without this you'll end up with errors on these devices as the swap
code still needs much love to support min order.
With this we at least now put a stop gap of its use, until the
swap subsystem completes its major overhaul:
mkswap: /dev/nvme3n1: warning: wiping old swap signature.
Setting up swapspace version 1, size = 100 GiB (107374178304 bytes)
no label, UUID=6af76b5c-7e7b-4902-b7f7-4c24dde6fa36
swapon: /dev/nvme3n1: swapon failed: Invalid argument
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
mm/swapfile.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/mm/swapfile.c b/mm/swapfile.c
index 2eff8b51a945..9e49875ca1fd 100644
--- a/mm/swapfile.c
+++ b/mm/swapfile.c
@@ -3322,6 +3322,15 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
goto bad_swap_unlock_inode;
}
+ /*
+ * The swap subsystem needs a major overhaul to support this.
+ * It doesn't work yet so just disable it for now.
+ */
+ if (mapping_min_folio_order(mapping) > 0) {
+ error = -EINVAL;
+ goto bad_swap_unlock_inode;
+ }
+
/*
* Read the swap header.
*/
--
2.47.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v2] swapfile: disable swapon for bs > ps devices
2025-05-05 19:35 ` [PATCH v2] " Luis Chamberlain
@ 2025-05-06 8:46 ` Christian Brauner
0 siblings, 0 replies; 6+ messages in thread
From: Christian Brauner @ 2025-05-06 8:46 UTC (permalink / raw)
To: Luis Chamberlain
Cc: Christian Brauner, akpm, linux-fsdevel, linux-block, linux-mm,
gost.dev, p.raghav, da.gomez
On Mon, 05 May 2025 12:35:19 -0700, Luis Chamberlain wrote:
> Devices which have a requirement for bs > ps cannot be supported for
> swap as swap still needs work. Now that the block device cache sets the
> min order for block devices we need this stop gap otherwise all
> swap operations are rejected.
>
> Without this you'll end up with errors on these devices as the swap
> code still needs much love to support min order.
>
> [...]
Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes
[1/1] swapfile: disable swapon for bs > ps devices
https://git.kernel.org/vfs/vfs/c/6ba0982c3235
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-05-06 8:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-02 23:13 [PATCH] swapfile: disable swapon for bs > ps devices Luis Chamberlain
2025-05-05 6:25 ` Christoph Hellwig
2025-05-05 14:40 ` Matthew Wilcox
2025-05-05 14:21 ` Christian Brauner
2025-05-05 19:35 ` [PATCH v2] " Luis Chamberlain
2025-05-06 8:46 ` Christian Brauner
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).