Skip to contentSkip to conversation

swapfile: disable swapon for bs > ps devices

PATCH Superseded Luis Chamberlain 5 participants 7 messages May 2, 2025 – May 6, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 swapfile: disable swapon for bs > ps devices

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

---

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/[email protected]/T/#u

 mm/swapfile.c | 5 +++++
 1 file changed, 5 insertions(+)
mm/swapfile.c +5 -0
index 2eff8b51a945..c24ec16dfc7a 100644
@@ -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.
 	 */
Signature · 1 line
2.47.2
#1 lore raw
Quoted 2 lines · Luis Chamberlain

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.

#3 lore raw
In reply to Luis Chamberlain
Quoted 22 lines · Luis Chamberlain

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

---

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.

Quoted 6 lines

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/[email protected]/T/#u

Thanks Luis! Did you plan on adding the comment that Christoph requested?

Reviewed-by on v1 1/1
#6 lore raw
In reply to Luis Chamberlain
Quoted 16 lines · Luis Chamberlain

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
Quoted 1 line
#2 lore raw
In reply to Christoph Hellwig
Quoted 7 lines · Christoph Hellwig
Quoted 2 lines · Luis Chamberlain

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.

#4 lore raw

PATCH v2 1/1 swapfile: disable swapon for bs > ps devices

In reply to Christian Brauner

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

---
 mm/swapfile.c | 9 +++++++++
 1 file changed, 9 insertions(+)
mm/swapfile.c +9 -0
index 2eff8b51a945..9e49875ca1fd 100644
@@ -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.
 	 */
Signature · 1 line
2.47.2
maintainer Applied
#5 lore raw
Quoted 9 lines · Luis Chamberlain

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